Skip to content

[Codegen][CPU] Add RISC-V V f32 vfmacc.vf inner_tiled MMA. - #24933

Merged
AGindinson merged 3 commits into
iree-org:mainfrom
TMahlatini:users/tmahlatini/inner-tiled-rvv-f32
Oct 1, 2026
Merged

AGindinson merged 3 commits into
iree-org:mainfrom
TMahlatini:users/tmahlatini/inner-tiled-rvv-f32

Conversation

@TMahlatini

@TMahlatini TMahlatini commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

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

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

Thanks for the PR and for splitting it out of #24926! Since Ege is on vacation, I'm picking up the review.

In general, the lowering looks right to me. I've left some small inline comments.

The one thing I'd like addressed before landing this is Ege's ask here: #24932 (comment). Could you take a look at the disassembly and see what's causing the performance gap compared to ukernels? I think it'd help to start with the inner loop of the matmul dispatch :))

@TMahlatini

TMahlatini commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for the PR and for splitting it out of #24926! Since Ege is on vacation, I'm picking up the review.

In general, the lowering looks right to me. I've left some small inline comments.

The one thing I'd like addressed before landing this is Ege's ask here: #24932 (comment). Could you take a look at the disassembly and see what's causing the performance gap compared to ukernels? I think it'd help to start with the inner loop of the matmul dispatch :))

Hi @phemashekar, sorry it took me a while to get back at Ege on that comment still working on it. Was caught up in the past couple days but will push a update soon. still running some local tests and collecting numbers.

@TMahlatini

Copy link
Copy Markdown
Contributor Author

Thanks for the PR and for splitting it out of #24926! Since Ege is on vacation, I'm picking up the review.

In general, the lowering looks right to me. I've left some small inline comments.

The one thing I'd like addressed before landing this is Ege's ask here: #24932 (comment). Could you take a look at the disassembly and see what's causing the performance gap compared to ukernels? I think it'd help to start with the inner loop of the matmul dispatch :))

following up on the disassembly the inner loop was a great start. on one thread for both small and large shapes, every K step zero-padded the accumulator and did a tail-undisturbed vector.scalable.insert / extract around vfmacc.vf (policy =0). That spilled m4 groups to the stack every iteration

Per K, before fix: one vle32.v, six flw, six vfmacc.vf, plus 5+ vmv.v.i, 5+ vmv.v.v, 2 vs4r.v, 2 vl4r.v, and 2 vsetvli.

Now the lowering hoists that accumulator insert/extract out of K, pads with ub.poison instead of a zero broadcast and passes policy = 3

per K, after: 1 vle32.v, 6 flw, 6 vfmacc.vf. No vmv, vs4r / vl4r, or vsetvli in the loop.

same loop in mmt4d ukernel for reference: 1 vle32.v, 7 flw, 7 vfmacc.vf.

I reran the same X60 sweep referenced here #24932 and below are the results. note ratio is flipped from the original dashboard, its ukernel wall / inner_tiled wall (more intuitive).

shape 1 / 4 / 8 thread
small 64³ 1.66 / 1.06 / 1.12×
medium 256³ 1.21 / 1.04 / 0.96×
rect 81×41×19 1.88 / 1.24 / 1.05×
large 540×516×332 1.26 / 0.77 / 0.64×

1 thread inner_tiled is faster on every shape. the remaining loss is 4/8 thread large. I will update the standing table on this issue.

@TMahlatini

Copy link
Copy Markdown
Contributor Author

@phemashekar could you please take a look at the updates when you get the chance and start the ci tests? thanks!

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

Thanks for the ping, I somehow missed it! the results look much better now, nice recovery. Just a few small comments :)

@TMahlatini

Copy link
Copy Markdown
Contributor Author

@phemashekar I have applied the feedback and fixed the failing CI run.

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

Thanks, LGTM :))

@AGindinson

Copy link
Copy Markdown
Contributor

@TMahlatini, the CI seems a bit flaky – could you try a rebase please?

@TMahlatini

Copy link
Copy Markdown
Contributor Author

@TMahlatini, the CI seems a bit flaky – could you try a rebase please?

yeah sure

TMahlatini and others added 3 commits October 1, 2026 15:31
Lower MMA_RISCV_V_VFMACC_*_F32_F32 to llvm.riscv.vfmacc. N is vlen/8.
Introduce lowerRiscvVFmaccLike. Restrict RISC-V inner_tiled e2e to
--shapes=small (iree-org#24593).

Towards iree-org#24311

Signed-off-by: Terence <[email protected]>
Co-authored-by: Cursor <[email protected]>
f32 accs are now scalable across the reduction loop and now using poison with tail/mask-agnostic pollicy to avoid redundant vector moves.

Signed-off-by: Terence <[email protected]>
@TMahlatini
TMahlatini force-pushed the users/tmahlatini/inner-tiled-rvv-f32 branch from c3aa030 to 7cdba91 Compare October 1, 2026 15:32
@AGindinson
AGindinson merged commit a3ec918 into iree-org:main Oct 1, 2026
48 of 55 checks passed
@devtbi devtbi mentioned this pull request Oct 19, 2026
7 of 8 tasks
devtbi pushed a commit that referenced this pull request Oct 21, 2026
…tiled MMA. (#25000)

Lowers the RISC-V V f16 `inner_tiled` MMA paths. Native f16 enums are
already on main from #24858. This adds lowering, the widening
`vfwmacc.vf` pair, and the `+zvfhmin`-only fallbacks. All of them reuse
`lowerRiscvVFmaccLike` and the hoisted accumulator legalization from
#24933. Tile N is `vlen/8`.

| Encoding | `+zvfh` | `+zvfhmin` only |
| --- | --- | --- |
| f16×f16→f16 | `llvm.riscv.vfmacc` (`MMA_RISCV_V_VFMACC_*_F16_F16`) |
`extf` the accumulator to f32, f32 `vfmacc`, `truncf` back
(`*_F16_F16_WIDENF32`) |
| f16×f16→f32 | `llvm.riscv.vfwmacc` (`MMA_RISCV_V_VFWMACC_*_F32_F16`) |
`extf` both panels, then f32 `vfmacc` (`*_F32_F16_CASTF32`) |

`+zvfh` implies `+zvfhmin`. When both are legal, the earlier enum wins:
native `vfmacc` for an f16 accumulator, `vfwmacc` for an f32
accumulator. At VLEN=256 the cost model picks `intrinsics_m` 14
(native), 7 (`vfwmacc`), and 6 (both `+zvfhmin` paths). CASTF32 and
WIDENF32 bill the widened f32 vector operand as f32.

Performance is tracked on #24932. On the X60 (VLEN=256), 1-thread
inner_tiled is faster than the mmt4d ukernel for native f16 and
`vfwmacc`. The 4-thread and 8-thread large shapes are still slower.
Native f16 is non-widening `vfmacc`; the f16 ukernel widens with
`vfwmacc`, so that ratio is not the same instruction sequence. `vfwmacc`
is the closer comparison.

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.

3 participants