<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/149472>149472</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[MLIR][Bindings][Transform] How to create foreach and include using MLIR python bindings
</td>
</tr>
<tr>
<th>Labels</th>
<td>
mlir
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Dasor
</td>
</tr>
</table>
<pre>
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.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy0V2-P2rgT_jTmjfWLgkMWeMELWH60SLvdVXdb6V4hJx6Ib42ds53l6Kc_jZ3wr-lVlXoWUgTjmXn8zHh4wp2TOw0wI_mC5MsBb3xl7GzJnbGDwojjbE3YeE-9PUq9o95QC7WSJfdAfQXUW67d1tg9hb_5vlZAlXQeBJWaknzhK-lOFpIvCZtU3teOZHPCVoStdtJXTZGUZk_YSqn37vG_2po_ofSErQplCsJWey41PpS0hK08OLSttYed5V4atC0lV9HnQWqudoSt7p-_ELaa2_3L1_-HIH7fqCQGmVLCJvEXGsxTWjSeNi6ctAJaH31lNC2kFlLvXELX9MAd5YWC75k4VEYBuUvpxksFG67F5h1Kb6z8Fn7WfA-COvirAV1CyBSp1cb3hwzBNieGN4GBu5RyR9e05JqwsadbqQWtzAG9SwvoWhhfUXKXnjyTrbHAyyo4a3Ftk7pUjQjJPpoDPZhGCerMHnyFPCj5hmC4pwVQYTTQg_RVHz0kWyX0I1ig0gV7aQQg0sZa0F4dacXfASufhs9dGj8xDEnntF0CthQ5nGvx9cQgm2wbXRI2jQHoxTpxSrLluSGTT0j4S2t7qgmboB9hbNNXIcYIuw8b8sU5xlMNsbtejzUkO_AYhTGEkkQ8DCFhY9_foMIVL1Vr43a34d5bF3CiabwgjJ2TlUa7Zg8Cg2Zz-kVLP_fentJOyXh5DoffrzOGwqy1A4uIn43U6Nexk-Bt7uUvIGUZffFQ0xRTfwBPOa24FrEtsZrtRTF1j3e0xYM5b5vSNxZE8sh9WT3VyR6fG1Nv8A64thA9KzLaVYEwpsI1TmJ4pCVf0l7wt1SEXwNJ7bGGeK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