Skip to content

[Codegen][CPU] Materialize data-tiled encodings to inner_tiled. - #24289

Merged
bjacob merged 1 commit into
mainfrom
users/bjacob/inner-tiled-materialize-encoding
Apr 29, 2026
Merged

bjacob merged 1 commit into
mainfrom
users/bjacob/inner-tiled-materialize-encoding

Conversation

@bjacob

@bjacob bjacob commented Apr 28, 2026

Copy link
Copy Markdown
Collaborator

When a target sets enable_inner_tiled = true, lower matmuls with encodings to iree_codegen.inner_tiled whose kind is a CPU data_tiled_mma_layout, instead of linalg.mmt4d.

The intrinsic and its orientation (transposed_intrinsic) are chosen jointly by a small cost model that maximizes "useful ops" per invocation (charging an intrinsic for the padding it would force along statically narrow M/N), with the intrinsic's raw MNK as tiebreaker.

Unroll factors are hard-coded to intrinsics_m = intrinsics_n = 1 for now; a follow-up commit introduces the register-budget/arithmetic- intensity cost model that picks better values.

Also:

  • Add the AVX2+FMA f32 intrinsic (MMA_X86_AVX2_FMA_1x8x1_F32_F32) to enabling writing additional tests.
  • Have MaterializeEncodingPatterns emit a clean op-level error if a layout lowering returns nullptr, rather than segfaulting.

AI: Claude Opus 4.7

@bjacob
bjacob marked this pull request as ready for review April 28, 2026 18:46

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

LGTM, just a couple nits and a question about roundtrip test.

Comment on lines +1003 to +1008
DictionaryAttr config = layoutAttr.getConfiguration();
if (getEnableInnerTiledFromConfig(config)) {
return getInnerTiledEncodingInfo(type.getContext(), encoding, *cDims,
config);
}
return getMmt4dEncodingInfo(encoding, *cDims, config);

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 okay to have the "fork" as we are moving towards inner tiles approach. It is mostly a note for future contributors and reviewers.

When a target sets `enable_inner_tiled = true`, lower matmuls with
encodings to `iree_codegen.inner_tiled` whose kind is a CPU
`data_tiled_mma_layout`, instead of `linalg.mmt4d`.

The intrinsic and its orientation (`transposed_intrinsic`) are chosen
jointly by a small cost model that maximizes "useful ops" per
invocation (charging an intrinsic for the padding it would force along
statically narrow M/N), with the intrinsic's raw M*N*K as tiebreaker.

Unroll factors are hard-coded to `intrinsics_m = intrinsics_n = 1` for
now; a follow-up commit introduces the register-budget/arithmetic-
intensity cost model that picks better values.

Also:
- Add the AVX2+FMA f32 intrinsic (`MMA_X86_AVX2_FMA_1x8x1_F32_F32`)
  to enabling writing additional tests.
- Have MaterializeEncodingPatterns notify a match failure if a layout
  lowering returns nullptr, rather than segfaulting.

Made-with: Cursor
Signed-off-by: Benoit Jacob <[email protected]>
@bjacob
bjacob force-pushed the users/bjacob/inner-tiled-materialize-encoding branch from 0c49f4e to 9d45d2b Compare April 29, 2026 16:22
@bjacob

bjacob commented Apr 29, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks, I have applied both your suggestions (notifyMatchFailure and reverted the round_trip.mlir test).

@bjacob
bjacob enabled auto-merge (squash) April 29, 2026 16:23
@bjacob
bjacob merged commit 798e137 into main Apr 29, 2026
64 of 65 checks passed
@bjacob
bjacob deleted the users/bjacob/inner-tiled-materialize-encoding branch April 29, 2026 17:19
bjacob added a commit that referenced this pull request Apr 30, 2026
#24303)

Replace the hard-coded `intrinsics_m = intrinsics_n = 1` from #24289
with a simple cost model based on maximizing arithmetic intensity
under the constraint of fitting in register space.

AI: Claude Opus 4.7

Signed-off-by: Benoit Jacob <[email protected]>
@bjacob bjacob mentioned this pull request Apr 30, 2026
25 of 28 tasks
jerryyin pushed a commit that referenced this pull request May 7, 2026
When a target sets `enable_inner_tiled = true`, lower matmuls with
encodings to `iree_codegen.inner_tiled` whose kind is a CPU
`data_tiled_mma_layout`, instead of `linalg.mmt4d`.

The intrinsic and its orientation (`transposed_intrinsic`) are chosen
jointly by a small cost model that maximizes "useful ops" per invocation
(charging an intrinsic for the padding it would force along statically
narrow M/N), with the intrinsic's raw M*N*K as tiebreaker.

Unroll factors are hard-coded to `intrinsics_m = intrinsics_n = 1` for
now; a follow-up commit introduces the register-budget/arithmetic-
intensity cost model that picks better values.

Also:
- Add the AVX2+FMA f32 intrinsic (`MMA_X86_AVX2_FMA_1x8x1_F32_F32`) to
enabling writing additional tests.
- Have MaterializeEncodingPatterns emit a clean op-level error if a
layout lowering returns nullptr, rather than segfaulting.

AI: Claude Opus 4.7

Signed-off-by: Benoit Jacob <[email protected]>
jerryyin pushed a commit that referenced this pull request May 7, 2026
#24303)

Replace the hard-coded `intrinsics_m = intrinsics_n = 1` from #24289
with a simple cost model based on maximizing arithmetic intensity
under the constraint of fitting in register space.

AI: Claude Opus 4.7

Signed-off-by: Benoit Jacob <[email protected]>
RattataKing pushed a commit to RattataKing/iree that referenced this pull request May 27, 2026
…-org#24289)

When a target sets `enable_inner_tiled = true`, lower matmuls with
encodings to `iree_codegen.inner_tiled` whose kind is a CPU
`data_tiled_mma_layout`, instead of `linalg.mmt4d`.

The intrinsic and its orientation (`transposed_intrinsic`) are chosen
jointly by a small cost model that maximizes "useful ops" per invocation
(charging an intrinsic for the padding it would force along statically
narrow M/N), with the intrinsic's raw M*N*K as tiebreaker.

Unroll factors are hard-coded to `intrinsics_m = intrinsics_n = 1` for
now; a follow-up commit introduces the register-budget/arithmetic-
intensity cost model that picks better values.

Also:
- Add the AVX2+FMA f32 intrinsic (`MMA_X86_AVX2_FMA_1x8x1_F32_F32`) to
enabling writing additional tests.
- Have MaterializeEncodingPatterns emit a clean op-level error if a
layout lowering returns nullptr, rather than segfaulting.

AI: Claude Opus 4.7

Signed-off-by: Benoit Jacob <[email protected]>
RattataKing pushed a commit to RattataKing/iree that referenced this pull request May 27, 2026
iree-org#24303)

Replace the hard-coded `intrinsics_m = intrinsics_n = 1` from iree-org#24289
with a simple cost model based on maximizing arithmetic intensity
under the constraint of fitting in register space.

AI: Claude Opus 4.7

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