Repository navigation
[DT][GPU] Permute cross-thread dims of TileSwizzle to outermost - #19734
Conversation
|
Note: https://github.com/iree-org/iree/actions/runs/12836887845/job/35897611026?pr=19734#step:8:208 is where we see that the tests ran and succeeded on RDNA3, supposedly the trickiest place for this PR to avoid breaking. |
hanhanW
left a comment
There was a problem hiding this comment.
Few style nits. I'll leave the detailed review to Benoit since he has the best context.
Signed-off-by: Max Dawkins <[email protected]>
Signed-off-by: Max Dawkins <[email protected]>
Signed-off-by: Max Dawkins <[email protected]>
f6c9545 to
c85efb9
Compare
There was a problem hiding this comment.
Nice job figuring this out! Let's take this in its current form. The complexity being moved to a static function makes it a lot more tolerable, and thanks also for the detailed comments.
Ultimately, what moveCrossThreadOutermost does is inherently complex, so it's normal that it's complex.
As a follow-up, I would like to explore if this could instead be achieved by having each step of the construction of tileswizzles (the initial construction of the intrinsic swizzle, and then the expand function) respect the invariants that are currently fixed up by moveCrossThreadOutermost. There are two such invariants:
- The "cross-thread dims are outermost" invariant is easy to enforce at each step because it's local to each fragment independently of other fragments.
- The "consistency of M and N dims expandshapes across LHS/RHS and ACC" invariant is a little trickier because of the interaction between fragments. The problem is in the original construction of the intrinsic swizzle from singlesubgrouplayout. We will need to change something at that level. On the other hand, once that is taken care of, the subsequent expansions for
intrinsics_{m,n}andsubgroups_{m,n}parameters will be fine because these apply equally to each fragment.
That would be a very nice cleanup indeed. It is getting hard to follow the tile swizzling logic now that everything is going through effectively 3 stages of building the swizzle (intrinsic swizzle -> full swizzle -> cross thread outermost swizzle). Doing this all in one place with some easy to follow invariants would be much nicer. |
This PR adds a new constraint on the generated TileSwizzles during GPU
encoding materialization. The new constraint is that all `CrossThread`
dimensions in the ACC layout must come from the outermost dimensions
within their reassociation groups of the swizzle's expand_shape. For
example, consider the following TileSwizzle for an ACC layout generated
without this constraint:
```
expandShape = [[8, {4}, 4], [{4}, 2, {16}]],
permutation = [3, 0, 4, 1, 5, 2]
```
`CrossThread` dimensions are denoted with braces {}, and this
TileSwizzle does not follow the new constrain because the first `{4}`
dim of reassociation group 0 and the `{16}` dim of reassociation group 1
are not outermost. After adding the new constraint, this swizzle would
look like the following:
```
expandShape = [[{4}, 8, 4], [{4}, {16}, 2]],
permutation = [3, 1, 5, 0, 4, 2]
```
Now, all `CrossThread` dimensions are outermost within their
reassociation groups. The permutation has been adjusted accordingly so
that the result shape of the swizzled tile remains the same in both
cases.
The LHS and RHS swizzle layouts also have to be adjusted to match the
new ACC layout, but the CrossThread dimensions are not necessarily the
same between corresponding M and N tiles of the ACC swizzle and LHS/RHS
swizzles. Because of this, the LHS and RHS (currently only LHS needs
this) swizzle shapes must be expanded to match the dimensionality of the
ACC layout. This is the reason why some of the LHS layouts have
additional expansion after this PR.
The reason for adding this constraint is so that the swizzle operations
of unset_encoding operations are able to be fused into the thread loop
of their data tiled multi_mma operation. This constraint makes the
fusion possible by forcing the slices that are held by a thread at the
end of the multi_mma computation to be contiguous in the linear layout
tensor within each reassociation group. This matters because we need to
fuse the collapse_shape op of the unset_encoding into the thread loop,
which is only possible when the written slice is contiguous in the
result for each reassociation group.
---------
Signed-off-by: Max Dawkins <[email protected]>
This PR adds a new constraint on the generated TileSwizzles during GPU encoding materialization. The new constraint is that all
CrossThreaddimensions in the ACC layout must come from the outermost dimensions within their reassociation groups of the swizzle's expand_shape. For example, consider the following TileSwizzle for an ACC layout generated without this constraint:CrossThreaddimensions are denoted with braces {}, and this TileSwizzle does not follow the new constrain because the first{4}dim of reassociation group 0 and the{16}dim of reassociation group 1 are not outermost. After adding the new constraint, this swizzle would look like the following:Now, all
CrossThreaddimensions are outermost within their reassociation groups. The permutation has been adjusted accordingly so that the result shape of the swizzled tile remains the same in both cases.The LHS and RHS swizzle layouts also have to be adjusted to match the new ACC layout, but the CrossThread dimensions are not necessarily the same between corresponding M and N tiles of the ACC swizzle and LHS/RHS swizzles. Because of this, the LHS and RHS (currently only LHS needs this) swizzle shapes must be expanded to match the dimensionality of the ACC layout. This is the reason why some of the LHS layouts have additional expansion after this PR.
The reason for adding this constraint is so that the swizzle operations of unset_encoding operations are able to be fused into the thread loop of their data tiled multi_mma operation. This constraint makes the fusion possible by forcing the slices that are held by a thread at the end of the multi_mma computation to be contiguous in the linear layout tensor within each reassociation group. This matters because we need to fuse the collapse_shape op of the unset_encoding into the thread loop, which is only possible when the written slice is contiguous in the result for each reassociation group.