# `ExBurn.Backend`
[🔗](https://github.com/ohhi-vn/ex_burn/blob/main/lib/ex_burn/backend.ex#L1)

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

# `t`

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

# `random_normal`

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

# `random_uniform`

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

# `tensor_type`

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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
