关于MLIR 官方的toy例子就非常好,但是非常分散,在实际项目中需要有一个统一的文件组织进行MLIR编译器的开发,本项目基于toy进行修改,统一文件排序规范以及链接库的整理。
- flow.constant ✅
- flow.func ✅
- flow.return ✅
- flow.transpose ✅
- flow.reshape ✅
- flow.add ✅
- flow.mul ✅
- flow.sub ✅
- flow.div ✅
- flow.print ✅ (支持各种print)
- flow.dot ✅
- flow.sum ✅ (1D)
- support math Dialect ✅
- matmul(linalg)
- conv1d(linalg)
- conv2d(linalg)
- sqrt ✅
- exp ✅
- pow ✅
flow.func @main() {
%0 = flow.constant dense<[1.0, 2.0, 3.0, 4.0, 9.0, 32.0]> : tensor<6xf64>
%2 = flow.sum %0: tensor<6xf64> to f64
%3 = flow.dot %0, %0: tensor<6xf64>, tensor<6xf64> to f64
%4 = math.atan %3: f64
flow.print %4: f64
flow.return
}
use
mlir::ExecutionEngineOptions engineOptions;
engineOptions.transformer = optPipeline;
engineOptions.sharedLibPaths = {"", ""};
将custom dialect lowering to vector dialect. (need to read vector lowering source file).
## 2023.04.25 update
use pre-built mlir && llvm library
https://github.com/ptillet/triton-llvm-releases
or build yourself.
git clone https://github.com/llvm/llvm-project.git
cd llvm-project && git checkout release/16.x && mkdir build && cd build
cmake -G Ninja ../llvm \
-DLLVM_ENABLE_PROJECTS="mlir;clang" \
-DLLVM_BUILD_EXAMPLES=ON \
-DLLVM_TARGETS_TO_BUILD="host;RISCV;ARM;X86" \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DMLIR_ENABLE_BINDINGS_PYTHON=ON \
-DLLVM_CCACHE_BUILD=ON \
-DMLIR_ENABLE_BINDINGS_PYTHON=ON
# wait a coffe time.
cd flow-mlir && mkdir build
cmake .. # you should look CMakelists.txt to change your mlir build path
make