# `AxeraNPU`
[🔗](https://github.com/cocoa-xu/axera_npu/blob/v0.2.0/lib/axera_npu.ex#L1)

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.

# `data`

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

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

# `describe`

```elixir
@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`

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

Loads a model file onto the NPU.

# `load_binary`

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

Loads a model from its bytes onto the NPU.

# `run`

```elixir
@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`, ...).

---

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