Skip to content

[Codegen][CPU] Add LLVMCPULowerInnerTiledPass and schedule it. - #24352

Closed
bjacob wants to merge 2 commits into
mainfrom
users/bjacob/cpu-lower-inner-tiled-pass
Closed

bjacob wants to merge 2 commits into
mainfrom
users/bjacob/cpu-lower-inner-tiled-pass

Conversation

@bjacob

@bjacob bjacob commented May 4, 2026

Copy link
Copy Markdown
Collaborator

Lowers vector-semantics iree_codegen.inner_tiled ops on the CPU side
by running two pattern sets in sequence on the function body:

  1. IREE::Codegen::populateDropInnerTiledUnitDimsPatterns drops the
    (now-unit) iter domain so the lowered op has empty iter bounds,
    satisfying the precondition of (2).
  2. IREE::Codegen::populateLowerInnerTiledPatterns replaces the
    iter-free vector-semantics inner_tiled with the per-intrinsic
    llvm.call_intrinsic ops emitted by
    DataTiledMMAAttr::buildUnderlyingOperations.

Both pattern sets were lifted out of Codegen/Dialect/GPU/Transforms/
into Codegen/Dialect/Codegen/Transforms/ in #24351
so CPU can share them with GPU. They are interface-driven and pick up
CPU's IREE::CPU::DataTiledMMAAttr transparently via its
buildUnderlyingOperations implementation.

The pass expects vector-semantics input, which the upstream
GenericVectorizationPass produces via the
InnerTiledOpVectorizationModel VectorizableOpInterface external
model already in tree. Schedule the new pass right after
GenericVectorizationPass in addMmt4dTilingExpertPassPipeline, where
data-tiled-MMA dispatches will land once the next commit teaches the
lowering strategy to route them through that pipeline. The pass is a
no-op when the function has no inner_tiled ops.

Adds a focused lit test
compiler/src/iree/compiler/Codegen/LLVMCPU/test/lower_inner_tiled.mlir
that feeds a single-tile AVX-512 1x16x1 f32 vector-semantics
inner_tiled and asserts the surviving llvm.fma.v16f32 call.

Progress towards #24323

bjacob added 2 commits May 4, 2026 11:26
…degen.

Moves the two `iree_codegen.inner_tiled` rewrite patterns and their
populate functions out of `Codegen/Dialect/GPU/Transforms/` into
`Codegen/Dialect/Codegen/Transforms/LowerInnerTiled.cpp`:

  - `LowerInnerTiledPattern` (replaces an iter-bound-empty `inner_tiled`
    with the per-intrinsic ops emitted by its kind's
    `buildUnderlyingOperations`)
  - `DropInnerTiledUnitDimsPattern` (folds unit iteration bounds and
    pulls the corresponding extract/broadcast pairs out of the loop)

Both patterns operate on `IREE::Codegen::InnerTiledOp` and dispatch
through the kind's interface, so there is nothing GPU-specific about
them. Lifting them lets CPU pass authors share the same lowering logic
without a `Codegen/Dialect/GPU/...` include.

Renames the populate functions accordingly:

  - `IREE::GPU::populateIREEGPULowerInnerTiledPatterns`
        -> `IREE::Codegen::populateLowerInnerTiledPatterns`
  - `IREE::GPU::populateIREEGPUDropUnitDimsPatterns`
        -> `IREE::Codegen::populateDropInnerTiledUnitDimsPatterns`

The `kShapeCastToIntrinsic` / `kShapeCastFromIntrinsic` and
`kDropUnitDims` / `kAddUnitDims` HoistableConversionOp tag constants
move with the patterns. The remaining tag pair on the GPU side
(`kUnrollAccDistribute` / `kUnrollAccReassemble`) stays in
`Codegen/Dialect/GPU/Transforms/Transforms.cpp` since it's still only
used by the GPU unroll path.

Updates the existing in-tree callers in `LowerIREEGPUOps.cpp`,
`IREEGPUExtensions.cpp`, and `UnrollToIntrinsics.cpp`, and adjusts
BUILD.bazel/CMakeLists.txt deps so GPU's transform libraries depend on
`IREECodegenTransforms`.

Strict NFC; no functional or behavioral change.

Signed-off-by: Benoit Jacob <[email protected]>

Progress towards #24323
Lowers vector-semantics `iree_codegen.inner_tiled` ops on the CPU side
by running two pattern sets in sequence on the function body:

  1. `IREE::Codegen::populateDropInnerTiledUnitDimsPatterns` drops the
     (now-unit) iter domain so the lowered op has empty iter bounds,
     satisfying the precondition of (2).
  2. `IREE::Codegen::populateLowerInnerTiledPatterns` replaces the
     iter-free vector-semantics inner_tiled with the per-intrinsic
     `llvm.call_intrinsic` ops emitted by
     `DataTiledMMAAttr::buildUnderlyingOperations`.

Both pattern sets were lifted out of `Codegen/Dialect/GPU/Transforms/`
into `Codegen/Dialect/Codegen/Transforms/` in the previous (NFC) commit
so CPU can share them with GPU. They are interface-driven and pick up
CPU's `IREE::CPU::DataTiledMMAAttr` transparently via its
`buildUnderlyingOperations` implementation.

The pass expects vector-semantics input, which the upstream
`GenericVectorizationPass` produces via the
`InnerTiledOpVectorizationModel` `VectorizableOpInterface` external
model already in tree. Schedule the new pass right after
`GenericVectorizationPass` in `addMmt4dTilingExpertPassPipeline`, where
data-tiled-MMA dispatches will land once the next commit teaches the
lowering strategy to route them through that pipeline. The pass is a
no-op when the function has no inner_tiled ops.

Adds a focused lit test
`compiler/src/iree/compiler/Codegen/LLVMCPU/test/lower_inner_tiled.mlir`
that feeds a single-tile AVX-512 1x16x1 f32 vector-semantics
inner_tiled and asserts the surviving `llvm.fma.v16f32` call.

Signed-off-by: Benoit Jacob <[email protected]>

Progress towards #24323
@bjacob
bjacob marked this pull request as ready for review May 4, 2026 16:42
@bjacob
bjacob requested a review from hanhanW as a code owner May 4, 2026 16:42
Base automatically changed from users/bjacob/nfc-lift-inner-tiled-patterns to main May 4, 2026 16:44
@bjacob bjacob mentioned this pull request May 4, 2026
25 of 28 tasks

@krzysz00 krzysz00 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.

Two notes, but this looks mostly like stampable code movement, so approved after notes

IREE::Codegen::populateLowerInnerTiledPatterns(patterns);
if (failed(applyPatternsGreedily(getOperation(), std::move(patterns)))) {
return signalPassFailure();
}

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.

I think you'll want to run the hoistable conversions code after this

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.

@krzysz00 : If I understand correctly what you mean, this is exactly what the next PR does: #24353.

Runs three pattern sets in sequence on the function body:
(1) `populateVectorizeInnerTiledPatterns`: lift tensor-semantics
inner_tiled ops to vector semantics.
(2) `populateIREEGPUDropUnitDimsPatterns`: drop the (now-unit) iteration

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.

Do we want to drop the "GPU" from these now?

Comment on lines +103 to +114
Runs three pattern sets in sequence on the function body:
(1) `populateVectorizeInnerTiledPatterns`: lift tensor-semantics
inner_tiled ops to vector semantics.
(2) `populateIREEGPUDropUnitDimsPatterns`: drop the (now-unit) iteration
domain so the lowered op has empty iter bounds.
(3) `populateIREEGPULowerInnerTiledPatterns`: replace the vector-
semantics, iter-domain-free inner_tiled with the per-intrinsic
`llvm.call_intrinsic` ops emitted by
`DataTiledMMAAttr::buildUnderlyingOperations`.
Despite the `IREEGPU` names, patterns (2) and (3) are interface-driven and
work for any `InnerTileDescAttrInterface` kind, including CPU's
`IREE::CPU::DataTiledMMAAttr`.

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 outdated? GPU should not be mentioned at all in this pass.

Comment on lines +28 to +30
// Expects vector-semantics `iree_codegen.inner_tiled` produced by the
// generic vectorization pass via the `VectorizableOpInterface` external
// model in `compiler/src/iree/compiler/Codegen/Interfaces/`.

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.

This should be part of pass description, and we should not mention GenericVectorization or how the op is vectorized at all IMO. The pass itself does not care that. What it expects is vectorized inner tiled. Let's drop the vectorization mechanism and move it into description?

btw, how about naming the pass as "LLVMCPULowerVectorizedInnerTiledPass`?


// `iree-llvmcpu-lower-inner-tiled` runs two pattern sets in sequence on a
// vector-semantics `iree_codegen.inner_tiled` (the kind produced by
// GenericVectorization via the VectorizableOpInterface external model):

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.

Same here, this is leaking layering assumption which is redundant to this pass.

Comment on lines +371 to +376
// Lower any iree_codegen.inner_tiled ops produced by the data-tiled MMA
// path. GenericVectorization above lifts them to vector-semantics via the
// VectorizableOpInterface external model; this pass then drops their unit
// iter dims and emits the per-intrinsic ops via
// `DataTiledMMAAttr::buildUnderlyingOperations`. If the dispatch has no
// inner_tiled ops the pass is a no-op.

@hanhanW hanhanW May 4, 2026 •

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.

I think we can say that this is similar to ukernel path, but it is more powerful because of fusion. I don't have fresh memory for the lowering patterns. IIRC, it should also unroll the inner tiled op which has the same behavior as your ukernels?

Open question: do we do the lowering after bufferization? The inner tiled captures the memref semantics well, which seems to have less burden in the pipeline. My first thinking for the pass is about "high level vector lowering", because it is lowering a "virtual vector" to IRs that is closer to LLVM dialect (low-level dialect). Thus, it belongs to the LLVMCPUVirtualVectorLoweringPass in buildLLVMCPUVectorLoweringPipeline IMO.

Do we just add the patterns to the pass? And we can add tests to virtual_vector_lowering.mlir in this context.

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.

I think you are right @hanhanW . Let me close this PR and redo this like you suggest.

@bjacob bjacob closed this May 4, 2026
@bjacob
bjacob deleted the users/bjacob/cpu-lower-inner-tiled-pass branch May 4, 2026 18:05
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.

3 participants