Commit a5c1a2d
[mlir][linalg] Extend DecomposeOuterUnitDimsPackOpPattern (linalg.pack) (llvm#162666)
Similarly to llvm#152960, this PR fixes `getTiledOuterDims` for `linalg.pack` by
ensuring that the `outer_dims_perm` attributeis properly taken into account.
This enables the main change in this PR: relaxing the constraints in
* `DecomposeOuterUnitDimsPackOpPattern`.
Specifically, the pattern is extended to allow non-unit untiled outer
dimensions. For example:
```mlir
func.func @example(
%src: tensor<2x32x16x8xf32>,
%dest: tensor<2x1x16x8x32xf32>) -> tensor<2x1x16x8x32xf32> {
%pack = linalg.pack %src
inner_dims_pos = [1]
inner_tiles = [32] into %dest
: tensor<2x32x16x8xf32> -> tensor<2x1x16x8x32xf32>
return %pack : tensor<2x1x16x8x32xf32>
}
```
decomposes as:
```mlir
func.func @example(
%src: tensor<2x32x16x8xf32>,
%dest: tensor<2x1x16x8x32xf32>) -> tensor<2x1x16x8x32xf32> {
%0 = tensor.empty() : tensor<2x16x8x32xf32>
%transposed = linalg.transpose
ins(%src : tensor<2x32x16x8xf32>)
outs(%init : tensor<2x16x8x32xf32>)
permutation = [0, 2, 3, 1]
%inserted_slice = tensor.insert_slice %transposed
into %dest[0, 0, 0, 0, 0] [2, 1, 16, 8, 32] [1, 1, 1, 1, 1]
: tensor<2x16x8x32xf32> into tensor<2x1x16x8x32xf32>
return %inserted_slice : tensor<2x1x16x8x32xf32>
}
```
Importantly, this change makes `DecomposeOuterUnitDimsPackOpPattern` (the
decomposition pattern for `linalg.pack`) consistent with the corresponding
pattern for `linalg.unpack`:
* `DecomposeOuterUnitDimsUnPackOpPattern`.
One notable assumption remains: untiled outer dimensions are not permuted. This
was already the case but is now explicitly documented.
Co-authored by: Max Bartel <[email protected]>1 parent 694be6a commit a5c1a2d
File tree
5 files changed
+150
-25
lines changed- mlir
- include/mlir/Dialect/Linalg/Transforms
- lib/Dialect
- Linalg
- IR
- Transforms
- Tensor/IR
- test/Dialect/Linalg
5 files changed
+150
-25
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1650 | 1650 | | |
1651 | 1651 | | |
1652 | 1652 | | |
| 1653 | + | |
1653 | 1654 | | |
1654 | | - | |
| 1655 | + | |
| 1656 | + | |
| 1657 | + | |
| 1658 | + | |
1655 | 1659 | | |
1656 | 1660 | | |
1657 | 1661 | | |
| |||
1687 | 1691 | | |
1688 | 1692 | | |
1689 | 1693 | | |
1690 | | - | |
| 1694 | + | |
1691 | 1695 | | |
| 1696 | + | |
1692 | 1697 | | |
1693 | | - | |
| 1698 | + | |
| 1699 | + | |
| 1700 | + | |
1694 | 1701 | | |
1695 | 1702 | | |
1696 | 1703 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5272 | 5272 | | |
5273 | 5273 | | |
5274 | 5274 | | |
5275 | | - | |
| 5275 | + | |
5276 | 5276 | | |
5277 | 5277 | | |
| 5278 | + | |
| 5279 | + | |
| 5280 | + | |
| 5281 | + | |
| 5282 | + | |
| 5283 | + | |
| 5284 | + | |
5278 | 5285 | | |
5279 | | - | |
| 5286 | + | |
5280 | 5287 | | |
5281 | 5288 | | |
5282 | 5289 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1134 | 1134 | | |
1135 | 1135 | | |
1136 | 1136 | | |
1137 | | - | |
1138 | | - | |
1139 | | - | |
| 1137 | + | |
1140 | 1138 | | |
1141 | 1139 | | |
1142 | 1140 | | |
1143 | 1141 | | |
1144 | 1142 | | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
1145 | 1170 | | |
1146 | 1171 | | |
1147 | 1172 | | |
1148 | 1173 | | |
1149 | 1174 | | |
1150 | 1175 | | |
1151 | | - | |
1152 | | - | |
1153 | 1176 | | |
1154 | 1177 | | |
1155 | 1178 | | |
| |||
1160 | 1183 | | |
1161 | 1184 | | |
1162 | 1185 | | |
1163 | | - | |
1164 | | - | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
1165 | 1189 | | |
1166 | | - | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
1167 | 1193 | | |
1168 | 1194 | | |
1169 | 1195 | | |
| |||
1179 | 1205 | | |
1180 | 1206 | | |
1181 | 1207 | | |
1182 | | - | |
1183 | | - | |
1184 | | - | |
| 1208 | + | |
| 1209 | + | |
| 1210 | + | |
| 1211 | + | |
| 1212 | + | |
| 1213 | + | |
| 1214 | + | |
| 1215 | + | |
| 1216 | + | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
1185 | 1223 | | |
1186 | 1224 | | |
1187 | 1225 | | |
| |||
1204 | 1242 | | |
1205 | 1243 | | |
1206 | 1244 | | |
1207 | | - | |
| 1245 | + | |
1208 | 1246 | | |
1209 | | - | |
1210 | | - | |
1211 | | - | |
1212 | | - | |
1213 | | - | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
1214 | 1258 | | |
1215 | 1259 | | |
1216 | | - | |
| 1260 | + | |
1217 | 1261 | | |
1218 | 1262 | | |
1219 | | - | |
1220 | 1263 | | |
1221 | 1264 | | |
1222 | | - | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
1223 | 1270 | | |
1224 | 1271 | | |
1225 | 1272 | | |
| 1273 | + | |
| 1274 | + | |
1226 | 1275 | | |
1227 | 1276 | | |
1228 | 1277 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2310 | 2310 | | |
2311 | 2311 | | |
2312 | 2312 | | |
| 2313 | + | |
2313 | 2314 | | |
2314 | 2315 | | |
2315 | 2316 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
34 | 53 | | |
35 | 54 | | |
36 | 55 | | |
| |||
157 | 176 | | |
158 | 177 | | |
159 | 178 | | |
| 179 | + | |
| 180 | + | |
160 | 181 | | |
161 | 182 | | |
162 | 183 | | |
| |||
182 | 203 | | |
183 | 204 | | |
184 | 205 | | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
185 | 228 | | |
186 | 229 | | |
187 | 230 | | |
| |||
295 | 338 | | |
296 | 339 | | |
297 | 340 | | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
0 commit comments