Skip to content

Notes on compilation pipeline from Devito MLIR llvm IR .so

George Bisbas edited this page Jun 3, 2023 · 5 revisions

Notes on compilation pipeline from Devito->MLIR -> llvm IR .so

Lowering Devito to XDSL

The current example.py can be found on our branch; it applies the iet_to_standard_mlir pass

python3 example.py > raw.mlir

This lowers devito to something that's mlir-compatible

Optimizing with mlir-opt

cat raw.mlir | mlir-opt -cse -loop-invariant-code-motion --mlir-print-op-generic > optimized.mlir

Lowering MLIR to LLVM dialect

cat optimized.mlir | mlir-opt -convert-scf-to-cf -convert-cf-to-llvm -convert-arith-to-llvm -convert-math-to-llvm -convert-func-to-llvm -reconcile-unrealized-casts > llvm.mlir

Lowering LLVM dialect to LLVMIR

cat llvm.mlir | mlir-translate --mlir-to-llvmir > llvm.ll

Lowering LLVM to .so

clang -O3 -shared llvm.ll -o kernel.so

Building instructions from Anton:

# mlir
RUN mkdir llvm-project \
    && cd llvm-project \
    && git init \
    && git remote add origin https://github.com/llvm/llvm-project.git \
    && git fetch origin 04fc02e583b06b846315904a55af9c273c8b20b9 \
    && git reset --hard FETCH_HEAD

RUN mkdir llvm-project/build \
 && cd llvm-project/build \
 && cmake -G Ninja ../llvm -DLLVM_ENABLE_PROJECTS="mlir;clang;openmp" -DLLVM_BUILD_EXAMPLES=ON -DLLVM_TARGETS_TO_BUILD="X86" -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=OFF -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DLLVM_ENABLE_LLD=ON

RUN cd llvm-project/build \
 && cmake --build . --target install