Skip to content

[Codegen][CPU] Teach the lowering strategy about inner_tiled. - #24328

Merged
bjacob merged 1 commit into
mainfrom
users/bjacob/cpu-inner-tiled-strategy
May 1, 2026
Merged

bjacob merged 1 commit into
mainfrom
users/bjacob/cpu-inner-tiled-strategy

Conversation

@bjacob

@bjacob bjacob commented Apr 30, 2026 •

Copy link
Copy Markdown
Collaborator

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

@bjacob bjacob mentioned this pull request Apr 30, 2026
25 of 28 tasks
@bjacob
bjacob force-pushed the users/bjacob/cpu-inner-tiled-strategy branch from eb70366 to bc61137 Compare April 30, 2026 19:40
@bjacob
bjacob marked this pull request as ready for review April 30, 2026 19:43
@bjacob
bjacob requested a review from hanhanW as a code owner April 30, 2026 19:43

@hanhanW hanhanW left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tried mmt4d pipeline? I think that is the pipeline we should target for this op.

Comment on lines +1680 to +1686
// `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).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

void addMmt4dTilingExpertPassPipeline(
OpPassManager &funcPassManager, const LLVMCPUPipelineOptions &pipelineOpt) {
addTileAndDistributePasses(funcPassManager, pipelineOpt);
funcPassManager.addPass(createLLVMCPUTileAndFuseProducerConsumerPass(
IREE::CPU::TilingLevel::VectorCommonParallelTiles));
// The below two passes are nop if the "mmt4d" is explicitly excluded in the
// ukernels attribute.
funcPassManager.addPass(createCPUPrepareUkernelsPass());
funcPassManager.addPass(createCPULowerToUKernelsPass(
pipelineOpt.cpuOpts.skipIntermediateRoundings));
funcPassManager.addPass(createLLVMCPUTileRootAndFuseInputOperandsPass(
IREE::CPU::TilingLevel::VectorReductionTiles));
// `VectorInnerParallelTiles` level models the tiling and fusion for the
// dimensions that are not captured in root op. I.e., root op may not have the
// config for the level. Thus, we use the last operation that has the tiling
// level as anchor.
funcPassManager.addPass(createLLVMCPUTileLastOpAndFuseProducerConsumerPass(
IREE::CPU::TilingLevel::VectorInnerParallelTiles));
funcPassManager.addPass(iree_compiler::createForallToForPass());
funcPassManager.addPass(createLLVMCPUTileToVectorSizePass());
{
GenericVectorizationPassOptions options;
options.useConfiguredVectorSizes = pipelineOpt.useConfiguredVectorSizes;
options.enableVectorMasking = pipelineOpt.enableVectorMasking;
options.vectorizeToTransferGather =
pipelineOpt.cpuOpts.enableTransferGather;
funcPassManager.addPass(createGenericVectorizationPass(options));
funcPassManager.addPass(createOptimizeTensorInsertExtractSlicesPass());
funcPassManager.addPass(createCanonicalizerPass());
funcPassManager.addPass(createCSEPass());
if (clFailOnLargeVector) {
funcPassManager.addPass(createLLVMCPUVerifyVectorSizeLegalityPass());
}
}
funcPassManager.addPass(createCanonicalizerPass());
funcPassManager.addPass(createCSEPass());
addCPUBufferizePasses(funcPassManager);
// Vector lowering of Mmt4d.
funcPassManager.addPass(createLLVMCPUMmt4dVectorLoweringPass(
LLVMCPUMmt4dVectorLoweringPassOptions{
clEnableVectorContractCustomKernels}));
// Generic vector lowering.
LLVMCPUVectorLoweringPassOptions options;
options.lowerVectorTransposeToAVX2 = pipelineOpt.lowerToAVX2;
options.splitVectorTransfersTo = "linalg-copy";
options.enableArmI8mm = pipelineOpt.enableAArch64I8mm;
options.enableArmSME = pipelineOpt.enableAArch64SME;
buildLLVMCPUVectorLoweringPipeline(funcPassManager, options);
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this!!

@hanhanW

hanhanW commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

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
@bjacob
bjacob force-pushed the users/bjacob/cpu-inner-tiled-strategy branch from bc61137 to 146a244 Compare May 1, 2026 15:17
@bjacob

bjacob commented May 1, 2026

Copy link
Copy Markdown
Collaborator Author

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.

Done. Thanks again for catching this. It shows how human expert reviewers are still as necessary when AI does the code authoring.

@bjacob
bjacob requested a review from hanhanW May 1, 2026 15:25
@hanhanW

hanhanW commented May 1, 2026

Copy link
Copy Markdown
Contributor

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.

@bjacob
bjacob enabled auto-merge (squash) May 1, 2026 15:36
@bjacob
bjacob merged commit c40c7a3 into main May 1, 2026
63 of 65 checks passed
@bjacob
bjacob deleted the users/bjacob/cpu-inner-tiled-strategy branch May 1, 2026 16:02
bjacob added a commit that referenced this pull request May 4, 2026
…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
bjacob added a commit that referenced this pull request May 4, 2026
…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
bjacob added a commit that referenced this pull request May 5, 2026
…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]>
jerryyin pushed a commit that referenced this pull request May 7, 2026
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
jerryyin pushed a commit that referenced this pull request May 7, 2026
…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]>
RattataKing pushed a commit to RattataKing/iree that referenced this pull request May 27, 2026
…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
RattataKing pushed a commit to RattataKing/iree that referenced this pull request May 27, 2026
…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]>
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.

2 participants