Repository navigation
[Codegen] NFC: Lift InnerTiledOp unroll pattern to Codegen. - #24357
Conversation
Follow-up to the previous NFC, moving the third (and last)
`iree_codegen.inner_tiled` rewrite pattern out of
`Codegen/Dialect/GPU/Transforms/`:
- `UnrollInnerTiledPattern` (unrolls along iter dimensions until each
intrinsic invocation has a unit iter shape)
The pattern itself is dialect-neutral; only the convenience
no-args populate function applied a default config (matmul-like
LHS-reuse traversal order, unit native shape) that happens to be a
good fit for any architecture, including CPU.
Renames the populate functions:
- `IREE::GPU::populateIREEGPUVectorUnrollPatterns` (with-options form)
-> `IREE::Codegen::populateUnrollInnerTiledPatterns`
- `IREE::GPU::populateIREEGPUVectorUnrollPatterns` (no-args form)
-> `IREE::Codegen::populateUnrollInnerTiledPatterns`
Renames the GPU-specific helper `gpuMatmulLikeUnrollOrder` to
`matmulLikeUnrollOrder` (its content is dialect-neutral). The
`kUnrollAccDistribute` / `kUnrollAccReassemble` HoistableConversionOp
tag constants move with the pattern.
Updates the in-tree callers in `IREEGPUExtensions.cpp` and
`UnrollToIntrinsics.cpp`, and adjusts BUILD.bazel/CMakeLists.txt deps.
Strict NFC; no functional or behavioral change.
Signed-off-by: Benoit Jacob <[email protected]>
Progress towards #24323
a3096e8 to
35ed0b0
Compare
There was a problem hiding this comment.
This transform op should be moved as well?
There was a problem hiding this comment.
The next PR #24358 shows the equivalent call on CPU. Does that look good?
There was a problem hiding this comment.
That one (#24358) looks good to me. This comment is mainly for transform_dialect::ApplyUnrollMultiMmaOp; can be addressed in either this PR or a follow-up.
There are several test name and method name still using multi_mma, and the other option may be cleaning them up in a follow-up. E.g.,
- https://github.com/search?q=repo%3Airee-org%2Firee+multi_mma&type=code
- https://github.com/search?q=repo%3Airee-org%2Firee%20MultiMma&type=code
I can kick started an AI session for doing this. However, it may conflict with your in-flight changes, so I haven't started yet. Let me know if you want to take it over or feel free to leave it to me. I can do it in my bubble time when your work are mostly landed.
There was a problem hiding this comment.
I'll leave it to you! I'll enable auto-merge here so this gets merged soon (I need to leave for today) and you'll be unblocked to implement your changes on top.
…ass. (#24358) `iree_codegen.inner_tiled` is a high-level vector op (a multi-dim contraction whose shape is described by its kind), and lowering it to per-intrinsic ops is "high-level vector -> lower-level dialect", which is exactly what `LLVMCPUVirtualVectorLoweringPass` already does for `vector.contract`, `vector.multi_reduction`, `vector.transfer_*`, and the IREE VectorExt ops. So land the CPU `inner_tiled` lowering in that pass rather than in a separate pass. Three pattern populates from `IREE::Codegen` (introduced in PR #24351 and #24357) join the target-independent block of `LLVMCPUVirtualVectorLoweringPass`: - `IREE::Codegen::populateUnrollInnerTiledPatterns` unrolls any non-unit iter dim (typically a residual reduction tile) to unit. - `IREE::Codegen::populateDropInnerTiledUnitDimsPatterns` drops the (now-unit) iter domain so the lowered op has empty iter bounds, which is the precondition of... - `IREE::Codegen::populateLowerInnerTiledPatterns` replaces the iter-free vector-semantics `inner_tiled` with the per-intrinsic ops emitted by its kind's `buildUnderlyingOperations` — for `IREE::CPU::DataTiledMMAAttr` those are `llvm.call_intrinsic` ops. These patterns only match `iree_codegen.inner_tiled`, so they are orthogonal to the existing patterns in this pass; the `DropVectorUnitDimsPass` that runs immediately before this one only touches `vector.*` ops and similarly does not interact. After the greedy pattern application, run `IREE::Util::eliminateHoistableConversions` to cancel the inverse-pair `util.hoistable_conversion` ops the inner_tiled lowering wraps around the per-intrinsic ACC distribute/reassemble. GPU's `LowerIREEGPUOps` pass calls this for the same reason; the introducing pattern set is the right place to clean up after itself. `LLVMCPUVirtualVectorLoweringPass` runs post-bufferization. That is fine for `iree_codegen.inner_tiled`: by then the op is already in vector semantics (lifted by `GenericVectorizationPass` via the `InnerTiledOpVectorizationModel` `VectorizableOpInterface` external model), and bufferization does not touch vectors. Updates a stale forward reference in `KernelDispatch.cpp` left over from #24328 — the comment described the unit-iter-dim drop and per- intrinsic lower patterns as firing inside a pass named `LLVMCPULowerInnerTiledPass`, which never landed; they now fire inside `LLVMCPUVirtualVectorLoweringPass`. Progress towards #24323 --------- Signed-off-by: Benoit Jacob <[email protected]>
Follow-up to the previous NFC, moving the third (and last) `iree_codegen.inner_tiled` rewrite pattern out of `Codegen/Dialect/GPU/Transforms/`: - `UnrollInnerTiledPattern` (unrolls along iter dimensions until each intrinsic invocation has a unit iter shape) The pattern itself is dialect-neutral; only the convenience no-args populate function applied a default config (matmul-like LHS-reuse traversal order, unit native shape) that happens to be a good fit for any architecture, including CPU. Renames the populate functions: - `IREE::GPU::populateIREEGPUVectorUnrollPatterns` (with-options form) -> `IREE::Codegen::populateUnrollInnerTiledPatterns` - `IREE::GPU::populateIREEGPUVectorUnrollPatterns` (no-args form) -> `IREE::Codegen::populateUnrollInnerTiledPatterns` Renames the GPU-specific helper `gpuMatmulLikeUnrollOrder` to `matmulLikeUnrollOrder` (its content is dialect-neutral). The `kUnrollAccDistribute` / `kUnrollAccReassemble` HoistableConversionOp tag constants move with the pattern. Updates the in-tree callers in `IREEGPUExtensions.cpp` and `UnrollToIntrinsics.cpp`, and adjusts BUILD.bazel/CMakeLists.txt deps. Strict NFC; no functional or behavioral change. Progress towards #24323
…ass. (#24358) `iree_codegen.inner_tiled` is a high-level vector op (a multi-dim contraction whose shape is described by its kind), and lowering it to per-intrinsic ops is "high-level vector -> lower-level dialect", which is exactly what `LLVMCPUVirtualVectorLoweringPass` already does for `vector.contract`, `vector.multi_reduction`, `vector.transfer_*`, and the IREE VectorExt ops. So land the CPU `inner_tiled` lowering in that pass rather than in a separate pass. Three pattern populates from `IREE::Codegen` (introduced in PR #24351 and #24357) join the target-independent block of `LLVMCPUVirtualVectorLoweringPass`: - `IREE::Codegen::populateUnrollInnerTiledPatterns` unrolls any non-unit iter dim (typically a residual reduction tile) to unit. - `IREE::Codegen::populateDropInnerTiledUnitDimsPatterns` drops the (now-unit) iter domain so the lowered op has empty iter bounds, which is the precondition of... - `IREE::Codegen::populateLowerInnerTiledPatterns` replaces the iter-free vector-semantics `inner_tiled` with the per-intrinsic ops emitted by its kind's `buildUnderlyingOperations` — for `IREE::CPU::DataTiledMMAAttr` those are `llvm.call_intrinsic` ops. These patterns only match `iree_codegen.inner_tiled`, so they are orthogonal to the existing patterns in this pass; the `DropVectorUnitDimsPass` that runs immediately before this one only touches `vector.*` ops and similarly does not interact. After the greedy pattern application, run `IREE::Util::eliminateHoistableConversions` to cancel the inverse-pair `util.hoistable_conversion` ops the inner_tiled lowering wraps around the per-intrinsic ACC distribute/reassemble. GPU's `LowerIREEGPUOps` pass calls this for the same reason; the introducing pattern set is the right place to clean up after itself. `LLVMCPUVirtualVectorLoweringPass` runs post-bufferization. That is fine for `iree_codegen.inner_tiled`: by then the op is already in vector semantics (lifted by `GenericVectorizationPass` via the `InnerTiledOpVectorizationModel` `VectorizableOpInterface` external model), and bufferization does not touch vectors. Updates a stale forward reference in `KernelDispatch.cpp` left over from #24328 — the comment described the unit-iter-dim drop and per- intrinsic lower patterns as firing inside a pass named `LLVMCPULowerInnerTiledPass`, which never landed; they now fire inside `LLVMCPUVirtualVectorLoweringPass`. Progress towards #24323 --------- Signed-off-by: Benoit Jacob <[email protected]>
…#24357) Follow-up to the previous NFC, moving the third (and last) `iree_codegen.inner_tiled` rewrite pattern out of `Codegen/Dialect/GPU/Transforms/`: - `UnrollInnerTiledPattern` (unrolls along iter dimensions until each intrinsic invocation has a unit iter shape) The pattern itself is dialect-neutral; only the convenience no-args populate function applied a default config (matmul-like LHS-reuse traversal order, unit native shape) that happens to be a good fit for any architecture, including CPU. Renames the populate functions: - `IREE::GPU::populateIREEGPUVectorUnrollPatterns` (with-options form) -> `IREE::Codegen::populateUnrollInnerTiledPatterns` - `IREE::GPU::populateIREEGPUVectorUnrollPatterns` (no-args form) -> `IREE::Codegen::populateUnrollInnerTiledPatterns` Renames the GPU-specific helper `gpuMatmulLikeUnrollOrder` to `matmulLikeUnrollOrder` (its content is dialect-neutral). The `kUnrollAccDistribute` / `kUnrollAccReassemble` HoistableConversionOp tag constants move with the pattern. Updates the in-tree callers in `IREEGPUExtensions.cpp` and `UnrollToIntrinsics.cpp`, and adjusts BUILD.bazel/CMakeLists.txt deps. Strict NFC; no functional or behavioral change. Progress towards iree-org#24323
…ass. (iree-org#24358) `iree_codegen.inner_tiled` is a high-level vector op (a multi-dim contraction whose shape is described by its kind), and lowering it to per-intrinsic ops is "high-level vector -> lower-level dialect", which is exactly what `LLVMCPUVirtualVectorLoweringPass` already does for `vector.contract`, `vector.multi_reduction`, `vector.transfer_*`, and the IREE VectorExt ops. So land the CPU `inner_tiled` lowering in that pass rather than in a separate pass. Three pattern populates from `IREE::Codegen` (introduced in PR iree-org#24351 and iree-org#24357) join the target-independent block of `LLVMCPUVirtualVectorLoweringPass`: - `IREE::Codegen::populateUnrollInnerTiledPatterns` unrolls any non-unit iter dim (typically a residual reduction tile) to unit. - `IREE::Codegen::populateDropInnerTiledUnitDimsPatterns` drops the (now-unit) iter domain so the lowered op has empty iter bounds, which is the precondition of... - `IREE::Codegen::populateLowerInnerTiledPatterns` replaces the iter-free vector-semantics `inner_tiled` with the per-intrinsic ops emitted by its kind's `buildUnderlyingOperations` — for `IREE::CPU::DataTiledMMAAttr` those are `llvm.call_intrinsic` ops. These patterns only match `iree_codegen.inner_tiled`, so they are orthogonal to the existing patterns in this pass; the `DropVectorUnitDimsPass` that runs immediately before this one only touches `vector.*` ops and similarly does not interact. After the greedy pattern application, run `IREE::Util::eliminateHoistableConversions` to cancel the inverse-pair `util.hoistable_conversion` ops the inner_tiled lowering wraps around the per-intrinsic ACC distribute/reassemble. GPU's `LowerIREEGPUOps` pass calls this for the same reason; the introducing pattern set is the right place to clean up after itself. `LLVMCPUVirtualVectorLoweringPass` runs post-bufferization. That is fine for `iree_codegen.inner_tiled`: by then the op is already in vector semantics (lifted by `GenericVectorizationPass` via the `InnerTiledOpVectorizationModel` `VectorizableOpInterface` external model), and bufferization does not touch vectors. Updates a stale forward reference in `KernelDispatch.cpp` left over from iree-org#24328 — the comment described the unit-iter-dim drop and per- intrinsic lower patterns as firing inside a pass named `LLVMCPULowerInnerTiledPass`, which never landed; they now fire inside `LLVMCPUVirtualVectorLoweringPass`. Progress towards iree-org#24323 --------- Signed-off-by: Benoit Jacob <[email protected]>
Follow-up to the previous NFC, moving the third (and last)
iree_codegen.inner_tiledrewrite pattern out ofCodegen/Dialect/GPU/Transforms/:UnrollInnerTiledPattern(unrolls along iter dimensions until each intrinsic invocation has a unit iter shape)The pattern itself is dialect-neutral; only the convenience no-args populate function applied a default config (matmul-like LHS-reuse traversal order, unit native shape) that happens to be a good fit for any architecture, including CPU.
Renames the populate functions:
IREE::GPU::populateIREEGPUVectorUnrollPatterns(with-options form) ->IREE::Codegen::populateUnrollInnerTiledPatternsIREE::GPU::populateIREEGPUVectorUnrollPatterns(no-args form) ->IREE::Codegen::populateUnrollInnerTiledPatternsRenames the GPU-specific helper
gpuMatmulLikeUnrollOrdertomatmulLikeUnrollOrder(its content is dialect-neutral). ThekUnrollAccDistribute/kUnrollAccReassembleHoistableConversionOp tag constants move with the pattern.Updates the in-tree callers in
IREEGPUExtensions.cppandUnrollToIntrinsics.cpp, and adjusts BUILD.bazel/CMakeLists.txt deps.Strict NFC; no functional or behavioral change.
Progress towards #24323