oxicuda_webgpu/lib.rs
1//! OxiCUDA WebGPU backend — cross-platform GPU compute via `wgpu` and WGSL.
2//!
3//! Provides a [`WebGpuBackend`] that implements the [`oxicuda_backend::ComputeBackend`] trait
4//! from `oxicuda-backend`, using `wgpu` to target Vulkan, Metal, Direct3D 12,
5//! and the browser WebGPU API from a single Rust crate.
6//!
7//! # Quick Start
8//!
9//! ```rust,no_run
10//! use oxicuda_webgpu::WebGpuBackend;
11//! use oxicuda_backend::ComputeBackend;
12//!
13//! let mut backend = WebGpuBackend::new();
14//! backend.init().expect("WebGPU init failed");
15//!
16//! // Allocate 1 KiB on the GPU.
17//! let ptr = backend.alloc(1024).expect("alloc failed");
18//! backend.free(ptr).expect("free failed");
19//! ```
20//!
21//! # Architecture
22//!
23//! ```text
24//! ┌──────────────────────────────────────────┐
25//! │ WebGpuBackend │
26//! │ (implements ComputeBackend) │
27//! └──────────────┬───────────────────────────┘
28//! │
29//! ┌────────▼────────┐
30//! │ WebGpuDevice │ ← wgpu Instance + Adapter + Device + Queue
31//! └────────┬────────┘
32//! │
33//! ┌───────────▼────────────┐
34//! │ WebGpuMemoryManager │ ← buffer pool (u64 handle → wgpu::Buffer)
35//! └────────────────────────┘
36//! ```
37//!
38//! # WGSL Shader Generation
39//!
40//! The [`shader`] module provides helpers that produce WGSL source strings for
41//! common kernels (GEMM, element-wise ops, reductions).
42
43pub mod backend;
44pub mod device;
45pub mod error;
46pub mod memory;
47pub mod shader;
48
49// WASM target support — compiled on wasm32 or when the `wasm` feature is
50// enabled (so that native tests can exercise the module).
51#[cfg(any(target_arch = "wasm32", feature = "wasm"))]
52pub mod wasm;
53
54pub use backend::WebGpuBackend;
55pub use error::{WebGpuError, WebGpuResult};