deepbox/core
Devices & execution
How Deepbox registers backends, what a tensor's and nn.Module's device means, and how `.to(device)` moves real data and compute onto the GPU once a WebGPU (or WASM) backend is registered.
Backends and device metadata
- Only the CPU backend is registered by default. WebGPU and WASM backends exist in deepbox/core but must be registered explicitly with registerBackend when your runtime can host them.
- Global defaults for device, dtype, and seed come from setConfig and the setDevice / setDtype / setSeed helpers; they coordinate metadata across modules but do not magically enable hardware you have not wired up.
- Tensor.device and Module.to(device) place a tensor (or a module's parameters) on a device. With no backend registered the only device is the CPU; once a WebGPU backend is registered, `.to('webgpu')` transfers real data into GPU memory and eligible ops execute on-device — like PyTorch's `.cuda()`. Ops a device cannot run throw a clear DeviceError rather than silently falling back.
- Training runs on the CPU by default; register a WebGPU backend to train on the GPU. The WebGPU path is training-complete — matmul and batched matmul, axis reductions (softmax/layerNorm), convolution and pooling, on-device autograd, and the SGD/Adam optimizer step all run resident on the device (fp32 and fp16). See Config & Backends and the nn Module page for the API details.
devices.ts
import { getBackend, listBackends, registerBackend, setConfig } from "deepbox/core";setConfig({ defaultDevice: "cpu", defaultDtype: "float32" });console.log("Registered backends:", listBackends());console.log("CPU backend:", getBackend("cpu"));// WebGPU / WASM: import WebGpuBackend / WasmBackend and registerBackend(...) when your environment supports them.