GitHub
deepbox/core

Config & Backends

Runtime configuration, backend registration, and device-level metadata exposed by deepbox/core.
Config
Backend registry

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.
type Backend
export interface Backend { … }
The interface every Deepbox execution backend must implement.
type BackendCapability
export type BackendCapability = "matmul" | "conv2d" | "fft" | "reduction" | "elementwise" | "blas" | "random";
Capability flags that a backend may support.
type BackendInfo
export type BackendInfo = { /** The device this backend serves. */ readonly device: Device; /** Human-readable name (e.g. "Deepbox CPU Backend"). */ readonly name: string; /** Whether this backend is currently available…
Information about a registered backend.
type BinaryKernelOp
export type BinaryKernelOp = "add" | "sub" | "mul" | "div" | "pow" | "maximum" | "minimum";
Binary element-wise kernels a backend may execute.
type CompiledWasmModule
export type CompiledWasmModule = { readonly name: WasmModuleName; readonly instance: WebAssembly.Instance; readonly memory: WebAssembly.Memory; };
A compiled WASM SIMD module with its exports.
type DeviceBuffer
export type DeviceBuffer = { /** Device that owns this buffer. */ readonly device: Device; /** Size of the buffer in bytes (dtype-aware: f16/bf16 are 2 bytes/element). */ readonly byteLength: number; /** Number of eleme…
DeviceBuffer is a public type in deepbox/core.
type DeviceDType
export type DeviceDType = "float32" | "float16" | "bfloat16";
Opaque handle to memory owned by a .
type GpuPipelineInfo
export type GpuPipelineInfo = { readonly name: ShaderName; readonly workgroupSize: number; };
Information about a compiled GPU pipeline.
type HostAcceleratorBackend
export interface HostAcceleratorBackend extends Backend { … }
Execution interface for host-accelerator backends (e.g.
type HostBinaryOp
export type HostBinaryOp = "add" | "sub" | "mul" | "div";
Binary ops a host accelerator may run over contiguous float32 data.
type Im2ColParams
export type Im2ColParams = { readonly batch: number; readonly channels: number; readonly height: number; readonly width: number; readonly outH: number; readonly outW: number; readonly kH: number; readonly kW: number; re…
Geometry of a 2-D convolution unfold/fold (`im2col`/`col2im`), all in elements.
type KernelBackend
export interface KernelBackend extends Backend { … }
Execution interface for accelerated (non-CPU) backends.
type KernelLayout
export type KernelLayout = { readonly shape: readonly number[]; readonly strides: readonly number[]; readonly offset: number; };
Explicit memory layout of one kernel operand.
type PoolKernelOp
export type PoolKernelOp = "max" | "avg";
2-D pooling kernels a backend may execute.
type ReduceKernelOp
export type ReduceKernelOp = "sum" | "mean" | "max" | "min";
Full-tensor reduction kernels a backend may execute.
type ShaderName
export type ShaderName = keyof typeof WGSL_SHADERS;
Available shader names.
type TernaryKernelOp
export type TernaryKernelOp = "where";
Ternary element-wise kernels a backend may execute.
type UnaryKernelOp
export type UnaryKernelOp = "copy" | "step" | "neg" | "abs" | "exp" | "log" | "sqrt" | "square" | "relu" | "sigmoid" | "tanh" | "gelu" | "erf" | "rsqrt" | "reciprocal" | "sign" | "expm1" | "log1p" | "softplus";
Unary element-wise kernels a backend may execute.
type WasmModuleName
export type WasmModuleName = keyof typeof WAT_MODULES;
Available WASM module names.
type WASM_BINARIES
export declare const WASM_BINARIES: Record<WasmModuleName, string>;
WASM_BINARIES is a public const in deepbox/core.
type WAT_MODULES
export declare const WAT_MODULES: { readonly simdAdd: "(module\n (import \"env\" \"memory\" (memory 1))\n (func (export \"run\") (param $a i32) (param $b i32) (param $out i32) (param $count i32)\n (local $i i32)\n (loca…
WAT_MODULES is a public const in deepbox/core.
type WGSL_SHADERS
export declare const WGSL_SHADERS: Record<string, string>;
WGSL_SHADERS is a public const in deepbox/core.
type DeepboxConfig
export type DeepboxConfig = { readonly defaultDtype: DType; readonly defaultDevice: Device; readonly seed: number | null; };
Global configuration for Deepbox.

CpuBackend

The built-in CPU execution backend.

WasmBackend

WASM SIMD execution backend.

WebGpuBackend

WebGPU execution backend.

getBackend
export declare function getBackend(device: Device): Backend;

Retrieve the backend for the given device.

getHostAccelerator
export declare function getHostAccelerator(device: Device): HostAcceleratorBackend | null;

Retrieve the host-accelerator backend for a device, or `null` when the device has no registered, available backend implementing that surface.

getKernelBackend
export declare function getKernelBackend(device: Device): KernelBackend | null;

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.

isBackendAvailable
export declare function isBackendAvailable(device: Device): boolean;

Check whether a backend is registered and available for the device.

isHostAcceleratorBackend
export declare function isHostAcceleratorBackend(backend: Backend): backend is HostAcceleratorBackend;

Type guard: does this backend implement the surface?

isKernelBackend
export declare function isKernelBackend(backend: Backend): backend is KernelBackend;

Type guard: does this backend implement the execution surface?

listBackends
export declare function listBackends(): Device[];

List all currently registered devices with backends.

registerBackend
export declare function registerBackend(device: Device, backend: Backend): void;

Register a new backend for a device.

unregisterBackend
export declare function unregisterBackend(device: Device): boolean;

Remove a registered backend.

getConfig
export declare function getConfig(): Readonly<DeepboxConfig>;

Get the current global configuration.

getDevice
export declare function getDevice(): Device;

Get the current default device.

getDtype
export declare function getDtype(): DType;

Get the current default data type.

getSeed
export declare function getSeed(): number | null;

Get the current random seed.

resetConfig
export declare function resetConfig(): void;

Reset configuration to default values.

setConfig
export declare function setConfig(next: Partial<DeepboxConfig>): void;

Update global configuration.

setDevice
export declare function setDevice(device: Device): void;

Set the default compute device for new tensors and other device-aware APIs.

setDtype
export declare function setDtype(dtype: DType): void;

Set the default data type for new tensors.

setSeed
export declare function setSeed(seed: number): void;

Set the global random seed for reproducibility.

core-config.ts
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"));