Struct std::WebGpuBuf
struct WebGpuBuf {
unsigned long handle;
unsigned long bytes;
int dtype;
}Memory on the WebGPU device -- the WebGPU twin of gpu_mps.h's MpsBuf. 'handle' is the backend's device handle (a byte offset into its heap, the element type in its top two bits as device.h's DEV_TAG_*), 0 for an invalid (failed or freed) buffer; every op returns 0 for one. 'bytes' is its size, 'dtype' its element type: 0 = fp32, WEBGPU_FP16 or WEBGPU_BF16.
Ops on buffers are queued on the device's stream and return without waiting; read() and read_f32() wait for the work queued before them, and write() is ordered after it, so a buffer may be written, used and read back without explicit synchronization. free() doesn't wait either: work already queued still reads the memory before anything queued after it can reuse it. Owned by the caller: free() exactly once.
Fields
Methods
handle != 0
back to the device heap; handle := 0
Copies the first dst.len (<= this.bytes) bytes into 'dst', once the work queued before has run. 1 = done.
The first n elements as fp32 (16-bit ones converted on the CPU).
Copies src.len bytes (<= this.bytes) from 'src' into the buffer, after the work queued before. 1 = done.
n uninitialized elements
n fp32 values rounded on the CPU (float16.h's f32_to_fp16_bulk / f32_to_bf16_bulk) and stored as fp16 / bf16.
n raw fp16 or bf16 values (dtype WEBGPU_FP16 / WEBGPU_BF16), copied as is.