Repository navigation
[Codegen][CPU] Teach the lowering strategy about inner_tiled. - #24328
Conversation
eb70366 to
bc61137
Compare
hanhanW
left a comment
There was a problem hiding this comment.
Have you tried mmt4d pipeline? I think that is the pipeline we should target for this op.
| // `iree_codegen.inner_tiled` rooted dispatches go through the DataTiling | ||
| // pipeline. The op's iter domain is already in inner-tile units (M_iter, | ||
| // N_iter, K_iter), so each iter dim is tiled to a single iteration: | ||
| // `vector_common_parallel` collapses the M and N parallel iter dims to 1 | ||
| // and `vector_reduction` collapses the K reduction iter dim to 1, so the | ||
| // LLVMCPULowerInnerTiled pass's greedy fixed point can fire on an iter-free | ||
| // vector inner_tiled. Distribution is parallel-only (M, N). |
There was a problem hiding this comment.
Seems to be implementation comment, but not test comment?
| LDBG() << "Set lowering_config for inner_tiled op: " << loweringConfig; | ||
| return setOpConfigAndEntryPointFnTranslation( | ||
| entryPointFn, op, loweringConfig, | ||
| getCPUTranslationInfo(op.getContext(), CPUPipeline::DataTiling)); |
There was a problem hiding this comment.
It's better to go through mmt4d pipeline, which has modern lowerings. The DataTiling one was created for pack/unpack ops and some optimizations are not kicked in. I haven't collapse the pipeline just because there are ukernels request sometimes, and I don't have cycles to fix future issue requests. This is a very rare path in CPU codegen, because packing ops are supposed to be fused.
iree/compiler/src/iree/compiler/Codegen/LLVMCPU/Passes.cpp
Lines 334 to 388 in 7247601
There was a problem hiding this comment.
Thanks for catching this!!
|
The best path is using double tiling expert, but that pipeline is not very good at bc level ukernel support atm. So we can still start from mmt4d pipeline. |
Adds a `setRootConfig(InnerTiledOp)` overload in `KernelDispatch.cpp`
that:
* routes `iree_codegen.inner_tiled` roots through the
`Mmt4dTilingExpert` pipeline. The DataTiling pipeline is the
pack/unpack-focused pipeline and not all the modern lowerings (e.g.
tile-and-fuse, post-bufferize vector lowering) kick in there;
Mmt4dTilingExpert has them, plus its `GenericVectorizationPass` step
is where vector-semantics lifting of `inner_tiled` happens via the
in-tree `VectorizableOpInterface` external model. The previous
commit schedules `LLVMCPULowerInnerTiledPass` right after
`GenericVectorizationPass` in this pipeline.
* sets `distribution = (1, 1, 0)` (one inner tile per workgroup in
the M and N parallel iter dims, K not distributed);
* sets `vector_common_parallel = (1, 1, 0)` and
`vector_reduction = (0, 0, 1)` so the K dim is tiled to a real
`scf.for` instead of being fully unrolled inside the
`LLVMCPULowerInnerTiledPass` greedy fixed point.
Without this commit, a `linalg.matmul` with
`--iree-opt-data-tiling --iree-llvmcpu-enable-inner-tiled` ended up on
the `Default` pipeline (which has no inner_tiled lowering hook) and
either failed bufferization (for non-trivial K) or compiled in time
exponential in K (after the previous "unroll inner_tiled" commit
turned the survival into a compile-time blow-up). With this commit,
a 256x256x256 f32 matmul on znver5 now compiles end-to-end in seconds:
the workgroup body is a tight scf.for(K_iter) wrapping a single
`llvm.call_intrinsic "llvm.fma.v16f32"` per intrinsics_m unroll.
Distribution tile sizing is deliberately conservative (1 inner tile
per parallel dim) — the mmt4d cost-model-driven sizing heuristic
should be ported to inner_tiled as a follow-up.
Signed-off-by: Benoit Jacob <[email protected]>
Progress towards #24323
bc61137 to
146a244
Compare
Done. Thanks again for catching this. It shows how human expert reviewers are still as necessary when AI does the code authoring. |
Agreed -- AI tools are powerful, and human are still responsible to those code, IMO. |
…ass. `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 the previous NFC commit on this stack) 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. Adds a focused `compiler/src/iree/compiler/Codegen/LLVMCPU/test/virtual_vector_lowering_inner_tiled.mlir` lit test that runs through `iree-llvmcpu-virtual-vector-lowering` and asserts a single `llvm.fma.v16f32` call with no surviving `util.hoistable_conversion` on the AVX-512 1x16x1 f32 single-tile case. 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`. Signed-off-by: Benoit Jacob <[email protected]> Progress towards #24323
…ass. `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 the previous NFC commit on this stack) 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. Adds a focused `compiler/src/iree/compiler/Codegen/LLVMCPU/test/virtual_vector_lowering_inner_tiled.mlir` lit test that runs through `iree-llvmcpu-virtual-vector-lowering` and asserts a single `llvm.fma.v16f32` call with no surviving `util.hoistable_conversion` on the AVX-512 1x16x1 f32 single-tile case. 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`. Signed-off-by: Benoit Jacob <[email protected]> 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]>
Adds a `setRootConfig(InnerTiledOp)` overload in `KernelDispatch.cpp`
that:
* routes `iree_codegen.inner_tiled` roots through the
`Mmt4dTilingExpert` pipeline. The DataTiling pipeline is the
pack/unpack-focused pipeline and not all the modern lowerings (e.g.
tile-and-fuse, post-bufferize vector lowering) kick in there;
Mmt4dTilingExpert has them, plus its `GenericVectorizationPass` step
is where vector-semantics lifting of `inner_tiled` happens via the
in-tree `VectorizableOpInterface` external model. The previous
commit schedules `LLVMCPULowerInnerTiledPass` right after
`GenericVectorizationPass` in this pipeline.
* sets `distribution = (1, 1, 0)` (one inner tile per workgroup in
the M and N parallel iter dims, K not distributed);
* sets `vector_common_parallel = (1, 1, 0)` and
`vector_reduction = (0, 0, 1)` so the K dim is tiled to a real
`scf.for` instead of being fully unrolled inside the
`LLVMCPULowerInnerTiledPass` greedy fixed point.
Without this commit, a `linalg.matmul` with
`--iree-opt-data-tiling --iree-llvmcpu-enable-inner-tiled` ended up on
the `Default` pipeline (which has no inner_tiled lowering hook) and
either failed bufferization (for non-trivial K) or compiled in time
exponential in K (after the previous "unroll inner_tiled" commit
turned the survival into a compile-time blow-up). With this commit,
a 256x256x256 f32 matmul on znver5 now compiles end-to-end in seconds:
the workgroup body is a tight scf.for(K_iter) wrapping a single
`llvm.call_intrinsic "llvm.fma.v16f32"` per intrinsics_m unroll.
Distribution tile sizing is deliberately conservative (1 inner tile
per parallel dim) — the mmt4d cost-model-driven sizing heuristic
should be ported to inner_tiled as a follow-up.
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]>
…rg#24328) Adds a `setRootConfig(InnerTiledOp)` overload in `KernelDispatch.cpp` that: * routes `iree_codegen.inner_tiled` roots through the `Mmt4dTilingExpert` pipeline. The DataTiling pipeline is the pack/unpack-focused pipeline and not all the modern lowerings (e.g. tile-and-fuse, post-bufferize vector lowering) kick in there; Mmt4dTilingExpert has them, plus its `GenericVectorizationPass` step is where vector-semantics lifting of `inner_tiled` happens via the in-tree `VectorizableOpInterface` external model. The previous commit schedules `LLVMCPULowerInnerTiledPass` right after `GenericVectorizationPass` in this pipeline. * sets `distribution = (1, 1, 0)` (one inner tile per workgroup in the M and N parallel iter dims, K not distributed); * sets `vector_common_parallel = (1, 1, 0)` and `vector_reduction = (0, 0, 1)` so the K dim is tiled to a real `scf.for` instead of being fully unrolled inside the `LLVMCPULowerInnerTiledPass` greedy fixed point. Without this commit, a `linalg.matmul` with `--iree-opt-data-tiling --iree-llvmcpu-enable-inner-tiled` ended up on the `Default` pipeline (which has no inner_tiled lowering hook) and either failed bufferization (for non-trivial K) or compiled in time exponential in K (after the previous "unroll inner_tiled" commit turned the survival into a compile-time blow-up). With this commit, a 256x256x256 f32 matmul on znver5 now compiles end-to-end in seconds: the workgroup body is a tight scf.for(K_iter) wrapping a single `llvm.call_intrinsic "llvm.fma.v16f32"` per intrinsics_m unroll. Distribution tile sizing is deliberately conservative (1 inner tile per parallel dim) — the mmt4d cost-model-driven sizing heuristic should be ported to inner_tiled as a follow-up. 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]>
Adds a
setRootConfig(InnerTiledOp)overload inKernelDispatch.cppthat:
iree_codegen.inner_tiledroots through theMmt4dTilingExpertpipeline. The DataTiling pipeline is thepack/unpack-focused pipeline and not all the modern lowerings (e.g.
tile-and-fuse, post-bufferize vector lowering) kick in there;
Mmt4dTilingExpert has them, plus its
GenericVectorizationPassstepis where vector-semantics lifting of
inner_tiledhappens via thein-tree
VectorizableOpInterfaceexternal model. The previouscommit schedules
LLVMCPULowerInnerTiledPassright afterGenericVectorizationPassin this pipeline.distribution = (1, 1, 0)(one inner tile per workgroup inthe M and N parallel iter dims, K not distributed);
vector_common_parallel = (1, 1, 0)andvector_reduction = (0, 0, 1)so the K dim is tiled to a realscf.forinstead of being fully unrolled inside theLLVMCPULowerInnerTiledPassgreedy fixed point.Without this commit, a
linalg.matmulwith--iree-opt-data-tiling --iree-llvmcpu-enable-inner-tiledended up onthe
Defaultpipeline (which has no inner_tiled lowering hook) andeither failed bufferization (for non-trivial K) or compiled in time
exponential in K (after the previous "unroll inner_tiled" commit
turned the survival into a compile-time blow-up). With this commit,
a 256x256x256 f32 matmul on znver5 now compiles end-to-end in seconds:
the workgroup body is a tight scf.for(K_iter) wrapping a single
llvm.call_intrinsic "llvm.fma.v16f32"per intrinsics_m unroll.Distribution tile sizing is deliberately conservative (1 inner tile
per parallel dim) — the mmt4d cost-model-driven sizing heuristic
should be ported to inner_tiled as a follow-up.
Progress towards #24323