Skip to content

HIP: turbo K-cache flash-attention spills 295-720 VGPRs at head size 256 on CDNA/RDNA2/RDNA3 (quality gate had never run) #294

Open

Description

@TheTom

Found while fixing an unrelated HIP compile error in #293. Filing separately because it is much larger than that PR.

Summary

The ubuntu-22-hip-quality-check job has a "Check for major VGPR spills" step that, as far as I can tell, has never run on this fork. The HIP build failed earlier, at a nodiscard compile error in fattn-common.cuh, so the job died before reaching the check. With that compile error fixed in #293, the step runs for the first time and fails.

What it reports

fattn-vec.cuh:44: flash_attn_ext_vec<256, 2, type 47, type 1,  false>  Total VGPRs: 555 (255 + 300)
fattn-vec.cuh:44: flash_attn_ext_vec<256, 2, type 47, type 1,  true >  Total VGPRs: 575 (256 + 319)
fattn-vec.cuh:44: flash_attn_ext_vec<256, 2, type 47, type 43, false>  Total VGPRs: 550 (255 + 295)
fattn-vec.cuh:44: flash_attn_ext_vec<256, 2, type 47, type 43, true >  Total VGPRs: 558 (255 + 303)
fattn-vec.cuh:44: flash_attn_ext_vec<256, 2, type 47, type 44, false>  Total VGPRs: 578 (255 + 323)
fattn-vec.cuh:44: flash_attn_ext_vec<256, 2, type 47, type 44, true >  Total VGPRs: 576 (255 + 321)
fattn-vec.cuh:44: flash_attn_ext_vec<256, 2, type 47, type 47, false>  Total VGPRs: 550 (255 + 295)
fattn-vec.cuh:44: flash_attn_ext_vec<256, 2, type 47, type 47, true >  Total VGPRs: 552 (255 + 297)
fattn-vec.cuh:44: flash_attn_ext_vec<256, 2, type 47, type 8,  false>  Total VGPRs: 586 (256 + 330)
fattn-vec.cuh:44: flash_attn_ext_vec<256, 2, type 47, type 8,  true >  Total VGPRs: 585 (256 + 329)
mmq.cuh:955:      mul_mat_q<type 10, 64, true>                         Total VGPRs: 317 (128 + 189)

Target is gfx908 (CDNA), configured via -DGPU_TARGETS=gfx908 -DGGML_HIP_EXPORT_METRICS=On.

Reading it

The type ids are the fork's own: 47 = TURBO4_0, 44 = TURBO3_0, 43 = TURBO2_0, plus 8 = Q8_0 and 1 = F16. The first template argument of flash_attn_ext_vec is the head size.

Two things stand out:

  1. Every flagged flash-attention instantiation is at head size 256, and every one has TURBO4_0 as the K type.
  2. The numbers are architectural + spilled. These kernels spill 295 to 330 VGPRs, roughly doubling their register footprint.

Spilling on that scale pushes traffic to scratch memory and collapses occupancy. Whatever the turbo FA path costs on CDNA today, this is likely to be a large part of it.

The mul_mat_q<type 10, ...> entry (type 10 = Q2_K) at 189 spilled is a separate, milder case and may well be upstream's rather than the fork's; worth checking against a clean upstream build before attributing it here.

Why it matters beyond performance

The fork has no AMD hardware in the fleet, so HIP has had effectively no coverage. Two independent things now point at the same corner:

Different architectures and spilling is not a correctness bug on its own, so I am not claiming this explains #253. But "turbo FA at hsk=256 is in serious trouble on AMD" has gone from hypothesis to measurement, and it is the same neighborhood #253 has been stuck in for two weeks.

It also raises the value of #279, still open, which adds the first hsk=256 turbo FA test coverage the suite has ever had. Until that lands, every turbo FA case in the suite runs at hsk=128 and this shape is untested everywhere.

Suggested next steps

  1. Decide whether the check should gate CI or warn. If the spilling is longstanding and understood, a threshold or an allowlist is reasonable. If not, it should stay red.
  2. Establish whether this is fork-specific by building upstream at the same target and diffing the metrics. The Q2_K mul_mat_q entry in particular smells upstream.
  3. Look at why flash_attn_ext_vec needs so many registers at 256. Head size 256 doubles the per-thread K/V register working set versus 128, so a tiling or V_rows_per_thread choice tuned for 128 may simply not fit at 256.

I have no AMD hardware, so I can take this no further than the CI metrics. Happy to help anyone who does.

Activity

  1. added
    bug
    on Aug 12, 2026
  2. jasstrong commented on Aug 12, 2026

    @jasstrong

    Ran the same set on gfx1100 (current HEAD, -DGPU_TARGETS=gfx1100 -DGGML_HIP_EXPORT_METRICS=On). Short version: RDNA3 spills these harder than gfx908, not less. Same K=TURBO4_0 instantiations you flagged:

                                        gfx1100 (RDNA3)   gfx908
    <256,2, TURBO4_0, F16,      false>   884 (256+628)   555 (255+300)
    <256,2, TURBO4_0, Q8_0,     false>   907 (256+651)   586 (256+330)
    <256,2, TURBO4_0, TURBO2_0, false>   902 (256+646)   550 (255+295)
    <256,2, TURBO4_0, TURBO3_0, false>   905 (256+649)   578 (255+323)
    <256,2, TURBO4_0, TURBO4_0, false>   901 (256+645)   550 (255+295)
    

    Occupancy 5, ~2.5 KB/lane scratch. So the wave32 register file doesn't rescue it — the pressure is roughly double. (These are the gate-crossing variants; each shape also has a lower-spill instantiation, same as gfx908 — your spill gate just prints the bad ones.)

    One useful narrowing: it's turbo-as-K that blows up, not turbo generally. Swapping roles on the same two types: K=TURBO4_0, V=Q8_0 spills 651, but K=Q8_0, V=TURBO4_0 spills only 36 (zero-spill variant at occ 7). So the target is the turbo K-cache path in fattn-vec — and the common mixed q8_0-K / turbo4-V shape, which is what my head-dim-256 deployment actually runs, is largely unaffected.

    On correctness: #252 is separately fixed on current HEAD — the added dkq256 / q8_0-turbo4 fattn instances that didn't exist at the old pin. My deployed model is exactly that shape (Qwen3.6-35B-A3B, head-dim 256, q8_0-K / turbo4-V cache) and runs clean — coherent generation, no garbling. So the corruption is resolved, and it's a separate axis from this spill.

    Happy to keep poking at these on gfx1100 — hardware's here.

  3. jasstrong commented on Aug 13, 2026

    @jasstrong

    Third AMD-arch datapoint, since I had the hardware: gfx1030 (RDNA2 — a Radeon PRO V620, 32 GB). Same fork, built for gfx1030 with zero source changes; the WMMA/RDNA3 paths are all properly arch-guarded, so it compiles clean on RDNA2. And it runs: my deployed model (Qwen3.6-35B-A3B, head-dim 256, native TQ4 weights) generates coherent output on the V620 at ~17 tok/s decode / ~24 tok/s prompt, all layers on-card. So the turbo path is now exercised on CDNA (gfx908), RDNA2 (gfx1030), and RDNA3 (gfx1100).

    test-backend-ops surfaced three things, in decreasing order of interest:

    1. A real dispatch bug, and not a turbo-specific one: odd-ncols MUL_MAT_ID crashes on AMD without WMMA. On gfx1030 a MUL_MAT_ID with an odd row count falls through to mul_mat_vec_f, which asserts ncols % 2 == 0 (mmvf.cu:421) — hard abort. The dispatch is byte-identical to upstream ggml, so this is a latent upstream bug on the AMD-non-WMMA path, not something turbo introduced; gfx1100 dodges it via its WMMA route. Real MoE models are safe (their expert/routing dims are even — mine are), but the synthetic m=24, k=16384 MUL_MAT_ID test trips it. Since the dispatch is identical to upstream, I wasn't sure whether you'd rather carry a guard in the fork or leave it to upstream ggml — what's your read?
    2. MUL_MAT tq3_1s lands a hair over the precision gate on RDNA2: NMSE 0.000508 vs the 0.0005 threshold (~1.7% over). gfx1100 passes the same shape, so this reads as RDNA2 fp-reduction ordering rather than anything structural — benign for inference (the real model runs clean), but flagging it as an arch difference.
    3. SET_ROWS_TURBO4 reports "not supported" on gfx1030 and falls back to CPU. I haven't yet confirmed whether gfx1100 reports the same (i.e. simply no HIP impl for that op, = expected) or whether it's an RDNA2-specific gap — will check.

    VGPR-spill numbers for gfx1030 to follow: the metrics build is running now, so I'll add an RDNA2 column to the gfx1100/gfx908 table above.

  4. TheTom commented on Aug 13, 2026

    @TheTom
    OwnerAuthor

    Noted on the pronouns, jasstrong, sorry about that. Names only from me going forward.

    This is a lot of ground covered and three of the four points change something on our side.

    The K-vs-V narrowing is the useful part

    K=TURBO4_0, V=Q8_0    spills 651
    K=Q8_0,     V=TURBO4_0  spills  36   (zero-spill variant, occ 7)
    

    That reframes #294 entirely. It is not "turbo flash attention spills", it is the turbo K-cache path in fattn-vec, and the mixed q8_0-K / turbo4-V shape that real deployments use is largely clear. I will retitle the issue to say K-cache rather than turbo generally, because as filed it overstates the blast radius.

    The RDNA3 numbers being roughly double gf908 with occupancy 5 and ~2.5 KB/lane scratch is worth having on the record too. My original filing only had the one architecture and I explicitly could not say whether it generalised.

    #252 being fixed on HEAD

    That is the most valuable thing here and I would not have found it: your deployed shape is exactly q8_0-K / turbo4-V at head-dim 256, it runs clean, and the added instances at current HEAD are what closed it. I will close #252 and #253 on that basis, crediting your run, unless you would rather keep #252 open until the spill work lands. They are separate axes and I do not want to leave a fixed bug open just because a neighbouring one is not.

    That also settles the 2x2 grid from #253 that we never finished. I am going to close #279 as well — its whole purpose was to add hsk=256 turbo FA coverage so this corruption would be reproducible in the suite, and if the underlying bug is fixed on HEAD the coverage argument is weaker than the cost. Happy to be argued out of that if you think the shapes are worth having regardless.

    The odd-ncols MUL_MAT_ID abort, and your question

    My read: both, but not equally.

    Since the dispatch is byte-identical to upstream ggml, the fix belongs upstream and a fork-local divergence in the dispatch itself would be the wrong shape. Please do report it there if you have the appetite; you have the repro and the hardware, and it will land better from you than relayed through me.

    But there is a fork-side piece that is ours regardless, and it is the same complaint as #280: an unsupported combination should report not supported, not abort the process. A hard GGML_ASSERT in mul_mat_vec_f means one synthetic shape takes down the whole test-backend-ops run on RDNA2, so nobody on that hardware can get a complete sweep. That is exactly how the HIP gaps kept hiding. A supports_op rejection for odd ncols on the non-WMMA AMD path costs us nothing on real models, since as you say their dims are even, and it buys back a completable suite.

    So: upstream for the dispatch, and I would take a fork-side supports_op guard purely for testability. If you would rather not carry that, say so and I will not push it.

    The other two

    tq3_1s NMSE 0.000508 against a 0.0005 gate — agreed that reads as RDNA2 reduction ordering, 1.7% over is not a structural failure. Worth leaving visible rather than widening the threshold, since a gate that moves whenever something brushes it stops being a gate.

    SET_ROWS_TURBO4 not supported on gfx1030 — please do check gfx1100. If both report it, it is simply an unimplemented HIP op and expected. If only RDNA2 does, that is a real arch gap. I have no AMD hardware so I genuinely cannot answer this one.

    Thanks for putting three architectures behind this. The fork has had zero AMD coverage in the fleet, which is precisely why the spill gate had never run, and you have now moved CDNA, RDNA2 and RDNA3 from untested to measured in a day.

  5. jasstrong commented on Aug 13, 2026

    @jasstrong

    gfx1030 (RDNA2) spill column, as promised — same K=TURBO4_0 gate-crossing shapes, built with -DGGML_HIP_EXPORT_METRICS=On, VGPRs allocated + spilled:

                                        gfx1100 (RDNA3)   gfx1030 (RDNA2)   gfx908 (CDNA)
    <256,2, TURBO4_0, F16,      false>   884 (256+628)    890 (256+634)     555 (255+300)
    <256,2, TURBO4_0, Q8_0,     false>   907 (256+651)    976 (256+720)     586 (256+330)
    <256,2, TURBO4_0, TURBO2_0, false>   902 (256+646)    929 (256+673)     550 (255+295)
    <256,2, TURBO4_0, TURBO3_0, false>   905 (256+649)    920 (256+664)     578 (255+323)
    <256,2, TURBO4_0, TURBO4_0, false>   901 (256+645)    931 (256+675)     550 (255+295)
    

    So RDNA2 is not better than RDNA3 here — if anything a touch worse. Every turbo-K shape spills a little harder than gfx1100 (with Q8_0-V worst, 720 vs 651), at occupancy 4 vs gfx1100's 5. The wave32 register file doesn't buy anything back; the pressure is ~2.3× gfx908 on both RDNA parts, scratch ~2.5–2.8 KB/lane.

    The turbo-as-K finding holds identically on RDNA2, and it's the reassuring part: swap the roles to my actual deployment shape (K=Q8_0, V=TURBO4_0, hsk=256) and the spill vanishes —

    <256,1, Q8_0, TURBO4_0, false>   143 VGPR, 0 spill, occ 7
    <256,2, Q8_0, TURBO4_0, false>   200 VGPR, 0 spill, occ 4  (272 B scratch)
    

    — which lines up with the model running clean at 17 tok/s on the V620. So the picture across all three AMD arches is consistent: it's specifically the turbo K-cache path at hsk=256 that's in trouble, the common q8_0-K / turbo-V shape is fine everywhere, and RDNA2 patterns with RDNA3 rather than rescuing it.

  6. TheTom commented on Aug 13, 2026

    @TheTom
    OwnerAuthor

    Three architectures, a role-swap narrowing, a fixed bug confirmed, and a latent upstream dispatch bug found. That is a genuinely excellent piece of work, jasstrong, and it moved this from one unexplained data point to something we actually understand.

    The RDNA2 column completes the picture:

                                  gfx1100 (RDNA3)   gfx1030 (RDNA2)   gfx908 (CDNA)
    K=TURBO4_0, V=Q8_0             907 (256+651)     976 (256+720)     586 (256+330)
    K=Q8_0,     V=TURBO4_0         143, 0 spill      200, 0 spill      -
    

    That role swap is the whole finding. It is not turbo flash attention, it is the turbo K-cache path at hsk=256, and it reproduces on all three AMD architectures with RDNA2 slightly worse than RDNA3 rather than better. The common q8_0-K / turbo-V shape that real deployments run is clean everywhere, which is why your V620 does 17 tok/s without complaint.

    I have retitled this issue accordingly. As filed it said "turbo flash-attention kernels", which overstated the blast radius considerably, and anyone reading it would have concluded turbo FA was broadly unusable on AMD. It is not.

    Actions taken

    #283 merged. The evidence there is exactly what I would want for re-enabling something that was disabled on measured grounds: PPL 5.6999 vs 5.7037 with the delta about 30x under the error bar, coherent generation, +33% decode, gated to HIP so CUDA is untouched, and an env escape hatch. I verified on my side that it builds clean on CUDA sm_121 with fatal warnings and that the non-HIP branch is byte-identical to base, so there is no way for it to affect CUDA users.

    #252 and #253 closed. You established that the corruption is fixed on current HEAD by the added dkq256 / q8_0-turbo4 instances, and that your deployed shape runs clean. #253's one-line change is superseded by that, and I would rather close it as fixed than leave your PR hanging against a bug that no longer exists.

    #279 closed. Its only purpose was adding hsk=256 turbo FA coverage so the corruption would be reproducible in the suite. With the underlying bug fixed the coverage argument no longer carries its cost.

    Still open, and yours if you want them

    The odd-ncols MUL_MAT_ID abort is worth reporting upstream, since the dispatch is byte-identical to ggml. I still think a fork-side supports_op rejection is worth carrying purely so the suite can complete on RDNA2, for the same reason as #280, but that is a testability convenience and not a correctness fix, so it is your call whether to bother.

    The SET_ROWS_TURBO4 gfx1100 check would be useful whenever you get to it.

    Thanks for putting real hardware behind this. The fork has had no AMD in the fleet at all, which is exactly why the spill gate had never once run, and you have taken CDNA, RDNA2 and RDNA3 from completely untested to measured inside a day.

  7. changed the title [-]HIP: turbo flash-attention kernels spill 295-330 VGPRs at head size 256 (quality gate had never run)[/-] [+]HIP: turbo K-cache flash-attention spills 295-720 VGPRs at head size 256 on CDNA/RDNA2/RDNA3 (quality gate had never run)[/+] on Aug 13, 2026
  8. seanrasch commented on Aug 14, 2026

    @seanrasch

    Ampere (SM 86) data: the fix removes the spill, but costs 12-31% turbo2 decode

    First NVIDIA numbers on this issue, since the three columns so far are all AMD. Short version: on
    Ampere the spill is much worse than any arch measured so far and PR #295 drives it to zero — but
    on the shapes that decode actually launches there was no spill to remove, and the split costs
    turbo2 up to 31%. I think the gate wants to be ncols-based rather than D-based.

    Setup

    RTX 3080 Ti (SM 86, driver 580.173.02, nvcc 12.0), -DGGML_CUDA_FA_ALL_QUANTS=ON,
    -DCMAKE_CUDA_ARCHITECTURES=86, -Xptxas=-v.

    • A = fca3093c9 unpatched
    • B = fca3093c9 + a70a324fa cherry-picked

    Model: Qwen3.5-9B Q4_K_M — attention.key_length = attention.value_length = 256, GQA 16/4,
    full_attention_interval = 4. This is the shape the issue is about, and it is what I run in
    production with --cache-type-k turbo2.

    Method note, because it nearly cost me the result: cross-session run-to-run drift on this box is
    ~7%
    (re-running A alone moved turbo2 81.01 → 86.84 t/s). Everything below is therefore
    clock-locked at 1500 MHz and interleaved A,B,B,A inside a single session, 5 reps. Repeats agree
    within 0.3 t/s.

    Registers and spill, D=256, turbo-as-K

    shape (ncols, K, V) A regs A spill B regs B spill
    1, turbo2, turbo2 117 0 113 0
    1, turbo3, turbo3 144 0 142 0
    1, turbo4, f16 255 264 200 0
    1, turbo4, turbo2 255 396 161 0
    1, turbo4, turbo3 255 460 187 0
    2, turbo2, turbo2 255 4,276 255 0
    2, turbo2, q8_0 255 4,408 192 0
    2, turbo4, q8_0 255 4,416 192 0

    Two things stand out against the AMD columns:

    1. Ampere spills roughly 6-14x harder at ncols=2 — ~4,300 bytes here versus the 295-720 VGPRs
      jasstrong measured. The fix zeroes all of it. It does what it says.
    2. At ncols=1, turbo2 and turbo3 never spilled at all — 117 and 144 registers, zero bytes. Only
      turbo4-K spills at ncols=1.

    Decode throughput, tg128, interleaved

    config depth A B Δ
    turbo2 / turbo2 8192 102.45 / 102.35 89.45 / 89.50 −12.6%
    turbo2 / turbo2 32768 84.12 / 84.07 58.18 / 57.92 −31.1%
    turbo3 / turbo3 32768 76.28 / 76.34 76.32 / 76.36 0.0%
    q8_0-K / turbo2-V 32768 87.87 / 87.85 87.87 / 87.88 0.0%
    f16 / f16 32768 96.84 / 96.90 96.87 / 96.86 0.0%

    Prefill is unaffected throughout. Correctness is fine — greedy, seed 42, A and B generations are
    byte-identical. B is slower, not wrong.

    Why: the LUT paths assume nthreads_KQ == 1

    The shared-memory LUT fast paths for turbo3 (fattn-vec.cuh L320) and turbo2 (L340) compute the full
    D-length dot per lane with no nthreads_KQ striding, and neither calls warp_reduce_sum — only
    the else at L358 does. They structurally require nthreads_KQ == 1.

    Raising nthreads_KQ to 128/cpy_nb makes the i_KQ_0 loop run that many times with several lanes
    masked onto the same i_KQ, so each lane recomputes the whole dot redundantly. Every lane still ends
    up with the correct full sum, which is exactly why the output stays byte-identical while throughput
    drops.

    The PR message anticipated this branch and set it aside — "the shared-memory LUT branch that assumes
    a single lane is gated on ncols==1, which no spilling shape uses."
    That is true on AMD. On Ampere the
    ncols == 1 shapes are precisely the ones that never spill, and they are what decode runs.

    Which kernels actually launch (nsys)

    This is the part that explains the turbo3 row, which otherwise looks inconsistent:

    cache type kernel launched at decode
    turbo2 flash_attn_ext_vec<256, 1, TURBO2_0, TURBO2_0>
    turbo3 flash_attn_ext_f16<256, 256, 2, 4, …, TURBO3_0, TURBO3_0> + flash_attn_stream_k_fixup

    turbo3 decode never enters fattn-vec.cuh on this shape — it goes down the MMA path. So turbo3
    being flat is expected rather than surprising, and its identical-looking LUT branch is simply not
    executed here. B launches the same kernel and the same call count as A for turbo2, so the regression
    is inside the kernel rather than a dispatch change.

    I could not get any ncols=2 VEC instance to launch. Single-stream decode, and
    llama-batched-bench at -npl 1,2,4, all launch ncols=1 only. So on this model the ~4,300-byte
    spill is on instances that do not appear to run in decode, while the cost lands on the one that does.
    Caveat: I have not tested speculative decoding / MTP, which I would expect to be the other source
    of ncols > 1, and I have not tested other head dims or architectures.

    One more thing the D > 128 gate leaves behind

    At ncols=2, turbo-as-K also spills at head_dim 128 — 548-680 bytes — and those numbers are
    identical in A and B, because D > 128 excludes them:

    shape (ncols, K, V) A spill B spill
    2, turbo2, turbo2 672 672
    2, turbo2, f16 680 680
    2, turbo3, turbo3 676 676

    To be precise, since it would be easy to overstate: this is ncols=2 only — D=128 at ncols=1 is
    clean at 0 bytes. But if the goal is "no turbo-K shape spills", the D=128 ncols=2 cases are still
    spilling after the patch.

    Suggestion

    The discriminator that matches the measurements is whether the shape actually spills, which
    tracks ncols and the K type, not D:

    constexpr int nthreads_KQ = K_is_turbo
        ? ((ncols > 1 || type_K == GGML_TYPE_TURBO4_0) ? 128 / cpy_nb : 1)
        : (K_is_unquantized ? 128 / cpy_nb : nthreads_KQ_q);

    That keeps the real win — every ncols=2 shape, at both head dims, plus turbo4-K at ncols=1, which is
    the one ncols=1 shape that genuinely spills — while leaving the zero-spill turbo2/turbo3 ncols=1
    decode path alone. On the AMD data this should be equivalent to the current patch, since the spilling
    shapes there are the ncols=2 ones.

    Happy to re-run any of this, or test a revised gate on SM 86.

  9. apollo-mg commented on Aug 14, 2026

    @apollo-mg

    I have gfx1201 (RX 9070 XT, RDNA4), so here is the target the CI has never built.

    Build-only, same knob you used: fca3093c9 (current feature/turboquant-kv-cache),
    -DGPU_TARGETS=gfx1201 -DGGML_HIP_EXPORT_METRICS=On, ROCm 7.2.53211. No benchmark, no
    runtime, just the resource-usage remarks. 7034 kernels analysed, 346 of them
    flash_attn_ext_vec, 98 spilling.

    RDNA4 reproduces it, and in three ways the gfx908 picture doesn't show.

    1. It is not confined to head size 256

    You wrote "Every flagged flash-attention instantiation is at head size 256." On gfx1201,
    spilling FA kernels by head size:

    head size spilling
    256 55
    128 40
    64 3

    hsk=128 is the shape the suite already tests, and the shape most models actually run. If
    that also holds on gfx908 once #293 lands, the "untested shape" framing understates it —
    the tested shape is affected too.

    2. Not only TURBO4_0 as the K type

    You wrote "every one has TURBO4_0 as the K type." K-type distribution across the 98
    spillers here:

    TURBO4_0  41
    TURBO3_0  21
    TURBO2_0  21
    Q8_0       7
    Q4_0       4
    F16        2
    

    TURBO4_0 does lead. But all three turbo K types spill, and the single worst kernel in the
    build has TURBO2_0 as K:

    hsk K V mask VGPR spill scratch B/lane occ
    256 TURBO2_0 F16 0 256 735 2608 5
    256 TURBO2_0 F16 1 256 708 2496 5
    256 TURBO4_0 Q8_0 0 256 704 2556 5
    256 TURBO2_0 TURBO2_0 0 256 698 2624 5
    256 TURBO3_0 TURBO2_0 1 256 696 2688 5

    All ten worst are pinned at the 256-VGPR architectural cap with occupancy 5 waves/SIMD,
    pushing 2.5-2.75 KB per lane to scratch. Worst spill is 735 against your 330, roughly
    2.2x.

    11 of the 98 involve no turbo type at all, so there is a residue here that isn't
    attributable to this fork's types.

    3. On the Q2_K mul_mat_q entry — your instinct looks right

    You flagged mul_mat_q<type 10, 64, true> at 189 spilled and said it "smells upstream."
    On gfx1201 it is both worse and clearly the dominant pattern:

    mul_mat_q<type 10, 80, 0>   VGPR=256  spill=865  scratch=2688   <- worst in the whole build
    mul_mat_q<type 10, 64, 0>   VGPR=256  spill=384  scratch=1196
    mul_mat_q<type 10, 64, 1>   VGPR=256  spill=365  scratch=1104   <- your 189 case
    mul_mat_q<type 10, 32, 1>   VGPR=256  spill=70   scratch=284
    

    Type 10 is Q2_K, a stock ggml type, and it occupies six of the top ten mul_mat_q
    spillers. Plenty of other stock types spill mildly too (Q8_0, Q4_0, IQ2/IQ3/IQ4, MXFP4),
    all in the 3-33 range. That is consistent with an upstream issue rather than a fork one,
    though I have not built clean upstream at gfx1201 to confirm — happy to do that next if
    it's useful, it's the same one-command build.

    Limits

    One reproduction note that cost me an hour: the turbo type IDs move between commits. I
    first read ggml.h from an older checkout where TURBO4_0=44, and mislabelled every type.
    At fca3093c9 it's TURBO2_0=43, TURBO3_0=44, TQ3_1S=45, TQ4_1S=46, TURBO4_0=47. Your
    mapping in the issue is correct — mine was briefly wrong. Worth stating explicitly if the
    check ever becomes a gate, since a threshold allowlist keyed on type ID would silently rot.

    Raw log available if you want it. Happy to rerun once #293 merges so it's like-for-like.

  10. jasstrong commented on Aug 15, 2026

    @jasstrong

    Extending @apollo-mg's head-size sweep to RDNA2, RDNA3, and the RDNA3 APU (V620/gfx1030, 7900 XTX/gfx1100, and a Phoenix2 iGPU/gfx1103). Same base fca3093c, -DGPU_TARGETS=<arch> -DGGML_HIP_EXPORT_METRICS=On, build-only, all 347 flash_attn_ext_vec instances.

    @apollo-mg is right, and it holds across the whole RDNA line — hsk=128 spills too:

    head size gfx1030 (RDNA2) gfx1100 (RDNA3) gfx1103 (RDNA3 APU) gfx1201 (RDNA4, @apollo-mg)
    256 46 56 51 55
    128 40 41 42 40
    64 3 3 3 3
    total spilling 89/347 100/347 96/347 98/346

    My earlier "every flagged instantiation is at head size 256" was an artifact of only tabulating the gate-crossing hsk=256 turbo-K shapes. The broad sweep shows hsk=128 spills ~40 kernels on every RDNA generation (40/41/42/40) — the tested, common shape, not a corner the suite skips.

    Still overwhelmingly the turbo K-cache path (RDNA2: 83 of 89 spillers are K=TURBO{2,3,4}_0; K=F16 spills 5), so the q8_0-K / turbo-V deployment shape stays clean at every head size. Worth noting the Phoenix APU is the worst case — occ 4 (vs the discrete gfx1100's occ 5) and the highest peak spill of any arch tested (786 VGPRs at hsk=256), because the iGPU's register file is tighter.

    Design note: #295 gates its split on D>128, so it wouldn't cover the ~40 hsk=128 spillers — consistent with @seanrasch's argument that the gate wants to be ncols-based rather than D-based.

  11. jasstrong commented on Aug 15, 2026

    @jasstrong

    @seanrasch your ncols-based-gate call looks right from where we're sitting — the sweep above shows a D>128 gate would both over-apply the split and skip the ~40 hsk=128 spillers per arch, so D can't be the whole story.

    Whatever gate @TheTom lands on, we're glad to run it through the House of Radeons™ — gfx1030 (V620, RDNA2), gfx1100 (7900 XTX, RDNA3), and gfx1103 (Phoenix2 APU, RDNA3). The metrics trees are already stood up, so we can turn both halves around quickly: the -Rpass resource sweep (does the revised gate actually zero the spills at both 128 and 256?) and a real on-hardware decode benchmark (does it dodge the 12–31% turbo2 hit you measured on the launched shapes?). Just point us at a branch.

  12. added 2 commits that reference this issue on Aug 17, 2026
  13. TheTom commented on Aug 17, 2026

    @TheTom
    OwnerAuthor

    Scope correction on my own f050a2501 write-up above, before any RDNA4 data lands and makes it look like a regression appeared.

    I wrote "All 15 <128,2,turbo-K,*> shapes went from 173-421 VGPR spill to zero." That was measured on gfx1030, gfx1100 and gfx1103, which is what @jasstrong had swept at the time, and I wrote it as though it held for the RDNA line generally. gfx1201 was never in that table and I should have said so instead of letting "zero" stand unqualified.

    @apollo-mg, you have the only gfx1201 in this thread, and you were the one who showed the original D>128 gate had the head sizes wrong in the first place. If you have re-run the resource sweep against f6124e914, please post it here. Two things I want and cannot get from this desk:

    1. Residual feat: CUDA port of TurboQuant3 KV cache — 3.47x compression, 98.5% of F16 decode speed on RTX 5090 #3, the gfx1100-only <128,1,K=TURBO2,V=TURBO3> at 36 VGPR. I said that if that pattern turned out to be common, the fix is teaching the LUT paths to stride and reduce so they work at any nthreads_KQ. That is a big change and I would rather not sign anyone up for it on the strength of one instance on one arch. Whether it appears on gfx1201 is what decides it.
    2. Whether <128,2,turbo-K,*> actually reaches zero on gfx1201 or only gets close. ncols=2 is a shape decode really launches, so a residual there sits on a live path, unlike the D=256 one which is a V-side accumulator spill on a shape nothing launches.

    Separately, for whoever gets to a runtime bench first: after @seanrasch's Ampere numbers I do not trust build-only resource metrics to tell us whether a small residual costs anything real. A turbo2/turbo3 decode run against f6124e914 on any RDNA part would settle whether a 20-60 VGPR residual is worth chasing or worth leaving alone. My guess is leave it alone, but guesses are how the first gate got written wrong.

  14. apollo-mg commented on Aug 18, 2026

    @apollo-mg

    gfx1201 resource sweep against f6124e914, plus the runtime run you asked for.

    Provenance first: the resource sweep was built at f050a2501, not the merge. The only delta between them touching flash attention is in fattn-common.cuh — (void) casts to silence [[nodiscard]] on cudaStreamSynchronize/cudaFree inside a destructor. No functional change, no register-allocation impact (the other file, ggml-cuda.cu, is the host-side RDNA2 stream-capture fix). So the spill numbers below apply to f6124e914. The runtime bench builds f6124e914 directly.

    RX 9070 XT, ROCm 7.2.4, -DGGML_HIP=ON -DGPU_TARGETS=gfx1201 -DGGML_HIP_EXPORT_METRICS=On, matched to my 2026-08-14 baseline run. Parser reproduces that baseline's published headline figures exactly, so the delta is like-for-like.

    Resource sweep

    baseline fca3093c9 f6124e914 delta
    flash_attn_ext_vec kernels 348 348 —
    FA kernels spilling 98 41 −57
    worst FA VGPR spill 735 357 −378

    By head size: 256 → 55/33, 128 → 40/8, 64 → 3/0. 57 fixed, 0 newly spilling.

    Your two questions

    1. Residual #3 — the gfx1100-only <128,1,K=TURBO2,V=TURBO3> at 36 VGPR.

    Zero instances on gfx1201. It does not occur here at all. On the evidence I have that reads as architecture-specific rather than a common pattern, which argues against signing anyone up for teaching the LUT paths to stride and reduce.

    2. Does <128,2,turbo-K,*> reach zero on gfx1201?

    No — it gets close and survives. Matches the scope correction you just posted:

    shape before after
    <128,2,TURBO3,TURBO3> 243 / 244 57 / 54
    <128,2,TURBO2,TURBO3> 271 / 272 37 / 36
    <128,2,TURBO4,TURBO3> 246 37 / 36
    <128,2,TURBO3,Q8_0> 424 / 424 23 / 23

    Two things you may not have

    Bucket #1 is not "identical under both gates" here. Present, 18 kernels, but they fell 698 → 57, 681 → 57, 661 → 36. On gfx1030/1100/1103 they were already ≤22/62/23 before the fix; on gfx1201 they started at 625–735 and the gate cut them ~90%.

    A fourth bucket. 19 of the 41 survivors are Q8_0-K pairs at D=256, ncols=2: Q8_0/TURBO2 (61, 60), Q8_0/F16 (40, 40), Q8_0/BF16 (32), Q8_0/TURBO4 (28, 25), plus BF16/BF16 (13) and F16/F16 (1). All byte-unchanged before→after. Same structural story as your Q4_0 residual — a non-turbo K path the gate doesn't reach — at a different type.

    Bucket #2 confirmed as pre-existing: 4 kernels, byte-unchanged (357→357, 336→336, 226→226, 206→206).

    Scale context, since gfx1201 wasn't in the original sweep:

    arch spilling before→after worst before→after
    gfx1030 40 → 3 294 → 23
    gfx1100 42 → 10 421 → 37
    gfx1103 40 → 2 298 → 25
    gfx1201 98 → 41 735 → 357

    Largest absolute win of the four, from a starting point ~2.5× worse, and still carrying 4–20× the residual count of the others.

    Runtime

    llama-bench, pure decode (-p 0 -n 128), -fa 1, TURBO_AUTO_ASYMMETRIC=0. Llama-3.2-3B-BF16 (D=128, GQA 3:1) so the <128,2> shapes are live and the auto-asymmetric gate can't fire. Two independent passes:

    KV pass 1 (5 reps) pass 2 (12 reps)
    f16 (control) −1.2 % −1.1 %
    turbo2 +0.4 % −0.3 %
    turbo3 +0.8 % −0.9 %
    turbo4 +1.0 % +1.0 %

    Null result at ±1 %. The two passes disagree in sign on turbo2 and turbo3, and this box shows intermittent 1–2 % (occasionally 6 %) variance between identical runs — some cells came back at ±1.7 even at 12 reps. I'm not claiming an improvement; I'm claiming there's no cost I can detect.

    So: the 23–57 VGPR residual doesn't buy back measurable decode throughput on RDNA4. Your instinct to leave it alone holds up.

    On the 12–31 % turbo2 ncols=1 regression — it does not reproduce here. turbo2 was +0.4 % / −0.3 %. That one I'd treat as a real absence rather than a resolution limit, since 12–31 % is an order of magnitude above this machine's noise floor.

    Caveats

    Decode only — no prefill, no long context, no batch >1. Throughput only, no fidelity gate. One card. And ncols=2 arises through GQA packing rather than being pinned by a flag, so a shape-pinned microbenchmark would be stronger evidence than this.

    D=256 was also measured; I'm not quoting deltas there because the 12-rep pass moved all four cells positive including the f16 control the fix doesn't touch, which reads as a machine-state offset between the two builds' runs rather than an effect of the commit.

    Happy to re-run anything, pin specific shapes, or test other configs — it's the only gfx1201 here and it's free.

  15. TheTom commented on Aug 18, 2026

    @TheTom
    OwnerAuthor

    @apollo-mg this is the most careful piece of measurement anyone has put on this issue, thank you. Two things in particular: running the f16 control that the fix does not touch, and then refusing to quote the D=256 deltas once that control moved. That is the part most people skip, and it is the only reason I believe the rest of the table.

    Residual #3 is closed. Zero instances on gfx1201 settles it. It is a gfx1100 artifact, not a property of the LUT path, so nobody is teaching the LUT paths to stride and reduce. That was the expensive branch of this issue and it is now off the table on evidence rather than on my guess.

    I got bucket #1 wrong, and in the opposite direction this time. I called it "identical under both gates, a V-side accumulator spill, a different mechanism." That was true on gfx1030/1100/1103 where it sat at 22/62/23 before and after. On gfx1201 it starts at 625-735 and the gate cuts it about 90 percent, to 36-57. So it is not a different mechanism, or at least not only that. My characterisation was arch-scoped twice over and I stated it as general twice. I will stop generalising from three RDNA parts.

    The fourth bucket is a real finding and it lines up with something CI just told us. Your 19 Q8_0-K pairs at D=256 ncols=2 are the same structural story as the Q4_0 residual, a non-turbo K path the gate cannot reach. Independently, the ubuntu-22-hip-quality-check job on gfx942 flags flash_attn_ext_vec<128,2,TURBO3,Q8_0> at 259 VGPR, which is 255 plus a 4 VGPR spill. Same shape class you measured at 424 to 23 on gfx1201. So that class is small-but-nonzero on both CDNA and RDNA4, and it is the surviving turbo shape on both.

    On the runtime null. Agreed, and it matches what I expected but had no right to assert. Your point that the 12-31 percent turbo2 ncols=1 regression is a real absence rather than a resolution limit is the useful half, since 12-31 percent is well clear of your noise floor. That reads as SM 86 specific rather than general, which is worth @seanrasch knowing.

    Where this leaves the gate. ubuntu-22-hip-quality-check is still red, but as of #302 it is no longer red for the nodiscard reason, that is fixed and the count is 19 to 0. What it flags now is rwkv_wkv_f32 at 387, mul_mat_q at 317, and the two <128,2,TURBO3,Q8_0> instances at 259. The first two are not turbo kernels at all.

    Given your runtime result, I do not think chasing a 4 VGPR spill that provably costs nothing is a good use of anyone's time. The check script already carries an ignore list, rwkv_wkv7_f32 and gated_linear_attn_f32 are on it. I would rather add the surviving shapes with a comment pointing at your numbers, so the gate goes green and starts catching regressions again, than leave it permanently red where it catches nothing. Any objection before I do that? You have the only measurements that would justify the entry.

  16. jasstrong commented on Aug 18, 2026

    @jasstrong

    House of Radeons runtime cross-check — extending @apollo-mg's RDNA4 method to RDNA2, RDNA3, and the RDNA3 APU.

    Same llama-bench recipe Mark used: pure decode -p 0 -n 128 -fa 1, TURBO_AUTO_ASYMMETRIC=0, KV sweep f16/turbo2/turbo3/turbo4. One difference in framing: rather than baseline-vs-fix, we compared the D-gate (a70a324f) directly against the LUT-gate (f050a2501) on the same card — so this pins the exact gate that produced seanrasch's over-split. f16 is the control the fix never touches; its delta is the per-box noise floor.

    D=128 — Llama-3.2-3B-BF16 (Mark's model), decode t/s, D-gate → LUT-gate

    KV gfx1030 (V620) gfx1100 (7900 XTX) gfx1103 (Phoenix2 iGPU)
    f16 (control) 59.25 → 59.13 (−0.2%) 106.93 → 106.98 (+0.0%) 4.99 → 5.01 (+0.5%)
    turbo2 57.71 → 57.69 (−0.0%) 101.49 → 101.60 (+0.1%) 5.01 → 5.02 (+0.2%)
    turbo3 57.84 → 57.80 (−0.1%) 101.48 → 101.71 (+0.2%) 5.01 → 5.01 (+0.0%)
    turbo4 56.78 → 57.57 (+1.4%) 99.67 → 101.07 (+1.4%) 4.99 → 5.01 (+0.4%)

    D=256 — qwen3.6-35B-A3B (seanrasch's exact ncols=1 launched shape), decode t/s

    At D=256, the D-gate splits the ncols=1 launched shape and the LUT gate keeps it unsplit — the precise thing seanrasch measured at 12–31% on SM 86.

    KV gfx1100 (7900 XTX) gfx1030 (V620)
    f16 (control) 13.56 → 13.51 (−0.4%) 19.02 → 18.97 (−0.2%)
    turbo2 13.37 → 13.40 (+0.2%) 18.73 → 18.86 (+0.7%)
    turbo3 13.25 → 13.29 (+0.3%) 18.57 → 18.81 (+1.3%)
    turbo4 13.34 → 13.36 (+0.2%) 18.81 → 18.83 (+0.1%)

    Verdict

    No regression on any RDNA part, at either head size. Every turbo2 delta lands between −0.0% and +0.7%, an order of magnitude below the 12–31% seanrasch measured — which does not reproduce on RDNA2, RDNA3, or the RDNA3 APU, matching Mark's read that it's SM 86-specific. The D=256 run puts the ncols=1 launched shape directly under test and still finds nothing.

    Where deltas do creep above the f16 control's noise floor they go the other way — toward the LUT gate: turbo4 at D=128 on both discrete parts (+1.4%), and turbo2/turbo3 on the V620 at D=256 (+0.7% / +1.3%). Small, and if anything a marginal recovery in the direction seanrasch's cost would live — never a penalty. Consistent with the LUT gate being strictly the better shape choice.

    Supports adding the surviving turbo shapes to the ignore list — three more arches showing the residual spill buys back nothing at runtime.

    Notes: the iGPU couldn't hold the 35B (17.6 GB > its 15.4 GB GTT pool), so D=256 is the two discrete cards; it's RDNA3, already covered by the 7900 XTX at D=256 and by itself at D=128. TQ4max wouldn't load in the metrics-tree llama-bench (unsupported quant) so both cards used TQ3_1S/TQ4opt weights — the turbo-K decode kernel is identical regardless of weight quant.

  17. apollo-mg commented on Aug 18, 2026

    @apollo-mg

    No objection to the ignore entry. @jasstrong's four-arch run is stronger evidence for it than mine, for two reasons I want to state plainly before adding anything.

    First, their comparison axis is better for this question. They ran D-gate a70a324f → LUT-gate f050a2501, which isolates the gate. I ran fca3093c9 → f6124e914, which bundles everything between the pre-fix baseline and the merge. For "did the gate cost anything", theirs is the cleaner instrument.

    Second, their noise floor is better. Their f16 controls move 0.0–0.5%; mine moved 1.1–1.2% and two of my D=256 cells came back at ~6%. Where we agree, weight theirs.

    Two things I can add that their run wouldn't have surfaced.

    Direct dispatch evidence for the ncols question, at D=128

    You wrote that ncols=2 is a shape decode really launches, and that this is what makes a residual there matter. jasstrong's D=256 run establishes ncols=1 as the launched shape there. I can check D=128 — where the shapes in question actually live — from the dispatch side.

    No rocprof on this box, but AMD_LOG_LEVEL=4 prints every dispatch's ShaderName with template arguments intact. Build f6124e914, -fa 1, TURBO_AUTO_ASYMMETRIC=0, types per the fork's ggml.h (8=Q8_0 43=TURBO2 44=TURBO3 47=TURBO4):

    config kernel launched count
    D=128, GQA 3:1, decode flash_attn_ext_vec<128, 1, TURBO3, Q8_0> 84
    D=256, GQA 4:1, decode flash_attn_ext_vec<256, 1, TURBO3, Q8_0> 40
    D=256, GQA 6:1, decode flash_attn_ext_vec<256, 1, TURBO3, Q8_0> 80
    D=128, decode at depth 4096 flash_attn_ext_vec<128, 1, TURBO3, Q8_0> 112
    D=128, turbo3 symmetric flash_attn_ext_vec<128, 1, TURBO3, TURBO3> 84

    Every one is ncols=1. Three GQA ratios, two head dims, and the packing factor never moves the VEC ncols. Depth changes the launch count (84 → 112) and not the shape, which is the control behaving.

    So ncols=1 is the launched shape at D=128 as well as D=256 — jasstrong's result from the gate side, mine from the dispatch side, covering both head sizes. On gfx1201, ordinary decode never reaches <128,2,…>.

    That supports the ignore entry rather than complicating it: the shapes being exempted are less live than the premise assumed. What I can't tell you is what does launch ncols=2 — speculation and multi-sequence batching are the obvious candidates and llama-bench produces neither. Happy to run the census on any config you name.

    llama-bench can't prefill with quantized KV on gfx1201

    Found while trying to add a prefill regime so the runtime evidence wasn't decode-only. Same build, llama-bench vs llama-server:

    path config result
    llama-bench -p 256 -n 0, any quantized KV ROCm error → abort, ggml-cuda.cu:109
    llama-server ~2000-token prompt, turbo3/q8_0 fine, coherent output

    The threshold is exact and sits on your HIP VEC/TILE boundary in ggml_cuda_get_best_fattn_kernel:

    -p 8 ok
    -p 9 abort
    -p 256 -ub 16 abort
    -p 256 -ub 8 -b 8 ok, 331.6 t/s

    turbo3/q8_0, turbo3/turbo3, q8_0/q8_0, turbo4/q8_0, turbo2/q8_0 all abort; only f16/f16 prefills (1639 t/s). Pre-existing — fca3093c9 does the same, so #295 neither caused nor fixed it.

    Scope, to be exact: benchmark path only. My first read was "prefill with quantized KV aborts on RDNA4" and that is wrong — serving is fine at every prompt length I tried. -ub 8 -b 8 works around it.

    Worth flagging because it's a second llama-bench gap on this work, alongside jasstrong's note that TQ4max wouldn't load in the metrics-tree build. Between them, the standard measurement tool can't do prefill with quantized KV on RDNA4 and can't load some turbo weight quants — which may be part of why RDNA runtime evidence has been thin.

    On the entry itself

    Two suggestions about keeping the gate useful, not about whether to add it.

    A threshold rather than a blanket shape ignore. If <128,2,TURBO3,Q8_0> is listed outright, a later change taking it from 4 VGPR to 200 keeps the gate green. Since the goal is to start catching regressions again, "flag above N" preserves that on the shape most likely to move, and still goes green today at 259.

    rwkv_wkv_f32 at 387 and mul_mat_q at 317 aren't covered by any of this. They're larger than the turbo residuals and, as you say, not turbo kernels. Neither my data nor jasstrong's speaks to them. If "the surviving shapes" means all four, the gate goes green over two unexplained spills — I'd keep those separate.

    One scope note on gfx942: everything above is RDNA. The ubuntu-22-hip-quality-check flag is CDNA, and none of us has that hardware. You just said you'd stop generalising from three RDNA parts — with jasstrong's run it's now four, but they're still all RDNA.

    Standing offer

    gfx1201 and a pair of P100s here, both idle most of the time — RDNA4 and pre-Turing CUDA. Any sweep, census, or config you want, say the word.

  18. TheTom commented on Sep 3, 2026

    @TheTom
    OwnerAuthor

    Data point from PR triage on 2026-09-03: hip-quality-check has failed on every PR since 2026-08-23, and a manual dispatch on feature/turboquant-kv-cache at 80be9a7 fails the same way, so it is red on the base branch, not the PRs: https://github.com/TheTom/llama-cpp-turboquant/actions/runs/33712051649

    The -Werror build step passes. The failure is the VGPR step (scripts/hip/gcn-cdna-vgpr-check.py), currently flagging:

    • fattn-vec.cuh:44 flash_attn_ext_vec<128,2,turbo3,q8_0,*> at 259 VGPRs (255 + 4)
    • mmq.cuh:955 mul_mat_q<type 10, 64, true> at 317 (128 + 189)
    • wkv.cu:5 rwkv_wkv_f32<128> at 387 (64 + 323)

    Until this is fixed, the check is noise for every PR that touches a .cu/.cuh. Real CUDA/HIP signal is the hosted cuda, hip, musa build jobs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions