Skip to content

[Codegen][CPU] Fix RHS indexing map in materialize-encoding inner_tiled lowering. - #24325

Merged
bjacob merged 1 commit into
mainfrom
users/bjacob/materialize-encoding-rhs-fix
May 1, 2026
Merged

bjacob merged 1 commit into
mainfrom
users/bjacob/materialize-encoding-rhs-fix

Conversation

@bjacob

@bjacob bjacob commented Apr 30, 2026

Copy link
Copy Markdown
Collaborator

The CPU encoding-materialization path (lowerContractionOpToInnerTiled) emits an iree_codegen.inner_tiled op with the standard matmul indexing maps [(d0, d2), (d2, d1), (d0, d1)], but the RHS pack it lowers to uses outer_dims_perm = [1, 0] so the packed RHS comes out with outer dims in (N_iter, K_iter) order — i.e. mmt4d-style, not standard-matmul style. The two interpretations of the same operand shape disagree, and the inner_tiled verifier rejects the op with:

error: 'iree_codegen.inner_tiled' op shape does not match
       iteration bounds

Switching the RHS map to (d0, d1, d2) -> (d1, d2) matches what the pack actually produces and lets the verifier project a consistent iteration domain across all three operands. The semantics are still a valid contraction (one parallel + one reduction on each input, two parallels on the output), just with the RHS walked in mmt4d order.

Without this fix, data-tiled linalg.matmul -> inner_tiled lowering on CPU fails the verifier on the very first dispatch and never gets near codegen; with it, end-to-end compile gets past verification all the way to bufferization (where a separate, pre-existing pipeline gap takes over: there is no CPU pass yet that vectorizes/lowers inner_tiled before bufferize).

Progress towards #24323

…ed lowering.

The CPU encoding-materialization path (`lowerContractionOpToInnerTiled`)
emits an `iree_codegen.inner_tiled` op with the standard matmul indexing
maps `[(d0, d2), (d2, d1), (d0, d1)]`, but the RHS pack it lowers to
uses `outer_dims_perm = [1, 0]` so the packed RHS comes out with outer
dims in `(N_iter, K_iter)` order — i.e. mmt4d-style, not standard-matmul
style. The two interpretations of the same operand shape disagree, and
the inner_tiled verifier rejects the op with:

    error: 'iree_codegen.inner_tiled' op shape does not match
           iteration bounds

Switching the RHS map to `(d0, d1, d2) -> (d1, d2)` matches what the
pack actually produces and lets the verifier project a consistent
iteration domain across all three operands. The semantics are still a
valid contraction (one parallel + one reduction on each input, two
parallels on the output), just with the RHS walked in mmt4d order.

Without this fix, data-tiled `linalg.matmul` -> `inner_tiled` lowering
on CPU fails the verifier on the very first dispatch and never gets
near codegen; with it, end-to-end compile gets past verification all
the way to bufferization (where a separate, pre-existing pipeline gap
takes over: there is no CPU pass yet that vectorizes/lowers
`inner_tiled` before bufferize).

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

Progress towards #24323
@bjacob bjacob mentioned this pull request Apr 30, 2026
25 of 28 tasks
@bjacob
bjacob marked this pull request as ready for review April 30, 2026 19:37
@bjacob
bjacob merged commit 0a73681 into main May 1, 2026
63 of 66 checks passed
@bjacob
bjacob deleted the users/bjacob/materialize-encoding-rhs-fix branch May 1, 2026 14:36
jerryyin pushed a commit that referenced this pull request May 7, 2026
…ed lowering. (#24325)

The CPU encoding-materialization path (`lowerContractionOpToInnerTiled`)
emits an `iree_codegen.inner_tiled` op with the standard matmul indexing
maps `[(d0, d2), (d2, d1), (d0, d1)]`, but the RHS pack it lowers to
uses `outer_dims_perm = [1, 0]` so the packed RHS comes out with outer
dims in `(N_iter, K_iter)` order — i.e. mmt4d-style, not standard-matmul
style. The two interpretations of the same operand shape disagree, and
the inner_tiled verifier rejects the op with:

    error: 'iree_codegen.inner_tiled' op shape does not match
           iteration bounds

Switching the RHS map to `(d0, d1, d2) -> (d1, d2)` matches what the
pack actually produces and lets the verifier project a consistent
iteration domain across all three operands. The semantics are still a
valid contraction (one parallel + one reduction on each input, two
parallels on the output), just with the RHS walked in mmt4d order.

Without this fix, data-tiled `linalg.matmul` -> `inner_tiled` lowering
on CPU fails the verifier on the very first dispatch and never gets near
codegen; with it, end-to-end compile gets past verification all the way
to bufferization (where a separate, pre-existing pipeline gap takes
over: there is no CPU pass yet that vectorizes/lowers `inner_tiled`
before bufferize).

Progress towards #24323
RattataKing pushed a commit to RattataKing/iree that referenced this pull request May 27, 2026
…ed lowering. (iree-org#24325)

The CPU encoding-materialization path (`lowerContractionOpToInnerTiled`)
emits an `iree_codegen.inner_tiled` op with the standard matmul indexing
maps `[(d0, d2), (d2, d1), (d0, d1)]`, but the RHS pack it lowers to
uses `outer_dims_perm = [1, 0]` so the packed RHS comes out with outer
dims in `(N_iter, K_iter)` order — i.e. mmt4d-style, not standard-matmul
style. The two interpretations of the same operand shape disagree, and
the inner_tiled verifier rejects the op with:

    error: 'iree_codegen.inner_tiled' op shape does not match
           iteration bounds

Switching the RHS map to `(d0, d1, d2) -> (d1, d2)` matches what the
pack actually produces and lets the verifier project a consistent
iteration domain across all three operands. The semantics are still a
valid contraction (one parallel + one reduction on each input, two
parallels on the output), just with the RHS walked in mmt4d order.

Without this fix, data-tiled `linalg.matmul` -> `inner_tiled` lowering
on CPU fails the verifier on the very first dispatch and never gets near
codegen; with it, end-to-end compile gets past verification all the way
to bufferization (where a separate, pre-existing pipeline gap takes
over: there is no CPU pass yet that vectorizes/lowers `inner_tiled`
before bufferize).

Progress towards iree-org#24323
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