Repository navigation
[Codegen] Generalize iree_gpu.multi_mma to iree_codegen.inner_tiled - #21062
Merged
Merged
Conversation
krzysz00
requested review from
Groverkss,
IanWood1,
MaheshRavishankar,
antiagainst,
benvanik,
hanhanW and
kuhar
as code owners
June 9, 2025 22:46
Max191
reviewed
Jun 11, 2025
In order to implement support for block-scaled MMA and to enable future operations over other "inner tiled" operations (for example, hand-rolled CPU micro-kernels), generalize iree_gpu.multi_mma to iree_codegen.inner_tiled. This PR is the next stage of the changes begun in iree-org#21000 The main differences between iree_gpu.multi_mma and iree_codegen.inner_tiled are that: 1. inner_tiled takes an arbitrary number of inputs, with the INnerTileDescAttrInterface describing the expected number of arguments. 2. The permutations - when present - are now stored as an array-of-arrays, and not as one array for each argument (since there are no longer fixed "lhs", "rhs", and "acc" arguments). 3. The operation takes an InnerTileDescAttrInterface implement instead of a MmaInterfaceAttr, though checking for the old interface is still sometimes used to scope patterns down to just multi-mma-like operations. 4. We use linalg.iterator_type<> instead of iree_gpu.iterator_type<>, since trying to define iree_codegen.iterator_type<> was causing redefinition errors In terms of transformatios, this PR generalizes (and, as a consequence, renames) those transformations that had clear generalizations to arbitrary intrinsics. This means that the configuration logic / lowering to multi-MMA is unaffeced, but a lot of the internal transformations (such as vectorization or tiling) have been reworked to support N inputs. These changes have not required more than mechanical (changing name + assembly format) changes to any tests and never showed end-to-end correctness issues, so it's likely that this PR causes no change in the generated code.
Max191
reviewed
Jun 12, 2025
Comment on lines
+120
to
+121
| kind that is to be used. The second return value is the upper bound | ||
| on the size of the mapping kind that'll be passed to the forall, if known. |
Contributor
There was a problem hiding this comment.
What do you mean by the size of the mapping kind?
Contributor
Author
There was a problem hiding this comment.
Is the new wording clearer?
Max191
reviewed
Jun 12, 2025
Max191
left a comment
Contributor
There was a problem hiding this comment.
Nice! It pretty much looks good to me % one more comment about the getDistributionMappingKind function.
qedawkins
approved these changes
Jun 12, 2025
qedawkins
left a comment
Contributor
There was a problem hiding this comment.
Awesome, just a bunch of minor comments. Looks like this was a lot more than I expected, great job wading through it!
kuhar
reviewed
Jun 12, 2025
Co-authored-by: Quinn Dawkins <[email protected]>
Max191
approved these changes
Jun 13, 2025
Max191
left a comment
Contributor
There was a problem hiding this comment.
Thanks for addressing all the comments, it LTGM!
AWoloszyn
pushed a commit
that referenced
this pull request
Dec 1, 2025
…21062) In order to implement support for block-scaled MMA and to enable future operations over other "inner tiled" operations (for example, hand-rolled CPU micro-kernels), generalize iree_gpu.multi_mma to iree_codegen.inner_tiled. This PR is the next stage of the changes begun in #21000 The main differences between iree_gpu.multi_mma and iree_codegen.inner_tiled are that: 1. inner_tiled takes an arbitrary number of inputs and accumulator outputs/inits, with the INnerTileDescAttrInterface describing the expected number of arguments. The inits are named "outputs" following the `linalg.generic` convention. 2. The permutations - when present - are now stored as an array-of-arrays, and not as one array for each argument (since there are no longer fixed "lhs", "rhs", and "acc" arguments). 3. The operation takes an InnerTileDescAttrInterface implement instead of a MmaInterfaceAttr, though checking for the old interface is still sometimes used to scope patterns down to just multi-mma-like operations. 4. We use linalg.iterator_type<> instead of iree_gpu.iterator_type<>, since trying to define iree_codegen.iterator_type<> was causing redefinition errors In terms of transformations, this PR generalizes (and, as a consequence, renames) those transformations that had clear generalizations to arbitrary intrinsics. This means that the configuration logic / lowering to multi-MMA is unaffeced, but a lot of the internal transformations (such as vectorization or tiling) have been reworked to support N inputs. These changes have not required more than mechanical (changing name + assembly format) changes to any tests and never showed end-to-end correctness issues, so it's likely that this PR causes no change in the generated code. To provide a motivating example for the generalization ```mlir iree_codegen.inner_tiled ins(%lhs, %lhs_scale, %rhs, %rhs_scale) acc(%acc) { indexing_maps = [ affine_map<(i, j, k) -> (i, k)>, affine_map<(i, j, k) -> (i, k)>, affine_map<(i, j, k) -> (j, k)>, affine_map<(i, j, k) -> (j, k)>, affine_map<(i, j, k) -> (i, j)> ], iterator_types = [parallel, parallel, reduction], kind = #iree_gpu.scaling_mma_kind<MFMA_16x16x128, lhsType = f4E2M1FN, rhsType = f8E3M3FN, acc_type = f32> } : tensor<?x?x16x128xf4E2M1FN>, tensor<?x?x16x4xf32>, // Note k dimension is a bunch smaller for scales tensor<?x?x128x16xf8E4M3FN>, tensor<?x?x4x16xf32> into tensor<?x?x16x16xf32> ``` The exact representation of scaling MMAs will be designed out later, but the above example is a demonstration of the overall motivation for this change Fixes ##20814 --------- Co-authored-by: Max191 <[email protected]> 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.
In order to implement support for block-scaled MMA and to enable future operations over other "inner tiled" operations (for example, hand-rolled CPU micro-kernels), generalize iree_gpu.multi_mma to iree_codegen.inner_tiled.
This PR is the next stage of the changes begun in #21000
The main differences between iree_gpu.multi_mma and iree_codegen.inner_tiled are that:
linalg.genericconvention.In terms of transformations, this PR generalizes (and, as a consequence, renames) those transformations that had clear generalizations to arbitrary intrinsics. This means that the configuration logic / lowering to multi-MMA is unaffeced, but a lot of the internal transformations (such as vectorization or tiling) have been reworked to support N inputs.
These changes have not required more than mechanical (changing name + assembly format) changes to any tests and never showed end-to-end correctness issues, so it's likely that this PR causes no change in the generated code.
To provide a motivating example for the generalization
The exact representation of scaling MMAs will be designed out later, but the above example is a demonstration of the overall motivation for this change
Fixes ##20814