Repository navigation
[Engine] AMD: faster decode GEMV for grouped Q8_0 and controllers - #307
Open
okada-shogo wants to merge 7 commits into
Open
okada-shogo wants to merge 7 commits into
okada-shogo wants to merge 7 commits into
Conversation
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>
…variants did not gain)
…arams; add_test, 8-matrix case, keep pending errors
Registered as a rollback of the virtual-warp GEMV kernels. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: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
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 samewarp_sum. There is no shared memory and no barrier. The dot product is an explicitfma(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.__HIPCC__ && !STRATA_HIP_GFX906; at run time a gfx11xx or gfx12xx device andSTRATA_GEMV_VWARPnot set to "0". CUDA, other HIP architectures and the gfx906 build run the old kernels.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-vwarpagainst simplex/main 36e654b.Passed:
STRATA_GEMV_VWARPis registered as a rollback.python3 tools/settings_register.py --checkandtools/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.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.poly_gemv_vwarp_test --bench, cold weights, 2 runs): grouped Q8_0 40.4 -> 39.2 µs, ctrl_down 13.9 -> 12.2 µs./work/hv/res/on the test container.Decode tok/s for each run, RX 9070 XT:
Failed:
Not run:
Limits
Credit: the E3 benchmark harness and kernel variants (this project's optimization plan); the explicit
d*sumiform comes from the same measurements.🤖 Generated with Claude Code