The sources behind FastFlowLM's NPU support, for building and changing the parts flm loads:
| Folder | What it builds |
|---|---|
FLM_DLL/ |
the engine libraries, C++20, one shared library per model family |
FLM_Xclbin/ |
the NPU kernels (.xclbin): IRON Python → MLIR → Peano → aiecc.py |
FLM_Q4NX_Converter/ |
the weight converter: GGUF (or safetensors) → model.q4nx |
FLM_Pybind/SmolVLA/ |
a Python module for the SmolVLA robot policy |
aie2p-launchlib/ |
an experimental library for switching apps inside one NPU context |
A model needs three matching parts: its model.q4nx weights, its .xclbin kernels, and its engine
library. Nothing checks that they belong together. A mismatch gives wrong output or a hang, not an
error, so rebuild all the parts a change touches.
- x86-64 Linux, tested on Ubuntu 24.04, with
g++-13, Python 3.12, Boost (program_options,filesystem) and the XRT development files. - A CPU with AVX-512: the engines use it, and on a CPU without it they build but crash at run time.
- To run what you build: an AMD Ryzen AI NPU (Strix, Strix Halo or Krackan) with the
amdxdnadriver and XRT 2.19 or newer. - For kernels: mlir-aie and Peano (
llvm-aie) at the exact versions inFLM_Xclbin/README.md. Chess (Vitis AIE Essentials, with a license) is optional; Peano builds every kernel. - For HRX engine builds: the HRX package pinned in
../hrx-integration/hrx-release.env; for the shippable HRX build, Docker.
Run these from the FastFlowLM repository root.
Engines (XRT), all of them, into flm-dev-kit/FLM_DLL/build/lib/ (about 6 minutes on 32 cores):
bash flm-dev-kit/FLM_DLL/build.sh
bash flm-dev-kit/FLM_DLL/build_hunyuan.sh # or one engine and what it needs (build_<model>.sh)The engine libraries (FLM_DLL) build with the product's AVX-512 flags, not -march=native; pass
FLM_MARCH=-march=native to tune for your own CPU. Their XRT comes from /opt/xilinx/xrt, or /usr
when only the distribution's libxrt-dev is installed; XRT_ROOT=<prefix> picks another. Both live in
FLM_DLL/flags.mk. The kernel host programs under FLM_Xclbin do not read it:
they still use -march=native and /opt/xilinx/xrt.
Engines (HRX):
bash hrx-integration/fetch-hrx-release.sh # once: the pinned HRX package
FLM_USE_HRX=1 bash flm-dev-kit/FLM_DLL/build.sh
bash flm-dev-kit/FLM_DLL/build_manylinux.sh # the shippable build: glibc <= 2.28 container + ABI checkA kernel (first do the one-time setup in FLM_Xclbin/README.md):
export MLIR_AIE_DIR=$HOME/flm-toolchain/mlir-aie
export PEANO_INSTALL_DIR=$HOME/flm-toolchain/peano/llvm-aie
source flm-dev-kit/FLM_Xclbin/setup.sh
cd flm-dev-kit/FLM_Xclbin/Dequant_Q4_0_w128x512 && make bitstream # -> build/xclbins/dequant.xclbinFLM_Xclbin/kernel_assignment.md lists which kernel folders (and
MODEL_TYPEs) each model uses.
Weights:
cd flm-dev-kit/FLM_Q4NX_Converter
./setup_venv.sh && source activate.sh # once: venv from the pinned requirements.txt
python convert.py -i model.gguf -o out/ # -> out/model.q4nx; python convert.py --help for the restflm loads a model from its folder under $FLM_MODEL_PATH/models/ (else ~/.config/flm/models/):
model.q4nx, config.json and the tokenizer. The engine libraries and xclbins ship with flm itself.
To try yours, build flm from source (see the root README.md) after you:
- copy the engine library to
../src/lib/xrt/(XRT) or../src/lib/hrx/(HRX); - copy each xclbin, under the name the model expects (
kernel_assignment.md), to../src/xclbins/<MODEL>-NPU2/.
For a kernel-only change you can also swap the .xclbin in an installed flm; see
FLM_Xclbin/kernel_assignment.md. Adding a whole model has more
steps: FLM_DLL/ADDING_A_NEW_MODEL.md and "Adding a model?" in
../CONTRIBUTING.md.
Most kernel folders have a test program (make host, then ./run.exe). Many check the NPU against a
CPU reference on random inputs and print PASSED or FAILED; others compare with reference data you
point them at through $FLM_REFERENCE_DIR. Reference data is not shipped.
The engines build on Windows (XRT or HRX) with Visual Studio's C++ tools. After FastFlowLM's
.github\script\ci\setup_windows_deps.ps1 has laid out its dependencies under C:\dev, run
flm-dev-kit\FLM_DLL\build.ps1 in a Developer PowerShell (-Runtime HRX for the HRX engines, which
fetches the pinned HRX package first); the DLLs land in flm-dev-kit/FLM_DLL/build/lib/.
Details and overrides: FLM_DLL/README.md. Kernels are built on Linux.
The Windows HRX engines build in CI but were not run on an NPU in this release.
The dev kit is MIT, like FastFlowLM's source: see ../LICENSE_RUNTIME.txt.
Files that carry their own license line (for example code adapted from mlir-aie, under
Apache-2.0 WITH LLVM-exception) keep it. Third-party components are listed in
../THIRD_PARTY_NOTICES.txt.
AGENTS.md: the map, conventions and the constraints that break silently, for coding agents and contributors.FLM_DLL/ADDING_A_NEW_MODEL.md,FLM_Xclbin/README.md,FLM_Xclbin/kernel_assignment.md,FLM_Q4NX_Converter/README.md.