Dala.Gpu.Compute.Buffer (dala v0.5.0)

Copy Markdown View Source

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.

Summary

Functions

Create a GPU buffer from a raw binary.

Create a new GPU buffer from a list of values.

Return the total number of elements in the buffer.

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

Create a zero-initialized GPU buffer.

Types

t()

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

Functions

from_binary(data, shape, dtype \\ :u8)

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

Create a GPU buffer from a raw binary.

new(data, shape, dtype \\ :f32)

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

Create a new GPU buffer from a list of values.

num_elements(buffer)

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

Return the total number of elements in the buffer.

valid?(buffer)

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

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

zeros(shape, dtype \\ :f32)

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

Create a zero-initialized GPU buffer.