Repository navigation
[Codegen] Generalize MultiMmaInterfaceAttr to InnerTileDescAttrInterface - #21000
Conversation
This commit is phase 1 of refactoring iree_gpu.multi_mma to take arbitrarily many operands. In this commit, we introduce InnerTileDescAttrInterface, which becasem a parent of MultiMmaInterfaceAttr and has versions of most of its methods moved to it. The main changes in the migration are: 1. Instead of returning M, N, and K values, the new interface returns the VectorType of the pre-distribution inner tile, which can be used to recover the M, N, and K values for a matrix multiply (though, in most cases, it's just the number of elements in those tiles that actually mattered) using getUndistributedTileTypes(), which populates a vector of results. 2. getABCVectorTypes() becomes getDistributedTileTypes(), which populates a vector. 3. getSubgroupSize() becomes optional just in case this all ends up on CPU. 4. MMAScope gets moved to the Codegen dialect and renamed InnerTileScope. 5. InnerTileDescAttrInterface gets a method to indicate the expected number of input arguments for a paritular inner tiled operation. It also allows for intrinsic-specific indexing map verefication (since non-matmuls may fail contraction map inference). 6. populateOperandOffsetSizesAndStrides() now takes an integer index and not an MMA fragment. The verifier for multi_mma op has been rewritten to not mention "lhs", "rhs", and "acc" where possible. A future commit will actually make the input arguments (and permutations) variadic and do the big pile of code motion into the codegen dialect, but this seemed like an independently reviewable piece of code.
qedawkins
left a comment
There was a problem hiding this comment.
Nice, looks pretty good so far. Did an initial skim and will do a full review tomorrow.
qedawkins
left a comment
There was a problem hiding this comment.
Nice, this is awesome progress. The new interface turned out pretty much exactly like I was hoping!
| @@ -0,0 +1,19 @@ | |||
| // Copyright 2025 The IREE Authors | |||
There was a problem hiding this comment.
Dead file? I don't see any codegen enums anymore
There was a problem hiding this comment.
This is harmonization so that we don't have all this in LoweringConfigEnums.h.inc which just gets included in the attrs file
There was a problem hiding this comment.
I did not get a chance to revisit Codegen dialect, but I like how we define these in IREE core dialects better, e.g., move all attributes/interfaces/enums/etc to IREECodegenTypes.h. I think we don't really need a separation between attrs.h, interfaces.h, and enums.h.
E.g.,
There was a problem hiding this comment.
GPU has An Enums.h, which was what I was going off of
And a lot of upstream dialects have a separate Enums.h
There was a problem hiding this comment.
GPU has An Enums.h, which was what I was going off of
And a lot of upstream dialects have a separate Enums.h
If it were me, I'd remove the Enums.h from GPU. Because I don't see a separation need in most of the dialects.
I'm not going to say if we should follow upstream or not, because I don't see a need for the separation. However, I'd like to point out that only three upstream dialects have a separate Enums.h.
❯ find . | rg 'Enums.h'
./SPIRV/IR/SPIRVEnums.h
./ArmSME/IR/ArmSMEEnums.h
./SparseTensor/IR/Enums.h
Co-authored-by: Quinn Dawkins <[email protected]>
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.
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.
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.
…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]>
…ace (#21000) This commit is phase 1 of refactoring iree_gpu.multi_mma to take arbitrarily many operands (and get renamed to `iree_codegen.inner_tiled`). In this commit, we introduce InnerTileDescAttrInterface, which becasem a parent of MultiMmaInterfaceAttr and has versions of most of its methods moved to it. The main changes in the migration are: 1. Instead of returning M, N, and K values, the new interface returns the VectorType of the pre-distribution inner tile, which can be used to recover the M, N, and K values for a matrix multiply (though, in most cases, it's just the number of elements in those tiles that actually mattered) using getUndistributedTileTypes(), which populates a vector of results. 2. getABCVectorTypes() becomes getDistributedTileTypes(), which populates a vector. 3. getSubgroupSize() becomes optional just in case this all ends up on CPU. 4. MMAScope gets moved to the Codegen dialect and renamed InnerTileScope. 5. InnerTileDescAttrInterface gets a method to indicate the expected number of input arguments for a paritular inner tiled operation. It also allows for intrinsic-specific indexing map verefication (since non-matmuls may fail contraction map inference). 6. populateOperandOffsetSizesAndStrides() now takes an integer index and not an MMA fragment. The verifier for multi_mma op has been rewritten to not mention "lhs", "rhs", and "acc" where possible. A future commit will actually make the input arguments (and permutations) variadic and do the big pile of code motion into the codegen dialect, but this seemed like an independently reviewable piece of code. --------- Co-authored-by: Quinn Dawkins <[email protected]>
…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 commit is phase 1 of refactoring iree_gpu.multi_mma to take arbitrarily many operands (and get renamed to
iree_codegen.inner_tiled).In this commit, we introduce InnerTileDescAttrInterface, which becasem a parent of MultiMmaInterfaceAttr and has versions of most of its methods moved to it.
The main changes in the migration are:
The verifier for multi_mma op has been rewritten to not mention "lhs", "rhs", and "acc" where possible.
A future commit will actually make the input arguments (and permutations) variadic and do the big pile of code motion into the codegen dialect, but this seemed like an independently reviewable piece of code.