Fan Jiang @ GT
  • About
  • All posts

Getting Started to MLIR in 2021 - Thu, Jun 3, 2021

Tips and pitfalls bootstraping MLIR

I recently got some interest into making compilers, and MLIR seems to be a great choice.

Compiling MLIR

The official guide suggests that you use these arguments to compile MLIR:

cmake -G Ninja ../llvm \
   -DLLVM_ENABLE_PROJECTS=mlir \
   -DLLVM_BUILD_EXAMPLES=ON \
   -DLLVM_TARGETS_TO_BUILD="X86;NVPTX;AMDGPU" \
   -DCMAKE_BUILD_TYPE=Release \
   -DLLVM_ENABLE_ASSERTIONS=ON \
   -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DLLVM_ENABLE_LLD=ON

However, it will lead to problems later if you are going to use MLIR in an external project. For example, if you directly copy the official example/standalone project, you will see this problem.

Use the argument below when compiling to avoid problems like: ``` CMake Error at /home/MLIR/llvm_install/lib/cmake/llvm/AddLLVM.cmake:1790 (add_dependencies): The dependency target "FileCheck" of target "check-standalone-standalone" does not exist. ``` ```bash cmake -G Ninja ../llvm \ -DLLVM_ENABLE_PROJECTS=mlir \ -DLLVM_BUILD_EXAMPLES=ON \ -DLLVM_TARGETS_TO_BUILD="X86;NVPTX;AMDGPU" \ -DCMAKE_BUILD_TYPE=Release \ -DLLVM_ENABLE_ASSERTIONS=ON \ -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DLLVM_ENABLE_LLD=ON \ -DLLVM_INSTALL_UTILS=ON -DCMAKE_INSTALL_PREFIX=/home/MLIR/llvm_install ``` `-DLLVM_INSTALL_UTILS` will make the `FileCheck` and `not` executables to be installed to the final install directory. MLIR needs these in order to compile even when used out-of-tree.

Standalone Example

Compiling the standalone example project is easy. First make sure that you install the build LLVM project to a prefix, and now you can compile the standalone demo with:

cmake -G Ninja .. -DMLIR_DIR=$LLVM_INSTALL_PREFIX/lib/cmake/mlir -DLLVM_EXTERNAL_LIT=$LLVM_BUILD_DIR/bin/llvm-lit

Note that the build dir is <somewhere>/llvm-project/build if you use the official guide.$LLVM_INSTALL_PREFIX is what you have input in CMAKE_INSTALL_PREFIX.

Adapting the MLIR tutorial

Basically what you need is to reduce the standalone example project. If you want to see a complete repo, see here.

Back to Home


hugo.386 theme | © Fan Jiang 2020 | All rights reserved.

Twitter GitHub