AxeraNPU (axera_npu v0.2.0)

Copy Markdown View Source

Runs Pulsar2 models (.axmodel) on the NPU of Axera AX620E chips, through the open ax620e-npu driver and an open runtime: no vendor libraries.

{:ok, model} = AxeraNPU.load("/data/mobilenetv2.axmodel")

model.inputs
#=> [%AxeraNPU.Tensor{name: "input", type: {:u, 8}, shape: {1, 224, 224, 3}, size: 150528}]

{:ok, [scores]} = AxeraNPU.run(model, [rgb])

Inputs are binaries of the inputs' sizes, or Nx tensors of their types and shapes; the outputs come back in the same form. A model runs one call at a time; separate models run concurrently, the NPU taking their work in turn.

Summary

Types

An input or output: its bytes, or an Nx tensor.

Functions

A model's inputs and outputs, read from its bytes without the NPU (so on any computer).

Loads a model file onto the NPU.

Loads a model from its bytes onto the NPU.

Runs a model on its inputs, in order.

Types

data()

@type data() :: binary() | struct()

An input or output: its bytes, or an Nx tensor.

Functions

describe(axmodel)

@spec describe(binary()) ::
  {:ok, %{inputs: [AxeraNPU.Tensor.t()], outputs: [AxeraNPU.Tensor.t()]}}
  | {:error, String.t()}

A model's inputs and outputs, read from its bytes without the NPU (so on any computer).

load(path)

@spec load(Path.t()) ::
  {:ok, AxeraNPU.Model.t()} | {:error, File.posix() | String.t()}

Loads a model file onto the NPU.

load_binary(axmodel)

@spec load_binary(binary()) :: {:ok, AxeraNPU.Model.t()} | {:error, String.t()}

Loads a model from its bytes onto the NPU.

run(model, inputs)

@spec run(AxeraNPU.Model.t(), [data()]) :: {:ok, [data()]} | {:error, atom()}

Runs a model on its inputs, in order.

The outputs are Nx tensors if any input is one, binaries otherwise. Raises ArgumentError for inputs that do not fit the model; returns an error when the NPU fails (:etimedout, :eio, ...).