How leandronunescorreia/gpu-task works
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: webgpu_compute.h Main header · compute_engine.cpp Compute engine · main.cpp Vector add · CMakeLists.txt CMake root
Components 19
Consumers
Runnable example and tests that exercise the library
- Vector add · End-to-end host-side sample
samples/01-vector-add/main.cpp - WGLSL kernel · Vector-add compute workload source
samples/01-vector-add/vec-add.wglsl - Device tests · Tests for device management behavior
test/test_device_manager.cpp - Buffer tests · Tests for buffer management behavior
test/test_buffer_manager.cpp
Public API
Installed headers that define the library surface
- Main header · Aggregated public entry point
include/webgpu_compute/webgpu_compute.h - Device API · Device selection and backend setup surface
include/webgpu_compute/device_manager.h - Buffer API · GPU buffer management surface
include/webgpu_compute/buffer_manager.h - Compute API · Engine orchestration surface
include/webgpu_compute/compute_engine.h - Effects store · Named compute workload catalog
include/webgpu_compute/compute_effects_store.h
Core Runtime
Implementation of device, buffer, and compute orchestration
- Device manager · Concrete device/backend selection implementation
src/device_manager.cpp - Buffer manager · Concrete GPU buffer lifecycle implementation
src/buffer_manager.cpp - Compute engine · Coordinates devices, buffers, and dispatch
src/compute_engine.cpp
Platform Layer
WebGPU abstraction and concrete backend choices
- WebGPU API · Backend-agnostic GPU abstraction layer
- Dawn · One supported WebGPU backend
- wgpu-native · Another supported WebGPU backend
Build
CMake-based project and targets
- CMake root · Top-level CMake project definition
CMakeLists.txt - Core CMake · Build rules for the library implementation
src/CMakeLists.txt - Samples CMake · Build rules for sample programs
samples/CMakeLists.txt - Tests CMake · Build rules for unit tests
test/CMakeLists.txt
Connections 25
- 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