Skip to content

[Engine] AMD: faster decode GEMV for grouped Q8_0 and controllers - #307

Open
okada-shogo wants to merge 7 commits into
simplexai-labs:mainfrom
okada-shogo:port/hip-gemv-vwarp
Open

okada-shogo wants to merge 7 commits into
simplexai-labs:mainfrom
okada-shogo:port/hip-gemv-vwarp

Conversation

@okada-shogo

@okada-shogo okada-shogo commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Problem and result

On RDNA3/RDNA4, two Inkling 2 Mini decode kernels are slower than they need to be: the grouped dense Q8_0 launch (q|k|v|gate|rel|sink, 48 a token) and ink_ctrl_down (the loop controllers' down product, 48 a token). This PR adds variants of both that give the same bits and run one wave per row with no shared memory and no barrier. On an RX 9070 XT they are faster per launch:

Kernel (cold weights, µs a launch, lower is better, same machine) main this PR
grouped Q8_0 q|k|v|gate|rel|sink 40.4 39.2 (+3%)
ctrl_down F32, 3 controllers 13.9 12.2 (+14%)

That saves about 0.2 ms a token (~1%). End-to-end decode tok/s stays inside the run-to-run noise (see Validation). Outputs are bit for bit the same.

Related discussion

none. This follows our own HIP kernel measurements (experiment E3 in our optimization plan). That plan also measured variants of the expert products. On the machine used here the existing expert kernels already run at about 550 GB/s and the variants did not gain, so they are not in this PR.

Approach

  • Grouped Q8_0 launch (native_mmvq_many, type 8, n_in 2304) uses "virtual warps": one wave does the work of the block kernel's four warps in turn, keeps a separate sum for each, adds them in the block's warp order and then does the same warp_sum. There is no shared memory and no barrier. The dot product is an explicit fma(d0*d1, sumi, sum), the same single fma that the block kernel's += apply() compiles to.
  • ink_ctrl_down (even rank) computes two outputs per block, which share one norm. It still uses shared memory and two __syncthreads; the gain comes from the shared norm and from streaming the second row.
  • Gate: at compile time __HIPCC__ && !STRATA_HIP_GFX906; at run time a gfx11xx or gfx12xx device and STRATA_GEMV_VWARP not set to "0". CUDA, other HIP architectures and the gfx906 build run the old kernels.
  • Changes visible to CUDA: two declarations (native_gemv_vwarp_active/force) with stubs that return false or do nothing, gfx_arch_is_rdna34(), and the new test executable (built in CUDA configurations too; add_test, SKIP_RETURN_CODE 77).

Validation

Hardware: a Salad cloud container with an RX 9070 XT (gfx1201), ROCm 7.2.4. Branch port/hip-gemv-vwarp against simplex/main 36e654b.

Passed:

  • Settings register: STRATA_GEMV_VWARP is registered as a rollback. python3 tools/settings_register.py --check and tools/test_settings_register.py: OK at this commit. No engine code changed in this commit.
  • poly_gemv_vwarp_test: 23 cases, every output byte-identical to the old kernels. Grouped Q8_0: the real 6-matrix shape, an 8-matrix shape with the k_dyn / v_dyn rows, odd row counts, and other formats untouched. ctrl_down: F32 and BF16, 1-3 controllers, 1 and 3 tokens, rank 62 (new kernel); rank 63 falls back to the old kernel and matches.
  • Frozen identity (STRATA_GPU_EXPERTS=2335 STRATA_FREEZE_EXPERTS=1), CUDA/HIP graphs on, 400 greedy tokens (302+64, 8192+64, 302+256), main and branch twice each, on the final code: the md5 of the token ids is identical in all 4 runs per model. IQ4_NL cd117965bd39, UD-Q2_K_XL fb865758d2de. This compares token ids only, not logits.
  • Kernel benchmark (poly_gemv_vwarp_test --bench, cold weights, 2 runs): grouped Q8_0 40.4 -> 39.2 µs, ctrl_down 13.9 -> 12.2 µs.
  • End-to-end decode speed, warm, default placement, 3 rotated rounds (table below). This ran on the previous revision of this branch, which had the same two kernels; the Q8_0 product differed only in how the fma is written. The expected ~1% cannot be resolved at this noise.
  • CUDA: strata-poly and poly_gemv_vwarp_test build (remote build on a Bazzite PC, CUDA 12.9, sm_75). On a machine with no GPU the test exits 77 (skipped).
  • Logs: /work/hv/res/ on the test container.

Decode tok/s for each run, RX 9070 XT:

Model After prompt Build Run 1 Run 2 Run 3
IQ4_NL 302 main 50.9 49.9 51.2
IQ4_NL 302 this PR 52.2 51.6 51.3
IQ4_NL 8K main 45.3 45.3 45.0
IQ4_NL 8K this PR 45.3 44.8 45.5
UD-Q2_K_XL 302 main 60.3 60.6 60.2
UD-Q2_K_XL 302 this PR 60.6 60.4 60.3
UD-Q2_K_XL 8K main 57.6 57.0 57.1
UD-Q2_K_XL 8K this PR 57.4 57.1 57.0

Failed:

  • none observed

Not run:

  • gfx11 (RDNA3) hardware.
  • Identity with graphs off.
  • Logits / KL comparison.
  • The test on a CUDA card (it needs the remote job queue).

Limits

  • The gain is about 1% a token at most and is not visible in tok/s here.
  • Only gfx1201 was measured.
  • The E3 numbers for the expert kernels came from another host and did not reproduce here.

Credit: the E3 benchmark harness and kernel variants (this project's optimization plan); the explicit d*sumi form comes from the same measurements.

🤖 Generated with Claude Code

okada-shogo and others added 6 commits November 24, 2026 14:56
Class: same bits. A wave does the block kernel's four warps in turn (no LDS, no barrier,
1-2 rows a wave) for Inkling 2 Mini's IQ4_NL / Q8_0 expert products, the grouped dense
Q8_0 launch and the loop controllers' down product, on gfx11xx/gfx12xx only. The dot is
written as an explicit d*sumi accumulate. CUDA and other HIP archs unchanged.
STRATA_GEMV_VWARP=0 turns it off. Test: poly_gemv_vwarp_test (byte compare).

Credit: measured and designed from E3 (rx9070xt-e123.md); idea of the wave layout from
VecSzn's engine and merbanan/cobra91/Tako88's lanes work.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…arams; add_test, 8-matrix case, keep pending errors
@okada-shogo okada-shogo changed the title [Engine] HIP: no-LDS virtual-warp GEMVs for Inkling's grouped Q8_0 launch and the loop controllers' down product (gfx11/gfx12, same bits) [Engine] AMD RDNA3/RDNA4: faster decode GEMV for grouped Q8_0 and the loop controllers Nov 24, 2026
@okada-shogo okada-shogo changed the title [Engine] AMD RDNA3/RDNA4: faster decode GEMV for grouped Q8_0 and the loop controllers [Engine] AMD RDNA3/RDNA4: faster decode GEMV for the grouped Q8_0 launch and the loop controllers (same bits, about 1% a token) Nov 24, 2026
@okada-shogo okada-shogo changed the title [Engine] AMD RDNA3/RDNA4: faster decode GEMV for the grouped Q8_0 launch and the loop controllers (same bits, about 1% a token) [Engine] AMD RDNA3/4: faster decode GEMV for grouped Q8_0 and loop controllers Nov 24, 2026
@okada-shogo okada-shogo changed the title [Engine] AMD RDNA3/4: faster decode GEMV for grouped Q8_0 and loop controllers [Engine] AMD: faster decode GEMV for grouped Q8_0 and controllers Nov 24, 2026
Registered as a rollback of the virtual-warp GEMV kernels.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.

1 participant