Skip to content

[Codegen][CPU] Add RISC-V V i8 CASTI16 inner_tiled MMA - #25357

Open
Prajit-Rahul wants to merge 1 commit into
iree-org:mainfrom
Prajit-Rahul:issue-24932-rvv-i8-casti16
Open

Prajit-Rahul wants to merge 1 commit into
iree-org:mainfrom
Prajit-Rahul:issue-24932-rvv-i8-casti16

Conversation

@Prajit-Rahul

@Prajit-Rahul Prajit-Rahul commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Added RISC-V V inner_tiled lowering for signed i8 × i8 → i32 matmul for RV64 with +v. The two tile orientations use VLEN / 8 lanes along M or N. Sign-extend the scalar and vector operands to i16 and accumulate into i32 with vwmacc.vx. Kept the accumulator scalable across K and accounted for the widened vector when choosing unroll factors.

Used Banana Pi F3 (SpaceMiT X60, VLEN 256), 10 repetitions per configuration. Ratios are mmt4d microkernel mean wall time divided by inner_tiled mean wall time.

Shape (M×N×K) 1 thread 4 threads 8 threads
64×64×64 1.12× 0.96× 1.01×
256×256×256 1.06× 0.99× 1.06×
81×41×19 1.72× 1.18× 1.02×
540×516×332 1.37× 1.62× 1.70×

Both paths used --iree-llvmcpu-vscale-range=4,4 with compiler distribution enabled. The 1-thread runs used local-sync, and the 4 and 8 thread runs used local-task. All timing runs preloaded rvv-prime.so to work around a first-use vl1r.v failure reproduced outside IREE on Linux 6.6.36-current-k1.

Towards #24932

Assisted-by: Codex

@Prajit-Rahul

Copy link
Copy Markdown
Contributor Author

Hi @egebeysel, could you rerun the failed CI jobs? The Windows console tracing job stopped before the build because the ccache download was only 430 bytes and unzip couldn’t open it. Thanks!

@egebeysel

Copy link
Copy Markdown
Contributor

Done! Could you maybe add a few more shapes to the mix? Also, damn, why is 540×516×332 quite a bit faster than the mmt4d ukernel 🤔

I'll give this a review soon, sorry for the delay!

@egebeysel

Copy link
Copy Markdown
Contributor

May I ask you to re-run thee benchmarks with #25130? If we do not regress too much, I'll merge that one in real quick.

@Prajit-Rahul

Prajit-Rahul commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks @egebeysel for rerunning CI! I added three shapes and reran all seven on the Banana Pi F3 with and without #25130. I used the benchmark setup described above and matched the compiler thread-count hint to the runtime thread count in both sweeps.

Across all 21 configurations, #25130 increased geometric mean inner_tiled wall time by 0.9%. The largest regressions were on 540×516×332, from 4.10 to 4.69 ms at four threads (+14.4%) and from 2.37 to 2.76 ms at eight threads (+16.5%).

The first two tables report mmt4d mean wall time divided by inner_tiled mean wall time. Values above 1.00× favor inner_tiled.

Baseline (this PR)

Shape (M×N×K) 1 thread 4 threads 8 threads
64×64×64 1.12× 0.98× 1.01×
256×256×256 1.07× 0.99× 0.99×
81×41×19 1.67× 1.18× 1.02×
540×516×332 1.41× 1.61× 1.69×
128×128×128 (new) 1.11× 0.93× 1.06×
512×512×352 (new) 1.08× 1.08× 1.06×
512×16×512 (new) 0.92× 0.89× 0.87×

Candidate (this PR plus #25130)

Shape (M×N×K) 1 thread 4 threads 8 threads
64×64×64 1.12× 1.01× 1.04×
256×256×256 1.07× 1.07× 1.11×
81×41×19 1.67× 1.17× 0.98×
540×516×332 1.44× 1.41× 1.46×
128×128×128 (new) 1.11× 1.02× 1.04×
512×512×352 (new) 1.00× 1.06× 1.06×
512×16×512 (new) 0.99× 0.95× 0.90×

Change in inner_tiled wall time with #25130

Positive values mean slower than the baseline.

Shape (M×N×K) 1 thread 4 threads 8 threads
64×64×64 0.0% +2.8% −5.8%
256×256×256 0.0% −6.4% −5.8%
81×41×19 0.0% +1.8% +8.6%
540×516×332 −1.3% +14.4% +16.5%
128×128×128 0.0% −5.3% +1.8%
512×512×352 +9.1% +1.1% +0.5%
512×16×512 −0.5% −9.5% +2.1%

Eight-thread dispatch profile for 540×516×332

Baseline inner_tiled vs. mmt4d. The main matmul dispatch took 1.65 ms with inner_tiled and 3.31 ms with mmt4d. The savings in that dispatch more than offset the higher input packing time (0.593 vs. 0.310 ms). The inner_tiled dispatch also used less total CPU time (12.9 vs. 19.0 ms) and had a higher CPU/wall ratio (7.82 vs. 5.74). The profile measures the MAC loop and output handling together.

Effect of #25130. The inner_tiled launch went from 1,326 workgroups to 13. Main-dispatch wall time rose from 1.65 to 2.03 ms, while total CPU time stayed near 13 ms and input packing time was nearly unchanged. The mmt4d control stayed at 17 workgroups, with main-dispatch wall time of 3.31 ms before and 3.33 ms after. The drop in the inner_tiled CPU/wall ratio from 7.82 to 6.40 is consistent with lower worker utilization after grouping more tiles per workgroup.

This branch has not been deployed

No deployments
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