Issue |
149472
|
Summary |
[MLIR][Bindings][Transform] How to create foreach and include using MLIR python bindings
|
Labels |
mlir
|
Assignees |
|
Reporter |
Dasor
|
I'm trying to replicate the transform example listed in [this example ](https://github.com/llvm/llvm-project/blob/main/mlir/test/Integration/Dialect/Linalg/CPU/ArmSVE/matmul.mlir) (matmul SVE) but using the python bindings. I was able to replicate the whole` _tile_and_vectorize` named sequence but I'm not able to replicate the` __transform_main` as I can't find how to create both `transform.foreach` and `transform.include` How would something like that be done with the python bindings?. Here is the code I currently have:
```python
def tileAndVectorize(func):
sequence = transform.NamedSequenceOp(
"__tile_and_vectorize",
[transform.OperationType.get("func.func")],
[],
arg_attrs = [{"transform.consumed": UnitAttr.get()}],
)
with InsertionPoint(sequence.body):
# Step 0: Get a handle to the matmul op
matmuls = structured.MatchOp.match_op_names(
func,
["linalg.matmul"]
)
# Step 1: Tile
tiled = structured.TileUsingForOp(matmuls.result, sizes=[2,[4],1])
# Step 2: Vectorize
structured.VectorizeOp(tiled.results[0], [2, [4], 1])
# Step 3: Lower vector.multi_reduction to vector.contract (+ some helpful patterns)
with InsertionPoint(transform.ApplyPatternsOp(func).patterns):
vector.ApplyVectorReductionToContractPatternsOp()
vector.ApplyTransferPermutationPatternsOp()
vector.ApplyLowerMaskedTransfersPatternsOp()
vector.ApplySinkVectorPatternsOp()
vector.ApplyLowerMaskedTransfersPatternsOp()
vector.ApplyLowerContractionPatternsOp(lowering_strategy=vector.VectorContractLowering.OuterProduct)
vector.ApplyLowerOuterProductPatternsOp()
transform.YieldOp([])
def transform_main():
sequence = transform.NamedSequenceOp(
"__transform_main",
[transform.AnyOpType.get()],
[],
arg_attrs = [{"transform.consumed": UnitAttr.get()}],
)
with InsertionPoint(sequence.body):
# get all the functions
funcs = structured.MatchOp.match_op_names(
sequence.bodyTarget,
["func.func"]
)
## MISSING: how to use transform.foreach + transform.include ???
transform.YieldOp([])
```
as said the `tileAndVectorize` already works, but I don't know what to put in the `transform_main`. Any help is appreciated, thanks in advance.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs