# leandronunescorreia/gpu-task architecture

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

- Interactive diagram: https://gitdiagram.com/leandronunescorreia/gpu-task
- Repository: https://github.com/leandronunescorreia/gpu-task

## Overview

1. **What this repo is**
   - A small C++ GPU compute engine for cross-platform prototyping and benchmarking.
   - The project is centered on **WebGPU-compatible backends** so the same compute workflow can run across Windows, Linux, and macOS.

2. **Top-level structure**
   - The repository is organized as a classic CMake C++ project:
     - `include/webgpu_compute/` exposes the public API.
     - `src/` contains the implementation.
     - `samples/` contains runnable examples.
     - `test/` contains unit tests.
   - This split suggests a reusable library with separate consumer programs, rather than a monolithic application.

3. **Public library boundary**
   - The main external surface appears to be `include/webgpu_compute/webgpu_compute.h`, which likely aggregates the core API.
   - Other headers under `include/webgpu_compute/` expose the main engine building blocks:
     - `device_manager.h`
     - `buffer_manager.h`
     - `compute_engine.h`
     - `compute_effects_store.h`
   - This indicates the repo is designed as a small SDK/library that consumers link against.

4. **Core runtime subsystems**
   - `DeviceManager` is the boundary for GPU/device selection and backend setup.
   - `BufferManager` is the boundary for GPU buffer creation, upload/download, and lifetime management.
   - `ComputeEngine` is the orchestration layer that likely coordinates device access, buffers, and compute dispatch.
   - `ComputeEffectsStore` appears to be a registry or catalog of compute kernels/effects, giving the engine a way to look up and execute named workloads.

5. **Implementation split**
   - The implementation lives in:
     - `src/device_manager.cpp`
     - `src/buffer_manager.cpp`
     - `src/compute_engine.cpp`
   - That suggests the main architectural seams are stable public interfaces in `include/` backed by relatively small implementation units in `src/`.

6. **Data flow through the engine**
   - Typical flow is likely:
     1. Initialize/select a WebGPU device via `DeviceManager`.
     2. Allocate or import GPU buffers via `BufferManager`.
     3. Register or select a compute effect from `ComputeEffectsStore`.
     4. Dispatch work through `ComputeEngine`.
     5. Read results back from GPU buffers.
   - This is a compute-oriented pipeline, not a rendering pipeline.

7. **Backend and portability boundary**
   - The README explicitly mentions **Dawn** and **wgpu-native** as supported backends.
   - That means the repo’s portability layer is centered around the WebGPU API, with backend choice controlled at build/config time rather than by application code.
   - Architecture diagrams should show the engine as backend-agnostic, with WebGPU backends underneath.

8. **Sample application subsystem**
   - `samples/01-vector-add/` is the clearest end-to-end example:
     - `main.cpp` is the host-side sample program.
     - `vec-add.wglsl` is the compute shader/kernel source.
   - This sample demonstrates the full host-to-device flow: prepare buffers, run a kernel, and validate vector addition results.

9. **Testing subsystem**
   - Tests exist for the management layers:
     - `test/test_device_manager.cpp`
     - `test/test_buffer_manager.cpp`
   - The presence of tests specifically for device and buffer management implies those are the most important correctness boundaries in the library.
   - Tests are separate CMake targets, which fits a library-style architecture.

10. **Build and packaging**
   - CMake is the only build system visible, with project-level and per-folder `CMakeLists.txt` files.
   - The README includes install steps, so the library is intended to be built, installed, and consumed by other projects.
   - The `.devcontainer` setup suggests the repo is also meant to support reproducible development environments.

11. **What matters for an architecture diagram**
   - Show three concentric layers:
     - **Consumers**: samples and tests.
     - **Library core**: device, buffer, compute engine, effects store.
     - **External platform layer**: WebGPU backend implementation (Dawn / wgpu-native).
   - The main arrows should run from sample/test code into the public headers, then into `src/`, then into backend APIs.

12. **Overall shape**
   - This is a **small compute-engine library**, not a large application platform.
   - The main architectural concern is clean separation between host orchestration and GPU execution, with portability handled by the WebGPU abstraction.

Main entry points: [`include/webgpu_compute/webgpu_compute.h`](https://github.com/leandronunescorreia/gpu-task/blob/main/include/webgpu_compute/webgpu_compute.h) (Main header), [`src/compute_engine.cpp`](https://github.com/leandronunescorreia/gpu-task/blob/main/src/compute_engine.cpp) (Compute engine), [`samples/01-vector-add/main.cpp`](https://github.com/leandronunescorreia/gpu-task/blob/main/samples/01-vector-add/main.cpp) (Vector add), [`CMakeLists.txt`](https://github.com/leandronunescorreia/gpu-task/blob/main/CMakeLists.txt) (CMake root)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_consumers["Consumers"]
  node_sample_main["Vector add<br/>sample app<br/>[main.cpp]"]
  node_sample_shader["WGLSL kernel<br/>shader<br/>[vec-add.wglsl]"]
  node_test_dm["Device tests<br/>unit tests"]
  node_test_bm["Buffer tests<br/>unit tests"]
end

subgraph group_api["Public API"]
  node_api_fa["Main header<br/>public facade<br/>[webgpu_compute.h]"]
  node_api_dm["Device API<br/>public interface<br/>[device_manager.h]"]
  node_api_bm["Buffer API<br/>public interface<br/>[buffer_manager.h]"]
  node_api_ce["Compute API<br/>public interface<br/>[compute_engine.h]"]
  node_api_es["Effects store<br/>public registry"]
end

subgraph group_core["Core Runtime"]
  node_src_dm["Device manager<br/>runtime component<br/>[device_manager.cpp]"]
  node_src_bm["Buffer manager<br/>runtime component<br/>[buffer_manager.cpp]"]
  node_src_ce["Compute engine<br/>orchestrator<br/>[compute_engine.cpp]"]
end

subgraph group_platform["Platform Layer"]
  node_webgpu(("WebGPU API<br/>portable runtime"))
  node_dawn(("Dawn<br/>backend"))
  node_wgpu_native(("wgpu-native<br/>backend"))
end

subgraph group_build["Build"]
  node_build_root["CMake root<br/>build system<br/>[CMakeLists.txt]"]
  node_build_src["Core CMake<br/>build target<br/>[CMakeLists.txt]"]
  node_build_samples["Samples CMake<br/>build target<br/>[CMakeLists.txt]"]
  node_build_test["Tests CMake<br/>build target<br/>[CMakeLists.txt]"]
end

node_build_root -->|"includes"| node_build_src
node_build_root -->|"includes"| node_build_samples
node_build_root -->|"includes"| node_build_test
node_build_samples -->|"builds"| node_sample_main
node_build_test -->|"builds"| node_test_dm
node_build_test -->|"builds"| node_test_bm
node_api_fa -->|"re-exports"| node_api_dm
node_api_fa -->|"re-exports"| node_api_bm
node_api_fa -->|"re-exports"| node_api_ce
node_api_fa -->|"re-exports"| node_api_es
node_api_dm -->|"implements"| node_src_dm
node_api_bm -->|"implements"| node_src_bm
node_api_ce -->|"implements"| node_src_ce
node_src_dm -->|"uses"| node_webgpu
node_src_bm -->|"uses"| node_webgpu
node_src_ce -->|"coordinates"| node_src_dm
node_src_ce -->|"coordinates"| node_src_bm
node_src_ce -->|"looks up"| node_api_es
node_webgpu -->|"backed by"| node_dawn
node_webgpu -->|"backed by"| node_wgpu_native
node_sample_main -->|"uses"| node_api_fa
node_sample_main -->|"dispatches"| node_sample_shader
node_sample_main -->|"drives"| node_src_ce
node_test_dm -->|"uses"| node_api_dm
node_test_bm -->|"uses"| node_api_bm

click node_build_root "https://github.com/leandronunescorreia/gpu-task/blob/main/CMakeLists.txt"
click node_build_src "https://github.com/leandronunescorreia/gpu-task/blob/main/src/CMakeLists.txt"
click node_build_samples "https://github.com/leandronunescorreia/gpu-task/blob/main/samples/CMakeLists.txt"
click node_build_test "https://github.com/leandronunescorreia/gpu-task/blob/main/test/CMakeLists.txt"
click node_api_fa "https://github.com/leandronunescorreia/gpu-task/blob/main/include/webgpu_compute/webgpu_compute.h"
click node_api_dm "https://github.com/leandronunescorreia/gpu-task/blob/main/include/webgpu_compute/device_manager.h"
click node_api_bm "https://github.com/leandronunescorreia/gpu-task/blob/main/include/webgpu_compute/buffer_manager.h"
click node_api_ce "https://github.com/leandronunescorreia/gpu-task/blob/main/include/webgpu_compute/compute_engine.h"
click node_api_es "https://github.com/leandronunescorreia/gpu-task/blob/main/include/webgpu_compute/compute_effects_store.h"
click node_src_dm "https://github.com/leandronunescorreia/gpu-task/blob/main/src/device_manager.cpp"
click node_src_bm "https://github.com/leandronunescorreia/gpu-task/blob/main/src/buffer_manager.cpp"
click node_src_ce "https://github.com/leandronunescorreia/gpu-task/blob/main/src/compute_engine.cpp"
click node_sample_main "https://github.com/leandronunescorreia/gpu-task/blob/main/samples/01-vector-add/main.cpp"
click node_sample_shader "https://github.com/leandronunescorreia/gpu-task/blob/main/samples/01-vector-add/vec-add.wglsl"
click node_test_dm "https://github.com/leandronunescorreia/gpu-task/blob/main/test/test_device_manager.cpp"
click node_test_bm "https://github.com/leandronunescorreia/gpu-task/blob/main/test/test_buffer_manager.cpp"

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_sample_main,node_sample_shader,node_test_dm,node_test_bm toneBlue
class node_api_fa,node_api_dm,node_api_bm,node_api_ce,node_api_es toneAmber
class node_src_dm,node_src_bm,node_src_ce toneMint
class node_webgpu,node_dawn,node_wgpu_native toneRose
class node_build_root,node_build_src,node_build_samples,node_build_test toneIndigo
```

## Components

### Consumers

Runnable example and tests that exercise the library

- [Vector add](https://github.com/leandronunescorreia/gpu-task/blob/main/samples/01-vector-add/main.cpp): sample app · End-to-end host-side sample · `samples/01-vector-add/main.cpp`
- [WGLSL kernel](https://github.com/leandronunescorreia/gpu-task/blob/main/samples/01-vector-add/vec-add.wglsl): shader · Vector-add compute workload source · `samples/01-vector-add/vec-add.wglsl`
- [Device tests](https://github.com/leandronunescorreia/gpu-task/blob/main/test/test_device_manager.cpp): unit tests · Tests for device management behavior · `test/test_device_manager.cpp`
- [Buffer tests](https://github.com/leandronunescorreia/gpu-task/blob/main/test/test_buffer_manager.cpp): unit tests · Tests for buffer management behavior · `test/test_buffer_manager.cpp`

### Public API

Installed headers that define the library surface

- [Main header](https://github.com/leandronunescorreia/gpu-task/blob/main/include/webgpu_compute/webgpu_compute.h): public facade · Aggregated public entry point · `include/webgpu_compute/webgpu_compute.h`
- [Device API](https://github.com/leandronunescorreia/gpu-task/blob/main/include/webgpu_compute/device_manager.h): public interface · Device selection and backend setup surface · `include/webgpu_compute/device_manager.h`
- [Buffer API](https://github.com/leandronunescorreia/gpu-task/blob/main/include/webgpu_compute/buffer_manager.h): public interface · GPU buffer management surface · `include/webgpu_compute/buffer_manager.h`
- [Compute API](https://github.com/leandronunescorreia/gpu-task/blob/main/include/webgpu_compute/compute_engine.h): public interface · Engine orchestration surface · `include/webgpu_compute/compute_engine.h`
- [Effects store](https://github.com/leandronunescorreia/gpu-task/blob/main/include/webgpu_compute/compute_effects_store.h): public registry · Named compute workload catalog · `include/webgpu_compute/compute_effects_store.h`

### Core Runtime

Implementation of device, buffer, and compute orchestration

- [Device manager](https://github.com/leandronunescorreia/gpu-task/blob/main/src/device_manager.cpp): runtime component · Concrete device/backend selection implementation · `src/device_manager.cpp`
- [Buffer manager](https://github.com/leandronunescorreia/gpu-task/blob/main/src/buffer_manager.cpp): runtime component · Concrete GPU buffer lifecycle implementation · `src/buffer_manager.cpp`
- [Compute engine](https://github.com/leandronunescorreia/gpu-task/blob/main/src/compute_engine.cpp): orchestrator · Coordinates devices, buffers, and dispatch · `src/compute_engine.cpp`

### Platform Layer

WebGPU abstraction and concrete backend choices

- **WebGPU API**: portable runtime · Backend-agnostic GPU abstraction layer
- **Dawn**: backend · One supported WebGPU backend
- **wgpu-native**: backend · Another supported WebGPU backend

### Build

CMake-based project and targets

- [CMake root](https://github.com/leandronunescorreia/gpu-task/blob/main/CMakeLists.txt): build system · Top-level CMake project definition · `CMakeLists.txt`
- [Core CMake](https://github.com/leandronunescorreia/gpu-task/blob/main/src/CMakeLists.txt): build target · Build rules for the library implementation · `src/CMakeLists.txt`
- [Samples CMake](https://github.com/leandronunescorreia/gpu-task/blob/main/samples/CMakeLists.txt): build target · Build rules for sample programs · `samples/CMakeLists.txt`
- [Tests CMake](https://github.com/leandronunescorreia/gpu-task/blob/main/test/CMakeLists.txt): build target · Build rules for unit tests · `test/CMakeLists.txt`

## Connections

- CMake root → Core CMake: includes · Top-level project builds the core library
- CMake root → Samples CMake: includes · Top-level project builds sample targets
- CMake root → Tests CMake: includes · Top-level project builds test targets
- Samples CMake → Vector add: builds · Sample target compiles the demo app
- Tests CMake → Device tests: builds · Test target compiles device tests
- Tests CMake → Buffer tests: builds · Test target compiles buffer tests
- Main header → Device API: re-exports · Facade aggregates the library interfaces
- Main header → Buffer API: re-exports · Facade aggregates the library interfaces
- Main header → Compute API: re-exports · Facade aggregates the library interfaces
- Main header → Effects store: re-exports · Facade aggregates the library interfaces
- Device API → Device manager: implements · Public device API is backed by the implementation
- Buffer API → Buffer manager: implements · Public buffer API is backed by the implementation
- Compute API → Compute engine: implements · Public compute API is backed by the implementation
- Device manager → WebGPU API: uses · Device setup depends on WebGPU abstraction
- Buffer manager → WebGPU API: uses · Buffer management depends on WebGPU abstraction
- Compute engine → Device manager: coordinates · Engine relies on device management
- Compute engine → Buffer manager: coordinates · Engine relies on buffer management
- Compute engine → Effects store: looks up · Engine consults the effects registry
- WebGPU API → Dawn: backed by · One possible implementation path
- WebGPU API → wgpu-native: backed by · Another possible implementation path
- Vector add → Main header: uses · Sample consumes the public library surface
- Vector add → WGLSL kernel: dispatches · Sample runs the compute kernel
- Vector add → Compute engine: drives · Sample exercises the compute workflow through the engine
- Device tests → Device API: uses · Device tests target the public device surface
- Buffer tests → Buffer API: uses · Buffer tests target the public buffer surface
