gpu.cpp is a lightweight, header-only C++ library for portable low-level GPU computation using WebGPU.
The library solves the problem of writing GPU compute code that runs across different platforms and devices without platform-specific rewrites. It wraps Google's Dawn WebGPU implementation, automatically selecting Metal on macOS, Vulkan on Linux, and WebGPU in browsers. The design stays deliberately close to WebGPU semantics: it owns native resources, manages asynchronous work and error handling, and eliminates repetitive descriptor boilerplate, but shaders still explicitly declare their resource bindings and execution model. The core API provides a Context to manage the GPU device and queue, Tensor objects for GPU buffers with shape and type metadata, Kernel objects for reusable compute pipelines, and Future-based async operations that work natively or suspend through JSPI in browsers.
Developers should choose this tool when they need GPU compute that runs on multiple platforms without maintaining separate code paths. It suits projects that can express their compute as WebGPU shaders and want to avoid the verbosity of raw WebGPU while staying close to its semantics. The library is particularly useful for teams already targeting both native and browser environments, since the same code compiles to both. The header-only design and CMake integration make it straightforward to embed in existing projects.
The project maintains exact pinned revisions of Dawn and Emscripten tooling, with dedicated build scripts that stage dependencies reproducibly. Native tests require actual GPU hardware and deliberately disable Dawn's Null backend to catch GPU access failures clearly rather than silently. The library supports optional SPIR-V input through a WebGPU-facing compiler contract rather than arbitrary Vulkan passthrough. Browser builds require specific Chrome features and coordinate with a sibling Emscripten SDK clone, with clear documentation in DEV.md for the dependency layout and update process.