git clone https://github.com/Xilinx/mlir-air.git
cd mlir-air
sudo apt-get install -y ninja-build clang lld
source utils/setup_python_packages.sh
Run the build script:
Without XRT (software-only build):
./utils/build-mlir-air-using-wheels.sh [build_dir] [install_dir]
With XRT (for hardware execution):
./utils/build-mlir-air-using-wheels.sh --xrt-dir <xrt_path> [build_dir] [install_dir]
Parameters:
--xrt-dir <xrt_path>: Path to your XRT installation (optional, only needed for hardware execution)[build_dir]: Build directory (optional, default: build)[install_dir]: Install directory (optional, default: install)The script will:
llvm-aie, which is used as a backend to generate AIE binariesmlir-aie dependencies from wheels--xrt-dir is providedsource utils/env_setup.sh [install_dir] $(python3 -m pip show mlir_aie | grep Location | awk '{print $2}')/mlir_aie my_install/mlir
This command automatically detects the installation directories of the mlir-aie Python package, and sets up environment variables for MLIR-AIE, Python, and MLIR libraries.
If you built with XRT support, also run:
source [xrt_dir]/setup.sh
This sets up the PATHs for XRT.
If you start a new terminal, you may need to re-source the above setup scripts as needed.
cd <build_dir> # default is 'build'
ninja install
ninja check-air-cpp
ninja check-air-mlir
ninja check-air-python
If you built with XRT support, you can also run XRT/hardware tests:
# Run LIT tests (set -DLLVM_EXTERNAL_LIT if needed)
lit -sv --time-tests --show-unsupported --show-excluded --timeout 600 -j5 test/xrt
# Run an individual test
lit -sv test/xrt/01_air_to_npu
# Run all xrt tests on device (may take a long time)
ninja check-air-e2e-peano
-DLLVM_EXTERNAL_LIT to the path of your lit executable.After building MLIR-AIR, you can try the i8 matrix multiplication example to verify your setup and understand the different compilation workflows. Matmul shapes are configurable in the Makefile.
This mode is useful for cross-compilation or development without hardware access. It generates intermediate compilation artifacts without requiring XRT to be installed:
cd programming_examples/matrix_multiplication/i8
make run4x4 COMPILE_MODE=compile-only
Expected output: Compilation completed successfully!
What this does:
xclbinutil needed)When to use:
If you have XRT and Ryzen AI hardware available, run the complete workflow:
cd programming_examples/matrix_multiplication/i8
make run4x4
Expected output: PASS!
What this does:
This is the default mode (COMPILE_MODE=compile-and-run) for users with hardware.
For specialized workflows like profiling with custom test executables:
make profile
What this does:
compile-and-xclbin mode to generate xclbin and instructionsThe sweep4x4 target similarly uses compile-and-xclbin to benchmark across multiple problem sizes with a custom test harness.
Different herd configurations:
make run2x2 COMPILE_MODE=compile-only # 2x2 herd
make run8x4 COMPILE_MODE=compile-only # 8x4 herd
Different architectures:
make run4x4 AIE_TARGET=aie2p COMPILE_MODE=compile-only # For NPU2/Strix
make run4x4 AIE_TARGET=aie2 # For NPU1/Phoenix (default)
View generated MLIR:
make print # Display MLIR module without compiling
Clean build artifacts:
make clean
The same patterns work for other matrix multiplication examples:
programming_examples/matrix_multiplication/bf16/ - bfloat16 matrix multiplyprogramming_examples/matrix_multiplication/i16/ - int16 matrix multiplyExplore programming_examples/ for many more examples including:
Most examples follow similar Makefile patterns with COMPILE_MODE and AIE_TARGET support.
The following instructions describe the manual, source-based build process. This is generally not required unless you need to build from source for development or debugging.
The MLIR-AIE repo maintains instructions on how to install dependencies and configure your environment. Follow the instructions here. It is not necessary to follow the final steps for cloning/building/running MLIR-AIE itself.
Building MLIR-AIR requires several other open source packages:
These prerequisites can be installed with some helpful scripts found in the utils directory in the process described below.
First, clone the MLIR-AIR repo:
git clone https://github.com/Xilinx/mlir-air.git
cd mlir-air
Next, run utils/setup_python_packages.sh to setup the prerequisite python packages. This script creates and installs the python packages listed in utils/requirements.txt in a virtual python environment called sandbox.
source utils/setup_python_packages.sh
Next, clone and build LLVM, with MLIR enabled. In addition, we make some common build optimizations to use a linker (‘lld’ or ‘gold’) other than ‘ld’ (which tends to be quite slow on large link jobs) and to link against libLLVM.so and libClang.so. You may find that other options are also useful. Note that due to changing MLIR APIs, only a particular revision is expected to work.
Run the following to clone and build llvm:
./utils/clone-llvm.sh
./utils/build-llvm-local.sh llvm
Next, clone and build the aienginev2 module. The installed files should be generated under aienginev2/install.
./utils/github-clone-build-libxaie.sh
Next, clone and build MLIR-AIE with paths to llvm, aienginev2, and cmakeModules repositories. MLIR-AIE requires some dependent packages to be installed. For details on the MLIR-AIE prerequisites, please refer to the MLIR-AIE repository. Once the prerequisites are set up, run the following commands to build MLIR-AIE.
./utils/clone-mlir-aie.sh
./utils/build-mlir-aie-local.sh llvm mlir-aie/cmake/modulesXilinx aienginev2/install mlir-aie
After this step, you are ready to build MLIR-AIR!
To build MLIR-AIR provide the paths to llvm, cmakeModules, and xrt (here, we assume it is installed in /opt/xilinx/xrt):
./utils/build-mlir-air-xrt.sh llvm mlir-aie/cmake/modulesXilinx mlir-aie aienginev2/install /opt/xilinx/xrt
To setup your environment after building:
source utils/env_setup.sh install-xrt/ mlir-aie/install/ llvm/install/
Note that if you are starting a new environment (e.g., by creating a new terminal sometime after building), restore your environment with:
source utils/env_setup.sh install-xrt/ mlir-aie/install/ llvm/install/
source sandbox/bin/activate
Some tests for MLIR-AIR are provided. Run them as demonstrated below:
cd mlir-air/build-xrt
ninja install
ninja check-air-cpp
ninja check-air-mlir
ninja check-air-python
# These are the ones in test/xrt, and this is about equivalent to `ninja check-air-e2e` if you set the LIT_OPS env var appropriately
lit -sv --time-tests --show-unsupported --show-excluded --timeout 600 -j5 test/xrt
# Run an individual test
lit -sv test/xrt/01_air_to_npu
# Run all xrt tests on device. Takes a long time.
ninja check-air-e2e
Copyright© 2022 Advanced Micro Devices, Inc.