ExBurn.Backend (ex_burn v0.1.0)

Copy Markdown View Source

Nx backend implementation that delegates tensor operations to Burn via NIF.

This module implements the Nx.Backend behaviour, translating Nx tensor operations into calls to the Rust NIF layer which executes them using Burn's CubeCL backend for GPU acceleration.

Architecture

Axon model
   
Nx.Defn graph
   
ExBurn.Backend (Nx.Backend behaviour)
   
ExBurn.Nif (Rustler NIF)  ExCubecl (GPU buffers, kernels, pipelines)
   
Burn Autodiff<CubeCL> (Rust)
   
CubeCL kernels
   
Metal (iOS) / Vulkan (Android) / CUDA  GPU

Usage

Nx.default_backend(ExBurn.Backend)

Implementation Notes

  • Tensors are stored as opaque NIF references on the Rust side
  • Data is serialized as binary (f32 little-endian) for NIF calls
  • The backend struct holds the NIF reference, shape, and type
  • For performance-critical paths, use ExBurn.BurnBridge directly
  • All public callbacks raise ExBurn.Error on failure

Summary

Types

t()

@type t() :: %ExBurn.Backend{
  ref: reference(),
  shape: [non_neg_integer()],
  type: ExBurn.Tensor.burn_type()
}

Functions

random_normal(out, opts)

@spec random_normal(
  Nx.Tensor.t(),
  keyword()
) :: t()

random_uniform(out, opts)

@spec random_uniform(
  Nx.Tensor.t(),
  keyword()
) :: t()

tensor_type(backend)

@spec tensor_type(t()) :: Nx.Type.t()