Repository navigation
Description
In our data tiling TileSwizzle layouts for matmul results, we have a final step to move all CrossThread dims to be outermost in the expand_shape:
iree/compiler/src/iree/compiler/Codegen/Dialect/GPU/IR/GPUTileSwizzleUtils.cpp
Lines 151 to 184 in cf60359
| /// Moves all `Kind::CrossThread` dims of the Acc layout to the outermost | |
| /// within their expand shape reassociation groups. This only moves the cross | |
| /// thread dims of the Acc layout because we want to fuse the unset_encoding | |
| /// ops with the data tiled matmul. In order to do this, the sliced dimensions | |
| /// (CrossThread) for each thread need to be outermost in the final write out. | |
| /// | |
| /// This transformation is for the Acc layout, but the Lhs and Rhs layouts need | |
| /// to be transformed too, because the layouts need to match the Acc for their | |
| /// respective M and N tile dimensions. | |
| /// | |
| /// Example (CrossThread dims are denoted with surrounding {} braces): | |
| /// Input: | |
| /// Lhs layout: | |
| /// expandShape = [[8, {16}], [2, {4}, 4]], | |
| /// permutation = [0, 3, 1, 2, 4] | |
| /// Rhs layout: | |
| /// expandShape = [[{4}, 2, {16}], [2, {4}, 4]], | |
| /// permutation = [0, 1, 4, 2, 3, 5] | |
| /// Acc layout: | |
| /// expandShape = [[8, {4}, 4], [{4}, 2, {16}]], | |
| /// permutation = [3, 0, 4, 1, 5, 2] | |
| /// Output: | |
| /// Lhs layout: | |
| /// expandShape = [[{4}, 8, {4}], [2, {4}, 4]], | |
| /// permutation = [1, 4, 0, 2, 3, 5] | |
| /// Rhs layout: | |
| /// expandShape = [[{4}, {16}, 2], [2, {4}, 4]], | |
| /// permutation = [0, 2, 4, 1, 3, 5] | |
| /// Acc layout: | |
| /// expandShape = [[{4}, 8, 4], [{4}, {16}, 2]], | |
| /// permutation = [3, 1, 5, 0, 4, 2] | |
| static TileSwizzle moveCrossThreadOutermost(TileSwizzle swizzle, | |
| TileSwizzle accSwizzle, | |
| MMAFragment fragment) { |
This was added before the early bufferization/map_scatter path was implemented, because we needed additional constraints on the layout in order to ensure codegen for layout transformation worked well (see #19734 for more details).
Now we use map_scatter by default, which does not require any additional constraints on the layout, so we don't have a reason to move CrossThread dims outermost anymore. The logic adds complexity to the GPUTileSwizzleUtils, so there is some benefit in removing it. On the other hand, removing this logic will break the non-map_scatter path for the cases where it would otherwise work.
The point of this issue is not to advocate for removing the logic, since there are pros and cons, but to take note of the option, and create a place for discussion, so that the idea does not get lost/forgotten.
Activity
Remove `moveCrossThreadOutermost` (#22284)
Remove `moveCrossThreadOutermost` (iree-org#22284)
Remove `moveCrossThreadOutermost` (iree-org#22284)