Skip to content
class

GpuBackend

extendsIBackend
GpuBackend

Concrete GPU backend routing every Lucid op through Apple's MLX library.

Inherits IBackend and overrides each per-op virtual to call the matching mlx::core::* primitive (broadcast, matmul, reduce, activations, …). Results are MLX lazy arrays — mx::eval() is invoked when the engine needs the concrete buffer (e.g. for MetalKernelRunner or download_gpu_to_cpu). Stream tagging uses Dispatcher's default GPU stream unless an op requests another (linalg ops dispatch to a CPU MLX stream per the H3 carve-out, since MLX's eigh / svd / qr run on CPU).

See Also

CpuBackend — Accelerate-backed sibling. MlxBridge — Storage ↔ mlx::core::array conversion. GpuBackendRegistrar — static-init registration.

Attributes

device()Device
Always returns Device::GPU.

Notes

  • CPU and GPU backends are static singletons registered with the Dispatcher at process start (see GpuBackendRegistrar).
  • All Storage values passed in MUST hold GpuStorage — the Dispatcher guarantees this by routing Device::GPU tensors here.
  • MLX uses lazy evaluation; operations build a graph but defer execution until eval() or a CPU read forces it.
  • Dtype::F64 is unsupported on the GPU (Metal limitation); callers must cast to F32 or keep the tensor on the CPU.
  • Convolutions internally permute NCHW ↔ NHWC because MLX expects channels-last; see gpu_nchw_to_nhwc_perm family of helpers.

Examples

Construction is automatic via static registration::
    // BackendInit.cpp triggers GpuBackendRegistrar at process start.
    auto t = lucid::tensor({1,2,3}, lucid::Device::GPU);
    // → routed to GpuBackend::from_cpu → mlx::core::copy.

Static methods

28

Virtual methods

1
virtconst

device

→Device
Device device()

Return the device tag this backend services.

Returns

Device

Always Device::GPU.

Methods

265