Skip to content

[Codegen][CPU] Materialize and lower RISC-V V inner_tiled MMA (f32, f16, bf16, i8) - #24926

Closed
TMahlatini wants to merge 2 commits into
iree-org:mainfrom
TMahlatini:users/tmahlatini/inner-tiled-rvv-mma
Closed

TMahlatini wants to merge 2 commits into
iree-org:mainfrom
TMahlatini:users/tmahlatini/inner-tiled-rvv-mma

Conversation

@TMahlatini

Copy link
Copy Markdown
Contributor

#24858 added vlen on DataTiledMMAAttr and f16 inner_tiled materialization on RISC-V V, but did not lower to LLVM. This continues that work for #24311: more RVV MMA enums, encoding selection, and lowering of iree_codegen.inner_tiled to llvm.call_intrinsic.

One enum pair still covers every +zvl*b length. Tile N is vlen/8 (8VLs); the swapped sibling is the M↔N orientation. LHS is the scalar .vf / .vx operand so m_bcst can fold, matching the mmt4d ukernels.

Family Intrinsic Features Lowering
f32×f32→f32 vfmacc.vf +v llvm.riscv.vfmacc
f16×f16→f16 vfmacc.vf +zvfh llvm.riscv.vfmacc
f16×f16→f32 CASTF32 extf + f32 vfmacc.vf +zvfhmin (+zvfh implies it) arith.extf then llvm.riscv.vfmacc
bf16×bf16→f32 vfwmaccbf16.vf +zvfbfwma llvm.riscv.vfwmaccbf16
i8×i8→i32 CASTI16 vsext + vwmacc.vx +v arith.extsi + llvm.riscv.vsext + llvm.riscv.vwmacc

Native Zvfh still wins over CASTF32 when both are legal.

Towards #24311

Assisted-by: Cursor

TMahlatini and others added 2 commits September 11, 2026 13:04
…F32).

f32 and native f16 lower to llvm.riscv.vfmacc. CASTF32 (Zvfhmin) extends
f16 panels to f32 and reuses that path. N is vlen/8. +zvfh implies
+zvfhmin for CASTF32 selection.

Signed-off-by: Terence <[email protected]>
Co-authored-by: Cursor <[email protected]>
…ed MMA.

bf16 lowers to llvm.riscv.vfwmaccbf16 (+zvfbfwma). i8 sign-extends i8m1
to i16m2 then vwmacc.vx into i32. N is vlen/8.

Signed-off-by: Terence <[email protected]>
Co-authored-by: Cursor <[email protected]>
@TMahlatini

Copy link
Copy Markdown
Contributor Author

cc @egebeysel

@egebeysel

Copy link
Copy Markdown
Contributor

Nice! Thanks for the patch. First things first, let's split this PR into multiple parts and handle all F16, F32, BF16, and INT8 in separate PRs. I have not yet looked at the implementation, though if you have any infrastructure/plumbing work that is required across data types, that could also be its own PR.

Furthermore, we ideally want the performance of code generating with inner_tiled on-par with the mmt4d microkernels approach. Therefore, it would be nice if you could include a performance comparison for a few shapes on each of these data types. Obviously, we do NOT have to be on-par at first-iteration and can build up performance incrementally but it would be nice to know where we stand. If there are performance regressions, you can spawn new issues for each data type (or a parent performance tracking issue + subissues) and we could track them there.

Lastly, I see that some of the e2e matmul tests are timing out. Take a look at: #24593 for a similar issue we had: we ran only a certain subset of all matmul shapes for rv64 on slow-running configurations.

I'll take a look as soon as I can :)

@TMahlatini

Copy link
Copy Markdown
Contributor Author

Nice! Thanks for the patch. First things first, let's split this PR into multiple parts and handle all F16, F32, BF16, and INT8 in separate PRs. I have not yet looked at the implementation, though if you have any infrastructure/plumbing work that is required across data types, that could also be its own PR.

Furthermore, we ideally want the performance of code generating with inner_tiled on-par with the mmt4d microkernels approach. Therefore, it would be nice if you could include a performance comparison for a few shapes on each of these data types. Obviously, we do NOT have to be on-par at first-iteration and can build up performance incrementally but it would be nice to know where we stand. If there are performance regressions, you can spawn new issues for each data type (or a parent performance tracking issue + subissues) and we could track them there.

Lastly, I see that some of the e2e matmul tests are timing out. Take a look at: #24593 for a similar issue we had: we ran only a certain subset of all matmul shapes for rv64 on slow-running configurations.

I'll take a look as soon as I can :)

thanks, will decouple and take a look at #24593

@TMahlatini

Copy link
Copy Markdown
Contributor Author

closing this PR in favor of per-type PRs. f32 is here #24933 Perfomance vs ukernels is tracking here: #24932. f16, bf16, and i8 will be stacked follow-ups following the same as direction as this patch.

@TMahlatini TMahlatini closed this Sep 14, 2026
AGindinson pushed a commit that referenced this pull request Oct 1, 2026
## Summary

Lowers RISC-V V f32 `inner_tiled` MMA (`MMA_RISCV_V_VFMACC_*_F32_F32`)
to
`llvm.riscv.vfmacc` (`vfmacc.vf`). Tile N is `vlen/8`. Introduces shared
helper
`lowerRiscvVFmaccLike`.

This is the first stacked dtype PR from #24926 review. Performance will
be tracked here #24932

Assisted-by: Cursor

Towards: #24311

---------

Signed-off-by: Terence <[email protected]>
Co-authored-by: Cursor <[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