Building the code¶
Versal AI Engine flow
This page covers the Versal™ AI Engine flow (VCK190). It is supported but is not part of the actively-tested Ryzen™ AI (NPU) path.
Prerequisites¶
lld
cmake 3.20.6
ninja 1.8.2
Xilinx Vitis 2023.2
python 3.8.x and pip
virtualenv
pip3 install rich pybind11 numpy
clang/llvm 14+ from source https://github.com/llvm/llvm-project
Xilinx Vitis can be downloaded and installed from the Xilinx Downloads site.
In order to successfully install Vitis on a fresh bare-bones Ubuntu install, some additional prerequisites are required, documented here. For Ubuntu 20.04, the installation should succeed if you additionally install the following packages: libncurses5 libtinfo5 libncurses5-dev libncursesw5-dev ncurses-compat-libs libstdc++6:i386 libgtk2.0-0:i386 dpkg-dev:i386 python3-pip Further note that the above mentioned cmake prerequisite is not satisfied by the package provided by Ubuntu; you will need to obtain a more current version.
NOTE: Using the Vitis recommended settings64.sh script to set up your environement can cause tool conflicts. Setup your environment in the following order for aietools and Vitis:
export PATH=$PATH:<Vitis_install_path>/Vitis/2023.2/aietools/bin:<Vitis_install_path>/Vitis/2023.2/bin
The cmake and python packages prerequisites can be satisfied by sourcing the utils/setup_python_packages.sh script. See step 2 of the build instructions.
This script requires virtualenv.
clang/llvm 14+ are recommended to be built with the provided scripts. See step 3. of the build instructions.
Building on X86 for mlir-aie development¶
-
Clone the
mlir-aierepository with its sub-modules:All subsequent steps should be run from inside the top-level directory of the
mlir-aierepository cloned above. -
Source
utils/setup_python_packages.shto setup the prerequisite python packages. This script creates and installs the python packages listed inpython/requirements.txtandpython/requirements_dev.txtin a virtual python environment called 'sandbox', then it enters the sandbox:If you need to exit the sandbox later, type
deactivate. If you have a recent Linux distribution, you might not need this, as you are able to have all the required packages from the distribution. -
Clone and compile LLVM, with the ability to target AArch64 as a cross-compiler, and with MLIR enabled: in addition, we make some common build optimizations to use a linker (
lldorgold) other thanld(which tends to be quite slow on large link jobs) and to link againstlibLLVM.soandlibClang.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.To clone
llvm, runutils/clone-llvm.sh(seeutils/clone-llvm.shfor the correctllvmcommit hash):If you have already an LLVM repository, you can instead of cloning just make a new worktree from it by using:
To build (compile and install) LLVM, run
This will build LLVM inutils/build-llvm-local.shin the directory wherellvmhas been cloned. Seeutils/build-llvm-local.shfor additional shell script arguments. (Note thatbuild-llvm-local.shandbuild-llvm.share a variation of the LLVM build script used for CI on GitHub and looking at the continuous integration recipe https://github.com/Xilinx/mlir-aie/blob/main/.github/workflows/buildAndTest.yml and output https://github.com/Xilinx/mlir-aie/actions/ might help in the case of compilation problem.)llvm/buildand install the LLVM binaries underllvm/install. -
Build the MLIR-AIE tools by calling
utils/build-mlir-aie.shwith the path to thellvm/builddirectory. The Vitis environment will have to be set up for this to succeed.Building mlir-aie for a Ryzen AI system:
This will create a
buildandinstallfolder in the directory that you cloned MLIR AIE into.The MLIR AIE tools will be able to generate binaries targetting a combination of AIEngine and ARM/x86 processors.
-
In order to run all the tools, it is necessary to add some paths into your environment. This can be done by sourcing the
utils/env_setup.shscript with the paths to the install folders for mlir-aie and llvm.
Note that when coming back to this install with a fresh environment, it is necessary to rerun the utils/env_setup.sh script to setup your environment as well as activate the Python virtual environment using the following command.
Sysroot¶
Since the AIE tools are cross-compiling, in order to actually compile code, we need a 'sysroot' directory, containing an ARM rootfs. This rootfs must match what will be available in the runtime environment. Note that copying the rootfs is often insufficient, since many root file systems include absolute links. Absolute symbolic links can be converted to relative symbolic links using symlinks.
Following the platform build steps will create such a sysroot based on PetaLinux. Note that those instructions require Vitis 2021.2 -- building a sysroot with Vitis 2023.2 will not currently succeed.Copyright© 2019-2025 AMD/Xilinx