Repository navigation
[Codegen][GPU] Add a inner tiled op descriptor for scaled MMA - #21141
Merged
Merged
Conversation
This commit adds a descriptor attribute - #iree_gpu.scaled_mma_layout -
for MMAs that takes "scale" operands and tests for its lowering
from DistributeInnerTiledToLanes and afterwards.
This descriptor takes four input operands - the lleft-hand side of the
matrix, the LHS scales, the right-hand side, and the RHS scales, in
that order. The operation has one accumulator.
Scaled MMAs are, like MMA intrinsics, represented by an enum, which
litss out the available intrinsics (currenvtly, we only have AMD's
MI-350). However, unlike with MMA intrinsics, the input and output
types are given in the scaled_mma_layout attribute itself. This is
because these scaled MMAs support arbitrary pairs of left- and
right-hand side types from {f4E2M1FN, f6E3M2FN, f6E3M2FN, f8E4M3FN,
f8E5M2}, so listing out all the combinations would take up a lot of
space and produce a large number of nearly-identical cases in the
descriotor logic.
This inner tiled operation treats the k values that have distinct
scales and the "block" (the B (currently always 32) values that share
a common scale) as separate reduction dimensions. This means that the
scale operands, in effect, don't have a block dimension. This also
means that models where the block size is larger than 32 can be
supported by tiling across the scale dimension.
The following work is not yet implemented:
- ContretizeMmaShapes has not yet been generalized to arbitrary inner
tiled ops. This will be needed to correctly lower the 32x32x64
intrinsic, which has an outer dimension on the accumulator.
- Lowering configuration logic and PackToIntrinsics have not been
addressed
Note that this PR does contain a few code changes. One is declaring
the vector unrolling logic to be safe for non-MMA inner_tiled ops. The
other is a bug fix to basisFromSizesStrides(), which used an incorrect
tiebreaking strategy for multiple dimensions that had the same
stride (now it's ties broken by the length of the dimension and _then_
its position in the list).
Contributor
Author
|
Superscedes #21110 so I can stack on top of it |
qedawkins
approved these changes
Jun 24, 2025
qedawkins
left a comment
Contributor
There was a problem hiding this comment.
Cool, this looks good. Much easier review than I expected, thanks for all the tests + comments
| for (auto [set, map] : llvm::zip_equal(resExprs, maps)) { | ||
| set.insert_range(map.getResults()); | ||
| } | ||
| // Note: the below conditions are a best guess and may be too strict. |
Contributor
There was a problem hiding this comment.
Just checking isProjectedPermutation should be good enough, I don't think mixing scale dimensions with other operands will break anything (although it would be weird).
Contributor
Author
There was a problem hiding this comment.
I figured a bit of paranoia never hurt anyone?
Co-authored-by: Quinn Dawkins <[email protected]>
AWoloszyn
pushed a commit
that referenced
this pull request
Dec 1, 2025
This commit adds a descriptor attribute - #iree_gpu.scaled_mma_layout -
for MMAs that takes "scale" operands and tests for its lowering from
DistributeInnerTiledToLanes and afterwards.
This descriptor takes four input operands - the lleft-hand side of the
matrix, the LHS scales, the right-hand side, and the RHS scales, in that
order. The operation has one accumulator.
Scaled MMAs are, like MMA intrinsics, represented by an enum, which
litss out the available intrinsics (currenvtly, we only have AMD's
MI-350). However, unlike with MMA intrinsics, the input and output types
are given in the scaled_mma_layout attribute itself. This is because
these scaled MMAs support arbitrary pairs of left- and right-hand side
types from {f4E2M1FN, f6E3M2FN, f6E3M2FN, f8E4M3FN, f8E5M2}, so listing
out all the combinations would take up a lot of space and produce a
large number of nearly-identical cases in the descriotor logic.
This inner tiled operation treats the k values that have distinct scales
and the "block" (the B (currently always 32) values that share a common
scale) as separate reduction dimensions. This means that the scale
operands, in effect, don't have a block dimension. This also means that
models where the block size is larger than 32 can be supported by tiling
across the scale dimension.
The following work is not yet implemented:
- ContretizeMmaShapes has not yet been generalized to arbitrary inner
tiled ops. This will be needed to correctly lower the 32x32x64
intrinsic, which has an outer dimension on the accumulator.
- Lowering configuration logic and PackToIntrinsics have not been
addressed
Note that this PR does contain a few code changes. One is declaring the
vector unrolling logic to be safe for non-MMA inner_tiled ops. The other
is a bug fix to basisFromSizesStrides(), which used an incorrect
tiebreaking strategy for multiple dimensions that had the same stride
(now it's ties broken by the length of the dimension and _then_ its
position in the list).
---------
Co-authored-by: Quinn Dawkins <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit adds a descriptor attribute - #iree_gpu.scaled_mma_layout - for MMAs that takes "scale" operands and tests for its lowering from DistributeInnerTiledToLanes and afterwards.
This descriptor takes four input operands - the lleft-hand side of the matrix, the LHS scales, the right-hand side, and the RHS scales, in that order. The operation has one accumulator.
Scaled MMAs are, like MMA intrinsics, represented by an enum, which litss out the available intrinsics (currenvtly, we only have AMD's MI-350). However, unlike with MMA intrinsics, the input and output types are given in the scaled_mma_layout attribute itself. This is because these scaled MMAs support arbitrary pairs of left- and right-hand side types from {f4E2M1FN, f6E3M2FN, f6E3M2FN, f8E4M3FN, f8E5M2}, so listing out all the combinations would take up a lot of space and produce a large number of nearly-identical cases in the descriotor logic.
This inner tiled operation treats the k values that have distinct scales and the "block" (the B (currently always 32) values that share a common scale) as separate reduction dimensions. This means that the scale operands, in effect, don't have a block dimension. This also means that models where the block size is larger than 32 can be supported by tiling across the scale dimension.
The following work is not yet implemented:
Note that this PR does contain a few code changes. One is declaring the vector unrolling logic to be safe for non-MMA inner_tiled ops. The other is a bug fix to basisFromSizesStrides(), which used an incorrect tiebreaking strategy for multiple dimensions that had the same stride (now it's ties broken by the length of the dimension and then its position in the list).