GitHub ↗
Contents

AMD mlir-air and IRON on 1bit OS#

pyxrt is an optional developer module for AMD's IRON / mlir-air tools. 1bit serve and its NPU route never use it: they run C++ on the NPU runtime, with no Python in the path. The release checks this on every package: no binary in it has libpython NEEDED, and 1bit names neither pyxrt nor a CPython entry point.

1bit OS has no XRT. Instead it ships a Python module named pyxrt, at /opt/1bit-package/1bit/python/pyxrt.cpython-314-x86_64-linux-gnu.so. AMD's mlir-aie / IRON and mlir-air host code imports it as XRT's binding, so programs built with those tools run on the appliance's NPU (XDNA2, Strix / Strix Halo / Krackan) as they are.

It runs full ELFs only: one self-contained ELF per design, the form aiecc --get-full-elf writes. An xclbin cannot be loaded. Every xclbin call (pyxrt.xclbin, pyxrt.kernel, device.register_xclbin, hw_context(device, uuid)) raises a RuntimeError that says so. An xclbin-based script therefore stops at its first pyxrt.xclbin(...), with RuntimeError: pyxrt on 1bit OS runs full ELFs only (the ELF flow); the xclbin flow (pyxrt.xclbin) is not supported. Build the design as a full ELF: .... Rebuild it as a full ELF (below). pyxrt.implementation is "npu_rt", which tells this module apart from XRT's.

Set up#

AMD's tools come from their wheels, in a virtual environment of the appliance's Python (3.14):

python3 -m venv ~/iron && . ~/iron/bin/activate
pip install 'mlir_air[aie]' numpy ml_dtypes \
  -f https://github.com/Xilinx/mlir-air/releases/expanded_assets/latest-air-wheels \
  -f https://github.com/Xilinx/mlir-aie/releases/expanded_assets/latest-wheels-5 \
  -f https://github.com/Xilinx/llvm-aie/releases/expanded_assets/nightly
SP=$(python -c 'import site; print(site.getsitepackages()[0])')
export PYTHONPATH=/opt/1bit-package/1bit/python:$SP/mlir_air/python:$SP/mlir_aie/python
export PEANO_INSTALL_DIR=$SP/llvm-aie PATH=$SP/mlir_air/bin:$SP/mlir_aie/bin:$PATH

/opt/1bit-package/1bit/python must come first on PYTHONPATH, ahead of any other pyxrt. Check it with python -c 'import pyxrt; print(pyxrt.implementation)', which prints npu_rt. The NPU device node belongs to root on the appliance, so from a non-root shell run NPU programs with sudo -E. The appliance's desktop and console sessions run as root and need no sudo.

mlir-air pins a Peano (llvm-aie) version in utils/build-mlir-air-using-wheels.sh of its checkout. Install that version when you build its LLM examples. Those examples' host code also imports PyTorch, on the CPU, and reads weights with safetensors / huggingface_hub:

pip install torch --index-url https://download.pytorch.org/whl/cpu
pip install safetensors huggingface_hub tokenizers transformers

IRON designs alone need neither.

IRON#

Ask the JIT for a full ELF:

import numpy as np, aie.iron as iron
from aie.iron import CompileTime, In, Out
from aie.iron.algorithms import transform

@iron.jit(full_elf=True)
def add_one(inp: In, out: Out, *, n: CompileTime[int] = 1024):
    return transform(lambda x: x + 1, np.ndarray[(n,), np.dtype[np.int32]], tile_size=32)

iron.ensure_current_device()
x = iron.arange(1, 1025, dtype=np.int32, device="npu"); y = iron.zeros_like(x)
add_one(x, y)
assert (y.numpy() == x.numpy() + 1).all()

For a design built outside the JIT, use aiecc --get-full-elf (with --get-scratchpad-parameters when it takes runtime parameters). Then load the ELF with pyxrt.hw_context(device, pyxrt.elf(path)) and pyxrt.ext.kernel(context, "device:sequence"). Runtime parameters are written with mlir-aie's ParameterScratchpad into run.get_ctrl_scratchpad_bo(), as under XRT.

mlir-air#

Compile with output_format="elf" (XRTBackend(output_format="elf", ...)). The LLM examples' decodes are already full ELFs (DECODE_OUTPUT_FORMAT=elf, make compile-decode-elf). Their per-op prefills are full ELFs too (make compile-prefill CTX=<n>). The examples' fused prefill builds only as an xclbin today, because mlir-air's ELF output takes one function per device and the fused prefill has one per operation. Run those examples with the per-op prefill (--fused-prefill '').

What is covered#

The covered part of XRT's binding is what mlir-aie's aie.utils.hostruntime.xrtruntime / IRON and mlir-air's backend and examples call on the full-ELF path: - device and get_info (name, bdf); - bo, sub-buffers, ext.bo, with map, read, write, sync, address and size; - elf and module; - hw_context(device, elf); - ext.kernel; - run (set_arg, start, wait, wait2, state and get_ctrl_scratchpad_bo); - ert_cmd_state.

Not covered: - the xclbin flow (it raises, as above); - user-pointer buffers (ext.bo(device, pointer, size)); - runlist; - XRT's system, profiling and AIE debug interfaces.

View this page's source on GitHub ↗