Optionaloptions: {Optionalbenchmark?: booleanenable GPU timestamp queries; BLAS functions then also return gpuTimeMs
alongside their normal result (e.g. sscal returns { x, gpuTimeMs }, saxpy returns { y, gpuTimeMs }) —
see each routine's own docs for its exact return shape (default: false)
OptionaldumpShaders?: booleanNode-only. Forwards Dawn's dump_shaders debug toggle, printing
each pipeline's WGSL and compiled backend IR (SPIR-V/Vulkan, MSL/Metal, or HLSL/D3D12,
whichever Dawn picked) to stderr as it compiles. A Dawn passthrough, not a wgblas format —
no effect in the browser, which gives pages no API to request compiled shader IR, or in Deno,
whose navigator.gpu is wgpu rather than Dawn (default: false)
OptionalpowerPreference?: GPUPowerPreferenceGPU power preference (default: "high-performance").
This is a hint to the browser: on dual-GPU systems, "high-performance" typically favors the discrete GPU
and "low-power" favors the integrated one.
See MDN: GPU.requestAdapter().
Initializes the WebGPU device.
Devices are cached per option set: the same options return the same device, different options a separate one — so one process can drive several GPUs (
"high-performance"and"low-power"typically resolve to the discrete and integrated adapters). Each routine dispatches to the device you pass it; GPU buffers cannot cross devices, so aGpuVector/GpuMatrixfrom one is rejected by another. cleanup releases them all.Default (high-performance GPU):
Low-power (integrated GPU):
Benchmark mode:
Two GPUs at once: