Config & Backends
Overview
- setConfig and the device/dtype/seed helpers control global defaults shared across modules.
- CpuBackend is the only execution backend registered by default. WebGpuBackend and WasmBackend are available but require explicit registerBackend(...) in environments that support them; there is no automatic GPU enablement.
- The backend API surfaces CPU, WebAssembly, and WebGPU registration hooks without forcing a specific runtime.
- A tensor's device and nn.Module.to(device) place data on a device; execution follows whichever backend is registered for those ops. With no non-CPU backend registered, work runs on the CPU. Register a WebGPU backend and `.to('webgpu')` moves data into GPU memory and eligible ops — including a full training loop — execute on-device.
- Use backend inspection APIs when building tooling, diagnostics, or experimental execution layers around Deepbox.
CpuBackend
The built-in CPU execution backend.
WasmBackend
WASM SIMD execution backend.
WebGpuBackend
WebGPU execution backend.
Retrieve the backend for the given device.
Retrieve the host-accelerator backend for a device, or `null` when the device has no registered, available backend implementing that surface.
Retrieve the kernel-capable backend for a device, or `null` when the device has no registered backend, the backend is unavailable, or it does not implement the execution surface.
Check whether a backend is registered and available for the device.
Type guard: does this backend implement the surface?
Type guard: does this backend implement the execution surface?
List all currently registered devices with backends.
Register a new backend for a device.
Remove a registered backend.
Get the current global configuration.
Get the current default device.
Get the current default data type.
Get the current random seed.
Reset configuration to default values.
Update global configuration.
Set the default compute device for new tensors and other device-aware APIs.
Set the default data type for new tensors.
Set the global random seed for reproducibility.
import { getBackend, getConfig, listBackends, setConfig, setDevice, setDtype, setSeed,} from "deepbox/core";setConfig({ defaultDevice: "cpu", defaultDtype: "float32" });setDevice("cpu");setDtype("float64");setSeed(42);console.log(getConfig());console.log(listBackends());console.log(getBackend("cpu"));