Getting Started on Linux with CMake

This guide walks through building the core compiler and runtime parts of IREE from source. Auxiliary components like the Python bindings and Vulkan driver are documented separately, as they require further setup.

Prerequisites

Install CMake

IREE uses CMake version >= 3.13.4. First try installing via your distribution's package manager and verify the version:

$ sudo apt install cmake
$ cmake --version # >= 3.13.4

Some package managers (like apt) distribute old versions of cmake. If your package manager installs a version < 3.13.4, then follow the installation instructions here to install a newer version (e.g. the latest).

Tip:
    Your editor of choice likely has plugins for CMake, such as the Visual Studio Code CMake Tools extension.

Install Ninja

Ninja is a fast build system that you can use as a CMake generator. Follow Ninja's installing documentation.

Install a Compiler

We recommend Clang. GCC is not fully supported.

$ sudo apt install clang

Clone and Build

Clone

Clone the repository and initialize its submodules:

$ git clone https://github.com/google/iree.git
$ cd iree
$ git submodule update --init

Tip:
    Editors and other programs can also clone the repository, just make sure that they initialize the submodules.

Build

Configure:

$ cmake -G Ninja -B ../iree-build/ -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ .

Tip:
    The root CMakeLists.txt file has options for configuring which parts of the project to enable.
    These are further documented in CMake Options and Variables.

Build all targets:

$ cmake --build ../iree-build/

What's next?

Take a Look Around

Check out the contents of the ‘tools’ build directory:

$ ls ../iree-build/iree/tools
$ ../iree-build/iree/tools/iree-compile --help

Translate a MLIR file and execute a function in the compiled module:

$ ../iree-build/iree/tools/iree-run-mlir $PWD/iree/samples/models/simple_abs.mlir \
  -function-input="f32=-2" -iree-hal-target-backends=vmvx -print-mlir

LLVM Ahead-of-Time (AOT) backend

Translate a source MLIR into an IREE module:

# Assuming in IREE source root
$ ../iree-build/iree/tools/iree-compile \
    -iree-mlir-to-vm-bytecode-module \
    -iree-llvm-target-triple=x86_64-linux-gnu \
    -iree-hal-target-backends=dylib-llvm-aot \
    iree/samples/models/simple_abs.mlir \
    -o /tmp/simple_abs_dylib.vmfb

Then run the compiled module using the dylib HAL driver:

$ ../iree-build/iree/tools/iree-run-module \
    --driver=dylib \
    --module_file=/tmp/simple_abs_dylib.vmfb \
    --entry_function=abs \
    --function_input=f32=-5

EXEC @abs
f32=5

Further Reading