Current section
Files
Jump to
Current section
Files
lib/cix_p1/context.ex
defmodule CixP1.Context do
@moduledoc """
A NOE UMD context — the handle onto the NPU device (`/dev/aipu`).
One context can hold many graphs. It is reference-counted by the BEAM: the
underlying `noe_context_t` is released (`noe_deinit_context`) when this struct
and every `CixP1.Graph`/`CixP1.Job` derived from it become garbage.
"""
alias CixP1.Nif
@enforce_keys [:resource]
defstruct [:resource]
@type t :: %__MODULE__{resource: reference()}
@doc """
Opens a new context on the AIPU device.
Returns `{:error, reason}` if the NPU device cannot be opened (e.g. `aipu.ko`
not loaded or `/dev/aipu` not present).
"""
@spec new() :: {:ok, t()} | {:error, String.t()}
def new do
case Nif.context_new() do
{:ok, resource} -> {:ok, %__MODULE__{resource: resource}}
{:error, reason} -> {:error, to_string(reason)}
end
end
end