Commit e56f5cb
committed
[mlir][linalg] Fix and Refactor DecomposeOuterUnitDimsUnPackOpPattern
This PR fixes an issue identified in #118786, where the following
example triggers a verification error:
```mlir
func.func @foo(
%src: tensor<1x1x2x?xf32>,
%dest: tensor<5x1xf32>,
%tile_dim: index) -> tensor<5x1xf32> {
%0 = tensor.unpack %src
inner_dims_pos = [1, 0]
inner_tiles = [2, %tile_dim]
into %dest : tensor<1x1x2x?xf32> -> tensor<5x1xf32>
return %0 : tensor<5x1xf32>
}
```
The error occurs because of faulty logic when computing dynamic sizes
for `tensor::EmptyOp`, which initializes tensors for `linalg::transpose`.
This specific example fails due to:
* Dynamic inner tile size, combined with
* Non-identity permutation.
For reference, here's the verification error:
```bash
error: 'tensor.empty' op incorrect number of dynamic sizes, has 0, expected 1
```
and here's the problematic `tensor.empty` (printed in generic form):
```mlir
%1 = "tensor.empty"() : () -> tensor<?x2xf32>
```
**Fix**
This PR refactors how dynamic sizes for `tensor::EmptyOp` are computed. Instead
of generating a separate vector of dynamic sizes to complement the output
shape, this PR adopts a common MLIR idiom: passing a vector of `OpFoldResult`s
directly to the `EmptyOp` builder. Previously, only dynamic sizes corresponding
to outer dimensions were tracked (see `dynamicSizes`), while inner dimensions
were skipped, causing issues in certain cases.
**Refactoring changes**
Variable names have been updated for better readability:
* `readShape` → `readShapeForExtractSlice`
* `readSizes` → `extractSliceSizes`
* `readStrides` → `stridesForExtractSlice`
Additional comments have been added for clarity.
**Remaining inconsistencies**
Patterns for `tensor::PackOp` and `tensor::UnpackOp` remain partially inconsistent:
`DecomposeOuterUnitDimsPackOpPattern` enforces that all outer dimensions must be
unit-sized, while `DecomposeOuterUnitDimsUnPackOpPattern` does not. The two
implementations have diverged in logic. I plan to address these inconsistencies
in a follow-up PR to further unify these patterns.1 parent 1885886 commit e56f5cb
File tree
2 files changed
+65
-31
lines changed- mlir
- lib/Dialect/Linalg/Transforms
- test/Dialect/Linalg
2 files changed
+65
-31
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1252 | 1252 | | |
1253 | 1253 | | |
1254 | 1254 | | |
1255 | | - | |
| 1255 | + | |
| 1256 | + | |
1256 | 1257 | | |
1257 | 1258 | | |
1258 | 1259 | | |
1259 | 1260 | | |
1260 | 1261 | | |
1261 | 1262 | | |
1262 | | - | |
1263 | | - | |
1264 | | - | |
1265 | | - | |
1266 | | - | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
1267 | 1276 | | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
1268 | 1283 | | |
1269 | | - | |
| 1284 | + | |
1270 | 1285 | | |
1271 | 1286 | | |
1272 | 1287 | | |
| 1288 | + | |
1273 | 1289 | | |
1274 | | - | |
| 1290 | + | |
1275 | 1291 | | |
1276 | | - | |
1277 | | - | |
| 1292 | + | |
| 1293 | + | |
1278 | 1294 | | |
1279 | | - | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
1280 | 1303 | | |
1281 | | - | |
1282 | | - | |
1283 | 1304 | | |
1284 | 1305 | | |
1285 | | - | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
1286 | 1310 | | |
1287 | 1311 | | |
1288 | 1312 | | |
1289 | 1313 | | |
1290 | 1314 | | |
1291 | | - | |
| 1315 | + | |
1292 | 1316 | | |
1293 | | - | |
| 1317 | + | |
1294 | 1318 | | |
1295 | | - | |
| 1319 | + | |
| 1320 | + | |
1296 | 1321 | | |
1297 | 1322 | | |
1298 | 1323 | | |
1299 | 1324 | | |
1300 | 1325 | | |
1301 | 1326 | | |
1302 | | - | |
1303 | | - | |
| 1327 | + | |
1304 | 1328 | | |
1305 | 1329 | | |
1306 | | - | |
| 1330 | + | |
1307 | 1331 | | |
1308 | 1332 | | |
1309 | 1333 | | |
1310 | 1334 | | |
1311 | 1335 | | |
1312 | | - | |
| 1336 | + | |
1313 | 1337 | | |
1314 | 1338 | | |
1315 | 1339 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
39 | | - | |
| 38 | + | |
| 39 | + | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
46 | | - | |
| 45 | + | |
| 46 | + | |
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
56 | | - | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
57 | 71 | | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | 72 | | |
63 | 73 | | |
64 | 74 | | |
| |||
0 commit comments