std1.0.0-beta-7 SafeC docs

Module ml::gpu_webgpu

#include <std/ml/gpu_webgpu.h> source

Structs

WebGpuBufMemory 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.

Functions

webgpu_available1 if a WebGPU adapter and device are available (initializes them).
webgpu_matmulout [M, N] = a [M, K] . b [K, N], row-major. a and b share a dtype (fp32, fp16 or bf16; products accumulate in fp32), out is any dtype. Queued.
webgpu_sgd_updatew[i] -= lr * g[i] for i < n, in place (any dtypes). Queued.
webgpu_syncWaits for everything queued on the device (tensor work too). 1 on success.
webgpu_add_f32out[i] = a[i] op b[i] (or op a[i]) for i in [0, n): the inputs uploaded, the op run, the result read back. 1 = done, 0 = no WebGPU (out untouched).
webgpu_sub_f32
webgpu_mul_f32
webgpu_div_f32
webgpu_pow_f32
webgpu_relu_f32
webgpu_log_f32
webgpu_exp_f32
webgpu_sqrt_f32
webgpu_scale_f32
webgpu_sum_f32out[0] = sum(a[0..n)): a reduction per workgroup, added atomically.
webgpu_matmul_f32out [M, N] = a [M, K] . b [K, N].

Macros

WEBGPU_FP16Element types of a buffer (WebGpuBuf.dtype): 0 = fp32, or 16-bit values.
WEBGPU_BF16