onnx-mlir
onnx-mlir copied to clipboard
Add ONNXToLinalg Conversion
I found that the proposal from Microsoft of using Linalg worth of exploring. The Linalg has some good features and there are existing optimization passes and backend. I am working on a draft to add passes to lower some ONNX Op to Linalg while the current lowering to knrl is kept working. The passes will look like:
existing passes
1. ONNXToLinalg
2. ONNXToKrnl
3. KrnlToAffine
4. LinalgToAffine
existing passes
The order of 1 and 2, and that of 3 and 4 may be switchable. In my experiment, I will only translate one ONNX op (currently, ONNXMatMul is chosen for simplicity) to Linalg. I will use memref for Linalg Op. I feel it may be easier to incorporate ONNX shape inference result for allocation and ONNXToKrnl conversion to lower to memref, instead of using the Linalg detensor pass. Will this decision be a problem for future optimization?
If the framework is set up, collaboration is needed to implement conversion of more ONNX Ops to Linalg. Which lowering should be applied to each ONNX Ops may be controlled by options and restricted by expressiveness of dialect. If the conversion to Linalg is disabled, onnx-mlir works as it does now.
Comments are welcomed.