# siriscent7/gridforge architecture

> Architecture diagram of the GitHub repository siriscent7/gridforge, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/siriscent7/gridforge
- Repository: https://github.com/siriscent7/gridforge

## Overview

GridForge is a C++20 compute runtime for vector addition, with explicit CPU and optional Metal backends. Its main workflow is to create a runtime and buffers, upload inputs, execute an addition, and retrieve and verify the result; its asynchronous API adds streams, events, and cross-stream dependencies. The repository also provides benchmark runs and operation metrics. Runtime internals are shown at the scheduler and backend boundary. Some implementation details are unsampled, so uncertain internal dispatch links are omitted.

Main entry points: [`include/gridforge/gridforge.hpp`](https://github.com/siriscent7/gridforge/blob/main/include/gridforge/gridforge.hpp) (Public API), [`src/runtime.cpp`](https://github.com/siriscent7/gridforge/blob/main/src/runtime.cpp) (Runtime and buffers), [`src/bench_main.cpp`](https://github.com/siriscent7/gridforge/blob/main/src/bench_main.cpp) (Benchmark runner), [`src/metal_bridge.hpp`](https://github.com/siriscent7/gridforge/blob/main/src/metal_bridge.hpp) (Metal interface)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Runtime API"]
  node_public_api["Public API<br/>[gridforge.hpp]"]
  node_runtime["Runtime and buffers<br/>[runtime.cpp]"]
end

subgraph group_async["Async execution"]
  node_scheduler["Stream scheduler<br/>[runtime.cpp]"]
  node_events["Events and results<br/>[runtime.cpp]"]
end

subgraph group_backends["Compute backends"]
  node_cpu["CPU execution<br/>[runtime.cpp]"]
  node_metal_bridge["Metal interface<br/>[metal_bridge.hpp]"]
  node_metal_device["Metal implementation<br/>[metal_bridge.mm]"]
  node_shader["Vector-add shader<br/>[vector_add.metal]"]
end

subgraph group_examples["Examples and benchmarks"]
  node_sync_demo["Synchronous demo<br/>[main.cpp]"]
  node_async_demo["Async demo<br/>[async_main.cpp]"]
  node_dependency_demo["Dependency demo"]
  node_benchmark["Benchmark runner<br/>[bench_main.cpp]"]
  node_bench_support["Benchmark statistics<br/>[bench_support.hpp]"]
end

node_user(("Application"))

node_user -->|"runs"| node_sync_demo
node_user -->|"runs"| node_async_demo
node_user -->|"runs"| node_dependency_demo
node_user -.->|"runs"| node_benchmark
node_sync_demo -->|"uses"| node_public_api
node_async_demo -->|"uses"| node_public_api
node_dependency_demo -->|"uses"| node_public_api
node_benchmark -->|"uses"| node_public_api
node_benchmark -->|"computes statistics"| node_bench_support
node_public_api -->|"implemented by"| node_runtime
node_runtime -->|"accepts stream work"| node_scheduler
node_scheduler -->|"retires operations"| node_events
node_scheduler -.->|"executes work"| node_cpu
node_runtime -->|"uses interface"| node_metal_bridge
node_metal_bridge -.->|"implemented by"| node_metal_device
node_metal_device -.->|"dispatches kernel"| node_shader

click node_public_api "https://github.com/siriscent7/gridforge/blob/main/include/gridforge/gridforge.hpp"
click node_runtime "https://github.com/siriscent7/gridforge/blob/main/src/runtime.cpp"
click node_scheduler "https://github.com/siriscent7/gridforge/blob/main/src/runtime.cpp"
click node_events "https://github.com/siriscent7/gridforge/blob/main/src/runtime.cpp"
click node_cpu "https://github.com/siriscent7/gridforge/blob/main/src/runtime.cpp"
click node_metal_bridge "https://github.com/siriscent7/gridforge/blob/main/src/metal_bridge.hpp"
click node_metal_device "https://github.com/siriscent7/gridforge/blob/main/src/metal_bridge.mm"
click node_shader "https://github.com/siriscent7/gridforge/blob/main/shaders/vector_add.metal"
click node_sync_demo "https://github.com/siriscent7/gridforge/blob/main/src/main.cpp"
click node_async_demo "https://github.com/siriscent7/gridforge/blob/main/src/async_main.cpp"
click node_dependency_demo "https://github.com/siriscent7/gridforge/blob/main/src/dependency_main.cpp"
click node_benchmark "https://github.com/siriscent7/gridforge/blob/main/src/bench_main.cpp"
click node_bench_support "https://github.com/siriscent7/gridforge/blob/main/src/bench_support.hpp"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_public_api,node_runtime toneBlue
class node_scheduler,node_events toneAmber
class node_cpu,node_metal_bridge,node_metal_device,node_shader toneMint
class node_sync_demo,node_async_demo,node_dependency_demo,node_benchmark,node_bench_support toneRose
class node_user toneIndigo
```

## Components

### Runtime API

- [Public API](https://github.com/siriscent7/gridforge/blob/main/include/gridforge/gridforge.hpp): `include/gridforge/gridforge.hpp`
- [Runtime and buffers](https://github.com/siriscent7/gridforge/blob/main/src/runtime.cpp): `src/runtime.cpp`

### Async execution

- [Stream scheduler](https://github.com/siriscent7/gridforge/blob/main/src/runtime.cpp): `src/runtime.cpp`
- [Events and results](https://github.com/siriscent7/gridforge/blob/main/src/runtime.cpp): `src/runtime.cpp`

### Compute backends

- [CPU execution](https://github.com/siriscent7/gridforge/blob/main/src/runtime.cpp): `src/runtime.cpp`
- [Metal interface](https://github.com/siriscent7/gridforge/blob/main/src/metal_bridge.hpp): `src/metal_bridge.hpp`
- [Metal implementation](https://github.com/siriscent7/gridforge/blob/main/src/metal_bridge.mm): `src/metal_bridge.mm`
- [Vector-add shader](https://github.com/siriscent7/gridforge/blob/main/shaders/vector_add.metal): `shaders/vector_add.metal`

### Examples and benchmarks

- [Synchronous demo](https://github.com/siriscent7/gridforge/blob/main/src/main.cpp): `src/main.cpp`
- [Async demo](https://github.com/siriscent7/gridforge/blob/main/src/async_main.cpp): `src/async_main.cpp`
- [Dependency demo](https://github.com/siriscent7/gridforge/blob/main/src/dependency_main.cpp): `src/dependency_main.cpp`
- [Benchmark runner](https://github.com/siriscent7/gridforge/blob/main/src/bench_main.cpp): `src/bench_main.cpp`
- [Benchmark statistics](https://github.com/siriscent7/gridforge/blob/main/src/bench_support.hpp): `src/bench_support.hpp`

### Other components

- **Application**

## Connections

- Application → Synchronous demo: runs (evidence: `src/main.cpp`)
- Application → Async demo: runs (evidence: `src/async_main.cpp`)
- Application → Dependency demo: runs (evidence: `src/dependency_main.cpp`)
- Application → Benchmark runner: runs
- Synchronous demo → Public API: uses (evidence: `src/main.cpp`)
- Async demo → Public API: uses (evidence: `src/async_main.cpp`)
- Dependency demo → Public API: uses (evidence: `src/dependency_main.cpp`)
- Benchmark runner → Public API: uses (evidence: `src/bench_main.cpp`)
- Benchmark runner → Benchmark statistics: computes statistics (evidence: `src/bench_main.cpp`)
- Public API → Runtime and buffers: implemented by (evidence: `src/runtime.cpp`)
- Runtime and buffers → Stream scheduler: accepts stream work (evidence: `src/runtime.cpp`)
- Stream scheduler → Events and results: retires operations (evidence: `src/runtime.cpp`)
- Stream scheduler → CPU execution: executes work (evidence: `src/runtime.cpp`)
- Runtime and buffers → Metal interface: uses interface (evidence: `src/runtime.cpp`)
- Metal interface → Metal implementation: implemented by
- Metal implementation → Vector-add shader: dispatches kernel
