-
Notifications
You must be signed in to change notification settings - Fork 519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ONNX] onnx.Loop #3136
Comments
Rob's Guide for Implementing If and Loop Constructs with Regions in ONNX LoweringTLDR:
Some conceptsBlock: A basic block with a single entry and exit point. Fundamental unit within a region.
How Linalg and SCF use Regions
|
Rob gave this reference for manipulating regions: https://github.com/llvm/llvm-project/blob/main/mlir/lib/Conversion/TosaToSCF/TosaToSCF.cpp Inline if case Rewrite terminators: the region's parent defines the rules about what terminators the region has. E.g. "must have 1 terminator block that ends in a particular op. e.g. functions must end with return" e.g. in SCF, 2 blocks for If / else. Has to "scf yield" at the end. What's getting returned is given in the yield. e.g. in while, one of the blocks has to have a conditional, and the other block has to have a yield block. before / after block for for style loops do while: before block and after block. scf while: yield op is both the conditional and the before block |
onnx binder:
RegionRange.size() |
Running this to test if import: wget -O onnx_conditional_example.py https://gist.githubusercontent.com/renxida/6e859dbfab286916dd8b99542c0a2332/raw/e38d1558a2bdc9553a14338ca84c8f1ae4bb40b5/onnx_conditional_example.py
python onnx_conditional_example.py
PYTHONPATH=~/torch-mlir/build/tools/torch-mlir/python_packages/torch_mlir python -m torch_mlir.tools.import_onnx ./conditional_example.onnx -o conditional_example.mlir |
Will need to extend importer for blocks and regions.
example test case here
https://gist.github.com/renxida/6e859dbfab286916dd8b99542c0a2332
Todo list for now:
Torch ops to translate to:
PrimLoopOp
PrimIfOp
PrimIfYieldOp
Methods / types of interest:
mlir::Region
PrimIfOp::getThenRegion
PrimIfOp::getElseRegion
PrimIfOp::getSuccessorRegions
The text was updated successfully, but these errors were encountered: