Change sets 4-5: chunked SSD Mamba-2 prefill + stream-k tuning for CDNA2 (+23.5% pp16384) - #1
Merged
Merged
Conversation
…for CDNA2 Two prefill optimisations for gfx90a, measured on Nemotron-3-Super-120B-A12B (i1-Q4_K_M) across 2x MI210. Combined: pp16384 1775 -> 2192 t/s (+23.5%). 4. Chunked SSD Mamba-2 prefill (+19%). Upstream PR #22675 replaced the sequential SSM scan with a State-Space-Duality formulation that turns the scan into batched FP16 GEMMs, but gated it to NVIDIA Turing+ as a scoping decision. On gfx90a the scan it replaces was the single largest prefill kernel at 22.8% of GPU time, scalar FP32 with no matrix-core use. Admitting HIP to the guards and adding CDNA to the capability test drops it to 1.0% and puts the work on the 181 TFLOPS v_mfma_f32_16x16x16f16 path. The kernels compiled for HIP with no changes to the GEMM calls; every cuBLAS symbol already had a hipBLAS alias. 5. Disable stream-k for K-quants (+3.7%). Every CASE entry in mmq-config-cdna.cuh sets stream_k = true, inherited across all CDNA generations. Upstream PR #26199 found stream-k hurts MoE models when retuning RDNA; MMQ is 53.3% of prefill here after change set 4. Both verified with test-backend-ops (SSM_SCAN 7/7, MUL_MAT_ID 790/790) and by reading generated tokens at temperature 0, not by throughput alone. Also documents a pre-existing multi-GPU fault: the second sequential llama-server request faults on node-1 across two cards. The unpatched baseline faults identically and a single card is clean, so it is unrelated to these changes; recorded because it is easy to misattribute. Change sets 4-5 are generated against upstream ggml-org/llama.cpp 67b9b0e, a different base from change sets 1-3; README says so explicitly. Patches verified to apply cleanly to that base and to reproduce the modified-files copies byte-for-byte.
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.
Two prefill optimisations for gfx90a, measured on Nemotron-3-Super-120B-A12B (
i1-Q4_K_M, 80 GiB) across 2× MI210.Result
llama-bench,-b 4096 -ub 2048 -fa 1 -sm layer -ctk q8_0 -ctv q8_0 -t 24 -r 267b9b0eGap to vLLM+AITER (4,070 t/s at 16k) narrows from 2.29× to 1.86×. Not closed.
4. Chunked SSD Mamba-2 prefill (+19%)
Upstream PR #22675 replaced the sequential SSM scan with a State-Space-Duality formulation — per-chunk intra-chunk output and chunk-final state become batched FP16 GEMMs — then gated it to NVIDIA Turing+. The author states it "does not affect ... HIP": a scoping decision, not a technical limit.
On gfx90a that scan was the single largest prefill kernel:
rocprofv3putssm_scan_f32_groupat 22.8% of GPU time (1759 ms / 7703 ms), scalar FP32, zero matrix-core use. Admitting HIP to the guards and adding CDNA to the capability test drops it to 1.0% and moves the work onto the 181 TFLOPSv_mfma_f32_16x16x16f16path.It compiled for HIP with no changes to the GEMM calls — every cuBLAS symbol already had a hipBLAS alias in
vendors/hip.h. Gated to CDNA, not blanket AMD; RDNA's WMMA path is unvalidated.USE_CUBleft HIP-excluded (hipCUB collides with ggml's__trapmacro).5. Disable stream-k for K-quants (+3.7%)
Every
CASEinmmq-config-cdna.cuhsetsstream_k = true, inherited across all CDNA generations. PR #26199 found stream-k "helps a lot for Dense models and hurts MoE models" when retuning RDNA. This is MoE, and MMQ is 53.3% of prefill after change set 4.Stated plainly: that evidence is RDNA3.5/RDNA4, not CDNA2. This was an experiment that paid off, not a transferred result — an earlier experiment on similar reasoning (extending CDNA3's rocBLAS carve-out to CDNA2) came back 6.5% slower and was discarded.
Verification
test-backend-ops -o SSM_SCAN7/7 per device, including the 256/512/300-token multi-chunk shapes that exercise the SSD path.test-backend-ops -o MUL_MAT_ID790/790 per device.temperature 0on a 240-token prompt. The SSD path chains batched GEMMs withbeta=1accumulation; a wrong stride doesn't crash, it yields fluent wrong text — so throughput alone is not evidence.git apply --checkagainst67b9b0e, reproducing themodified-files/copies byte-for-byte.Pre-existing multi-GPU fault (documented, not introduced)
The second sequential
llama-serverrequest faults onGPU node-1across two cards. Bisected:67b9b0eThe unpatched baseline faults identically, so it is unrelated to these changes.
llama-benchnever surfaces it, pointing at state reuse between requests rather than a prefill kernel — throughput numbers unaffected. Not root-caused.Note on base
Change sets 4-5 are against upstream
ggml-org/llama.cpp67b9b0e, a different base from change sets 1-3 (TurboQuantc26cbdf). They have not been tested on the TurboQuant fork andssm-scan.cuchanged substantially upstream in the interim, sopatches/04-*will likely need rebasing to apply there. The two groups touch disjoint files.Branch
ssd-cdna2on this repo carries the same work as a full llama.cpp tree with real history, if that is easier to build from.