# `Dala.Gpu.Compute.Buffer`
[🔗](https://github.com/manhvu/dala/blob/main/lib/dala/gpu/compute/buffer.ex#L1)

Typed wrapper around EXCubeCL GPU buffers.

Provides a struct-based API so buffers can be passed around safely
and matched on in function heads.

## Lifecycle

1. Create via `new/3`, `zeros/2`, or `from_binary/3`
2. Use in `Dala.Gpu.Compute.run_kernel/4` or `Dala.Gpu.Compute.submit/1`
3. Read results via `Dala.Gpu.Compute.read/1`
4. Free via `Dala.Gpu.Compute.free/1`

Buffers are automatically freed when the owning process exits
(via Rust ResourceArc cleanup). Explicit `free/1` is a no-op but
provided for API compatibility.

# `t`

```elixir
@type t() :: %Dala.Gpu.Compute.Buffer{
  dtype: atom(),
  ref: reference(),
  shape: tuple(),
  size_bytes: non_neg_integer()
}
```

# `from_binary`

```elixir
@spec from_binary(binary(), tuple(), atom()) :: t()
```

Create a GPU buffer from a raw binary.

# `new`

```elixir
@spec new(list(), tuple(), atom()) :: t()
```

Create a new GPU buffer from a list of values.

# `num_elements`

```elixir
@spec num_elements(t()) :: non_neg_integer()
```

Return the total number of elements in the buffer.

# `valid?`

```elixir
@spec valid?(t()) :: boolean()
```

Return true if the buffer is valid (has a non-nil ref).

# `zeros`

```elixir
@spec zeros(tuple(), atom()) :: t()
```

Create a zero-initialized GPU buffer.

---

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