1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//! WebGPU backend for accelerated matrix operations.
//!
//! Provides GPU-accelerated (or CPU-fallback) computation with WGSL shader generation
//! for use in browser environments with WebGPU support.
//!
//! # Architecture
//!
//! | Module | Role |
//! |--------|------|
//! | `types` | Core types: `WebGpuConfig`, `GpuBuffer`, `GpuError`, `GpuBufferDescriptor`, etc. |
//! | `shader_gen` | WGSL source generation: matmul, elementwise, reduction, conv1d |
//! | `matmul` | Tiled GEMM with CPU simulation and WGSL shader output |
//! | `operations` | Elementwise and reduction operations (CPU + WGSL) |
//! | `backend` | `DeviceSimulator` and `WebGpuContext` — full CPU-side execution model |
//! | `wasm_bindings` | `WasmWebGpu` and `#[wasm_bindgen]` entry points |
//!
//! # Quick start (native Rust)
//!
//! ```rust
//! use scirs2_wasm::webgpu::backend::WebGpuContext;
//! use scirs2_wasm::webgpu::shader_gen::ElementwiseOp;
//! use scirs2_wasm::webgpu::types::{GpuBufferUsage, WebGpuConfig};
//!
//! let mut ctx = WebGpuContext::new(WebGpuConfig::default());
//!
//! // Upload input data.
//! let a_id = ctx.upload_buffer(vec![1.0_f32, 2.0, 3.0, 4.0], GpuBufferUsage::Storage).unwrap();
//! let b_id = ctx.upload_buffer(vec![5.0_f32, 6.0, 7.0, 8.0], GpuBufferUsage::Storage).unwrap();
//!
//! // Matrix multiply 2×2 × 2×2.
//! let c_id = ctx.matmul(a_id, b_id, 2, 2, 2).unwrap();
//! let c = ctx.download_buffer(c_id).unwrap();
//! assert!((c[0] - 19.0).abs() < 1e-4);
//! ```
pub use ;
pub use WebGpuMatmul;
pub use WebGpuOps;
pub use ;
pub use ;
pub use ;