MLIR 学习1
本文记录了MLIR 的学习过程。本文记录的是 MLIR Toy Tutorial 的学习过程。
感谢网上的一些博主的指引
知乎-入门MLIR(1)- Toy CH1 & CH2
0. MLIR compile
Refer to the official tutorial(s)
Refer to the official tutorial 参考官方安装教程。
git clone https://github.com/llvm/llvm-project.git
mkdir llvm-project/build
cd llvm-project/build
cmake -G Ninja ../llvm \-DLLVM_ENABLE_PROJECTS=mlir \-DLLVM_BUILD_EXAMPLES=ON \-DLLVM_TARGETS_TO_BUILD="Native;NVPTX;AMDGPU" \-DCMAKE_BUILD_TYPE=Release \-DLLVM_ENABLE_ASSERTIONS=ON
# Using clang and lld speeds up the build, we recommend adding:
# -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DLLVM_ENABLE_LLD=ON
# CCache can drastically speed up further rebuilds, try adding:
# -DLLVM_CCACHE_BUILD=ON
# Optionally, using ASAN/UBSAN can find bugs early in development, enable with:
# -DLLVM_USE_SANITIZER="Address;Undefined"
# Optionally, enabling integration tests as well
# -DMLIR_INCLUDE_INTEGRATION_TESTS=ON
cmake --build . --target check-mlir
完成编译后,可以采用如下命令确认,
./build/bin/toyc-ch1 mlir/test/Examples/Toy/Ch1/ast.toy -emit=ast
-emit=ast ,表示以ast 格式输出,执行以上命令之后,可以看到,ast.toy的ast格式输出结果,如下内容:
Module:FunctionProto 'multiply_transpose' @mlir/test/Examples/Toy/Ch1/ast.toy:4:1Params: [a, b]Block {ReturnBinOp: * @mlir/test/Examples/Toy/Ch1/ast.toy:5:25Call 'transpose' [ @mlir/test/Examples/Toy/Ch1/ast.toy:5:10var: a @mlir/test/Examples/Toy/Ch1/ast.toy:5:20]Call 'transpose' [ @mlir/test/Examples/Toy/Ch1/ast.toy:5:25var: b @mlir/test/Examples/Toy/Ch1/ast.toy:5:35]} // BlockFunctionProto 'main' @mlir/test/Examples/Toy/Ch1/ast.toy:8:1Params: []Block {VarDecl a<> @mlir/test/Examples/Toy/Ch1/ast.toy:11:3Literal: <2, 3>[ <3>[ 1.000000e+00, 2.000000e+00, 3.000000e+00], <3>[ 4.000000e+00, 5.000000e+00, 6.000000e+00]] @mlir/test/Examples/Toy/Ch1/ast.toy:11:11VarDecl b<2, 3> @mlir/test/Examples/Toy/Ch1/ast.toy:15:3Literal: <6>[ 1.000000e+00, 2.000000e+00, 3.000000e+00, 4.000000e+00, 5.000000e+00, 6.000000e+00] @mlir/test/Examples/Toy/Ch1/ast.toy:15:17VarDecl c<> @mlir/test/Examples/Toy/Ch1/ast.toy:19:3Call 'multiply_transpose' [ @mlir/test/Examples/Toy/Ch1/ast.toy:19:11var: a @mlir/test/Examples/Toy/Ch1/ast.toy:19:30var: b @mlir/test/Examples/Toy/Ch1/ast.toy:19:33]VarDecl d<> @mlir/test/Examples/Toy/Ch1/ast.toy:22:3Call 'multiply_transpose' [ @mlir/test/Examples/Toy/Ch1/ast.toy:22:11var: b @mlir/test/Examples/Toy/Ch1/ast.toy:22:30var: a @mlir/test/Examples/Toy/Ch1/ast.toy:22:33]VarDecl e<> @mlir/test/Examples/Toy/Ch1/ast.toy:25:3Call 'multiply_transpose' [ @mlir/test/Examples/Toy/Ch1/ast.toy:25:11var: c @mlir/test/Examples/Toy/Ch1/ast.toy:25:30var: d @mlir/test/Examples/Toy/Ch1/ast.toy:25:33]VarDecl f<> @mlir/test/Examples/Toy/Ch1/ast.toy:28:3Call 'multiply_transpose' [ @mlir/test/Examples/Toy/Ch1/ast.toy:28:11var: a @mlir/test/Examples/Toy/Ch1/ast.toy:28:30var: c @mlir/test/Examples/Toy/Ch1/ast.toy:28:33]} // Block