perf(tensilelite): wave-parallel group search in grouped GEMM kernels #14788
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #14788"
general
weight: 0.35
yzhang93
JIRA ID : AIHPBLAS-1828
Motivation
A grouped GEMM kernel computes many independent matrix products, or groups, in one launch; a mixture-of-experts (MoE) layer, for example, runs one group per expert. Each workgroup, the block of GPU threads that computes one output tile, first finds the group its tile belongs to. TensileLite's grouped kernels do this with a scalar loop that loads one group's sizes, waits for the load and adds that group's tile count, so a workgroup pays one dependent memory round trip (about 0.4 µs on MI355X) for every group before its own.
The launch grid is sized for the worst case, and the workgroups past the last real tile scan every group before they exit. With the 384 groups of a DeepSeek V4 MoE layer, kernel time follows the group count instead of the work: on MI355X, the 5120 x 576 down projection for one token takes 2,313 µs over 384 groups, against 15 µs when the empty groups are removed.
Technical Details
The kernel change is limited to the grouped-kernel code that
KernelWriterAssembly.defineAndResourcesemits before theFOUNDlabel. Non-grouped kernels are unchanged.1. Wave-parallel search (
groupedGemmWaveSearch):- Each of the wave's 64 lanes loads the (M, N, batch, K) header of one group with
global_load_dwordx4, so one round trip covers 64 groups, and computes that group's tile count: ceil(M / MacroTile0) x ceil(N / MacroTile1) x batch, times GSU when GlobalSplitU is on.- The wave gives each lane the running total of tiles through its group (an inclusive prefix sum): a DPP
row_shrscan by 1, 2, 4 and 8 lanes within each 16-lane row, plus the row totals read withv_readlane. Av_cmpagainst the workgroup id and a find-first-set pick the first group whose running total exceeds the id.- Each round trip loads up to 6 chunks of 64 groups (384 groups); with 64 groups or fewer it issues one load.
groupedGemmWaveSearchChunkspicks the largest chunk count whose VGPRs, 4 per chunk plus 5 scratch, fit as one block in the VGPRs the kernel can use without lowering its occupancy (getMaxRegsForOccupancy, which accounts for LDS). A kernel where not even one chunk fits keeps the loop.- Lanes past the last group load group 0, which keeps the load in bounds, and count 0 tiles. Workgroups past the last tile resolve to the last group, as before.
- At
FOUND, the search leaves the same registers as the loop: the group's sizes, its tile count, the running tile total through the group and the group index + 1. The code afterFOUNDis unchanged.- A launch with one group skips the search and takes the existing scalar single-group path; the vector load and scan cost single-group launches up to 6.5%.
2. Where it applies (
groupedGemmWaveSearchSupported): gfx942 and gfx950 kernels with 64-thread waves, power-of-twoMacroTile0andMacroTile1, and no per-group GSU code in the loop (MultipleBufferSingleKernel and AdaptiveGemmGSUA). All other kernels keep the loop, including gfx908, gfx90a and gfx1250.3. Grouped heuristic host time (
a866d6b4b78): the grouped C API asks for at least 8 candidates. When the libraries return fewer,rocblaslt_algo_get_heuristic_cppchecks every solution of the same types fromgetAllSolutions(GEMM_TYPE_ONLY), grouped or not (19,987 with the full gfx950 library).isSolutionSupportedsized the grouped workspace, which builds kernel arguments for every group, before rejecting them: about 40 s per heuristic call at 1000 groups. It now rejects solutions that are not grouped or not for this hardware first. Selection is unchanged.Test Plan
On MI355X (gfx950), with only the grouped logic files in the build (
TENSILELITE_LOGIC_FILTER=_GG_) unless noted:GroupedMatmul.and allroupedtests):-
smoke_Fp16TN65Groups: uneven shapes with empty groups (M = 0 or N = 0) and K = 0.-
smoke_Fp16TN400Groups: one heuristic call and launch setup for four calls: 400 equal groups (one workgroup per tile, so no surplus workgroup can cover a missed tile), uneven groups, then only the first and only the last group non-empty. Alpha and beta are per group.-
pre_checkin_Fp16TN1000Groups: the same with 1000 groups, in the standard tier.-
smoke_MXFP8TNPreSwizzled385Groups: MXFP8 in the MoE layout; gfx950 only.- Group 0 is non-empty in these tests, every grouped test checks that D's ld padding is not written, and the workspace starts filled with ones so a record read past the last group faults.
- The same tests with develop's grouped kernels.
a866d6b4b78.Tests/common/groupedgemm), with full validation:grouped_gemm.yaml,grouped_gemm_userargs.yaml,grouped_gemm_many_groups.yaml(400 gemms, MT128x128, GSU 1 and 2) andgrouped_gemm_many_groups_userargs.yaml(GSU 1; GSU 2 with user arguments fails to launch on develop too).- group index off by one after the first chunk;
- each further load starting 64 groups early;
- row cutover off by one;
- tile total not carried between chunks;
- past-the-end path resolving to one group beyond the last;
- out-of-range lanes keeping group 0's tile count.
Tests/unit/test_grouped_gemm_wave_search_chunks.py, against the gfx942 and gfx950 caps, and five broken versions ofgroupedGemmWaveSearchChunks.hipblasLtMatmulwith grouped layouts on the MXFP8, MXFP4 and FP16 grouped kernels, for 12 group patterns from 1 to 1000 groups, compared with per-grouptorch.matmul; also used for the benchmark.Tests/unit, markerunit).Test Result
GroupedMatmul, 21 run and pass, and 8 skip on gfx950 for lack of grouped kernels (FP16 NN and TT, BF16, MX without pre-swizzled scales, and the MX-and-FP8 selection test). All otherroupedtests pass exceptAlgoErrors.smoke_RowOrderIsRefusedBesideAGroupedLayout, which needs a non-grouped kernel the grouped-only build lacks; it passes with the full library. Before the rebase, the tests also passed with develop's grouped kernels.pre_checkin_Fp16TN1000Groups43.6 s to 1.6 s,smoke_Fp16TN400Groups18.1 s to 0.67 s, allrouped*tests 170 s to 22 s with the same results.smoke_Fp16TN400Groups; the two past-the-end builds fault in every many-group test. A broken GSU multiply is caught bygrouped_gemm_many_groups.yamlwith GSU 2.- gfx950: all 14 kernels take the search (4 to 6 chunks per load). The MXFP8 and MXFP4 MT64x64 kernels keep 82 to 87 VGPRs; the FP16 MT16x16 kernels grow from 43-47 to 53 VGPRs, which their LDS use already limits to 6 waves per SIMD.
- gfx942: 7,241 kernels take the search (7,034 with 6 chunks per load); their VGPR count grows by 0 to 35, and by an estimate from VGPRs, LDS and workgroup size none runs fewer waves per SIMD. The FP16 TN grouped kernel the heuristic returns first (the only GridBased solution, MT16x16x32) takes the search with 6 chunks per load at 53 VGPRs.
- SGPR counts and every kernel that keeps the loop are unchanged; the gfx1250 grouped code objects are byte-identical to develop's.
| case | gate_up develop | gate_up PR | down develop | down PR |
| --- | --- | --- | --- | --- |
| 1 token, 384 groups | 579 | 43.3 | 2,313 | 129 |
| 1 token, 6 groups | 22.2 | 21.4 | 15.2 | 13.9 |
| 16 tokens, 384 groups | 616 | 123 | 2,075 | 198 |
| 16 tokens, 96 groups | 110 | 99.2 | 129 | 87.1 |
| 256 tokens, 384 groups | 853 | 453 | 1,438 | 453 |
| 4096 tokens, 384 groups | 1,426 | 687 | 3,117 | 753 |
| 1 group of 64 tokens, 383 empty | 577 | 36.9 | 2,318 | 126 |
| 384 groups of 64 tokens | 895 | 592 | 1,357 | 542 |
| 1 group of 24,576 tokens | 280 | 277 | 316 | 311 |
With few groups (median of 7 runs of 200 iterations), the change is within ±1% for one group and 2.6% to 2.7% faster for 6 groups:
| case | gate_up develop | gate_up PR | down develop | down PR |
| --- | --- | --- | --- | --- |
| 1 group of 64 tokens | 16.1 | 16.2 | 10.7 | 10.5 |
| 1 group of 24,576 tokens | 270 | 270 | 301 | 304 |
| 1 token, 6 groups | 21.0 | 20.4 | 10.7 | 10.4 |
| 16 tokens, 96 groups | 108 | 97.4 | 121 | 80.3 |
test_arch_steppings.py,test_custom_kernel_staggeru_metadata.pyand the GPU tile-assignment tests, which fail the same way on develop in my container.Submission Checklist
Risk level
Medium (3/5): the change rewrites the group search of the grouped kernels with power-of-two tiles on gfx942 and gfx950. A wrong group pick computes a tile with another group's sizes and pointers: that group's tile is written twice and the intended tile is never written, and no error is reported. The gtests and configs catch such picks, as the six broken builds show. On gfx942 the search has run only in CI and in a reviewer's runs. The heuristic fix only rejects, earlier, solutions that were already rejected.