A minimal, custom MLIR backend pipeline that lowers PyTorch models directly to native OpenBLAS execution.
This project demonstrates how to write a custom MLIR pass to intercept linalg.matmul operations and swap them with optimized C-calls to OpenBLAS, completely bypassing LLVM's default nested loops.
- LLVM & MLIR
- Torch-MLIR
- OpenBLAS (
sudo apt-get install libopenblas-dev)
custom-opt/: Contains the C++ source for the custom MLIR pass (ConvertMatmulToBlas.cpp).compile.sh: The progressive lowering pipeline that translates.mlirto LLVM IR, compiles to an object file, and links the native libraries.main.cpp: The C++ runner that initializes theMemRefDescriptor, calls the compiled MLIR function, and handles I/O.
export PATH=/path/to/torch-mlir/build/bin:$PATH
export PYTHONPATH=/path/to/torch-mlir/build/tools/torch-mlir/python_packages/torch_mlir:$PYTHONPATH