Skip to content

[Codegen][GPU] Add a inner tiled op descriptor for scaled MMA - #21110

Closed
krzysz00 wants to merge 2 commits into
iree-org:mainfrom
krzysz00:scaling-mfma-desc
Closed

krzysz00 wants to merge 2 commits into
iree-org:mainfrom
krzysz00:scaling-mfma-desc

Conversation

@krzysz00

@krzysz00 krzysz00 commented Jun 17, 2025 •

Copy link
Copy Markdown
Contributor

This commit adds a descriptor attribute - #iree_gpu.scaled_mma_layout -
for MMAs that take "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).

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).
@krzysz00
krzysz00 force-pushed the scaling-mfma-desc branch from 4a5b3bd to 0c8859e Compare June 17, 2025 21:15
@krzysz00 krzysz00 changed the title [DRAFT] Add inner tiled op descriptor for scaled MFMA, handle distribute-to-lanes on down [Codegen][GPU] Add a inner tiled op descriptor for scaled MMA Jun 17, 2025
@krzysz00
krzysz00 marked this pull request as ready for review June 17, 2025 21:17
@krzysz00

Copy link
Copy Markdown
Contributor Author

Closing in favor of #21141 to enable stacked PRs

@krzysz00 krzysz00 closed this Jun 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant