Commit 1477e98
authored
[TritonArithToLinalg] Lower batched matmul from tt.dot to linalg.batch_matmul (#35)
**Problem:**
Triton uses the same tt.dot() operation for both matmul and batched
matmul: for 3D operands, the first dimension is a batch dimension and
tt.dot performs a batched matrix product. The current lowering did not
account for this and always emitted linalg.matmul, which only supports
2D operands.
Running triton-shared-opt --triton-arith-to-linalg on a 3D tt.dot
therefore failed with:
```
error: 'linalg.matmul' op expected operand #0 rank (3) to match the
result rank of indexing_map (2)
```
**Solution:**
`MatmulConverter` now inspects the rank of the result tensor and emits
`linalg.batch_matmul` for rank-3 operands (and linalg.matmul for rank-2,
as before). Rank > 3 is not supported and now fails the pattern instead
of producing an invalid op.
**Testing:**
Adds a lit test (batched_matmul.mlir) covering the 3D case.1 parent bce5578 commit 1477e98
2 files changed
Lines changed: 41 additions & 3 deletions
Lines changed: 13 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1099 | 1099 | | |
1100 | 1100 | | |
1101 | 1101 | | |
1102 | | - | |
1103 | | - | |
1104 | | - | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
1105 | 1115 | | |
1106 | 1116 | | |
1107 | 1117 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
0 commit comments