Graph Compiler is an end-to-end, MLIR-based compiler designed to enhance the performance of deep learning workloads. It accepts computation graphs from the frontend (primarily linalg on tensors), applies domain-specific optimizations and transformations, generates code, and manages runtime execution.
It is recommended for the users to use the all-in-one compile script at scripts/compile.sh. It downloads the LLVM dependency and builds the project.
To build this project step by step, first you need to find the LLVM commit-id we are using at cmake/llvm-version.txt. Then clone specific version of LLVM:
export LLVM_COMMIT_HASH=$(< cmake/llvm-version.txt)
git clone https://github.com/llvm/llvm-project
cd llvm-project
git checkout $LLVM_COMMIT_HASHBuild LLVM with the command lines given in .github/workflows/build-llvm.yml:
mkdir llvm-install
cmake -G Ninja llvm -B build -DCMAKE_INSTALL_PREFIX=llvm-install \
-DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=true -DLLVM_ENABLE_PROJECTS="mlir" -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_INSTALL_UTILS=true -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DLLVM_INSTALL_GTEST=ON
cmake --build build --target installNotes
- It is recommended to add optional options
-DLLVM_BUILD_LLVM_DYLIB=ON -DLLVM_LINK_LLVM_DYLIB=ONto the commandcmake -G Ninja llvm ...above if you are building for CPU only. These will enable the build of LLVM/MLIR dynamic libraries and let MLIR/LLVM tools link to them, to reduce the installed binary size of LLVM/MLIR. These options also enable theGC_DEV_LINK_LLVM_DYLIBoption of graph-compiler repo (see below). - The option
-DLLVM_INSTALL_GTEST=ONis optional, if the tests of graph-compiler are disabled (seeGC_ENABLE_TESTbelow). - If you would like to enable GPU components of Graph Compiler, please make sure to statically link Graph Compiler and LLVM(MLIR). It is a known issue that LLVM shared library cannot be linked together with IGC (Intel's low level GPU compiler). Make sure
LLVM_BUILD_LLVM_DYLIBandLLVM_LINK_LLVM_DYLIBareOFF(they are off by default). Also make sure Graph Compiler's cmake optionGC_DEV_LINK_LLVM_DYLIBisOFFwhen configuring Graph Compiler (see below). - If you would like to enable
BenchGCorMLIR Binding, please confirm to add options-DPython3_EXECUTABLE=`which python3` -DMLIR_ENABLE_BINDINGS_PYTHON=ON.
We have now installed LLVM at llvm-project/llvm-install.
Change working directory to graph-compiler repo and prepare the build directory:
cd /PATH/TO/graph-compiler
mkdir build && cd buildBuild and run tests:
cmake .. -G Ninja \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DMLIR_DIR=/PATH/TO/llvm-project/llvm-install/lib/cmake/mlir \
-DLLVM_EXTERNAL_LIT=$(which lit)
cmake --build . --target gc-checkNotes:
/PATH/TO/llvm-project/llvm-installshould be the install path of LLVM. If you installed LLVM elsewhere by-DCMAKE_INSTALL_PREFIXoption when building LLVM, you need to change the path in-DMLIR_DIRaccordingly.- The cmake option
-DLLVM_EXTERNAL_LITis for the tests of this project. It requires thelittool to be installed in the system. You can install it viapip install lit. If you don't need to run the tests of this repo, you can omit this option in the command line.
More notes if Intel® Extension for MLIR is on (-DGC_ENABLE_IMEX=ON):
- make sure the OpenCL runtime is installed in your system. You can either install using OS-provided package (Ubuntu 22.04)
sudo apt install -y intel-opencl-icd opencl-c-headersOr, download and install package from: https://github.com/intel/compute-runtime/releases
- the LLVM codebase needs to be patched to support XeGPU lowering (from IMEX). Please follow instructions of IMEX on patching LLVM.
Graph Compiler supports the following build-time options.
| CMake Option | Supported values (defaults in bold) | Description |
|---|---|---|
| GC_ENABLE_LEGACY | ON, OFF | Controls building the legacy graph-compiler component |
| GC_ENABLE_TEST | ON, OFF | Controls building the tests |
| GC_DEV_LINK_LLVM_DYLIB | ON, OFF | Controls dynamic link LLVM/MLIR libraries, mainly for developer |
| GC_ENABLE_BINDINGS_PYTHON | ON, OFF | Controls building the Python API |
| GC_ENABLE_IMEX | ON, OFF | Whether to enable the IMEX components |
| GC_ENABLE_GPU | ON, OFF | Whether to enable the GPU tools and components |