Archived
attn prefill h256 gqa6: split the KV walk when the launch has too few workgroups
The prefill attention kernel gives each workgroup 64 query rows of one KV head and walks the whole causal context serially. A launch with few query rows therefore has few workgroups: the tail chunk of a prompt (53 rows) or a follow-up turn of a few hundred tokens runs 2-10 workgroups on 32 WGPs, each walking up to 188k keys (17.7 ms per layer at 188k). When kv_heads * qtiles * seqs is below the WGP count, the launch now splits the KV range into S segments (blockIdx.x = qtile * S + segment), writes unnormalised f32 partials (O, m, l) in the decode partial layout and merges them with the existing split-KV combine. S is the smaller of one or two rounds of workgroups, capped by the context's tiles and the declared scratch. A segment past a workgroup's causal end still writes an empty partial; the merge reads every segment it counts. The merges take a SPAN parameter so a launch over part of a step (pipelined pieces) only rewrites its own rows; the decode instances are unchanged (identical ISA). R4D_PREFILL_SPLITS: unset/0 = the law, 1 = off, N = force N (debug/tuning). Measured on 2x Radeon AI PRO R9700, Qwen3.8-27B MXFP4, TP 2, k6_v4 KV: - r4d_selftest --perfpaged, off -> on: 53 rows over 40k 3.71 -> 0.47 ms, 80 rows 3.64 -> 0.68 ms, 345 rows 3.80 -> 1.79 ms, 1024 rows 4.29 -> 4.29 ms (no split). - Engine, 188k prompt, time to first token: 62.78 -> 62.54 s (the tail chunk). - KLD vs the bf16 reference: chunk 64 0.040384 -> 0.040337, chunk 2048 0.040237 -> 0.040220; top-1 agreement 93.985 -> 93.998 %. Split vs unsplit outputs differ by at most 1 bf16 ulp. - With R4D_PREFILL_SPLITS=1 the engine is bit-identical to before (top-5 logprobs, 100 positions). Tests: attn_split_case / attn_split_scratch_case for k6_v4, fp8_v4, fp8 and bf16 KV (q 1-345 over 8k-20k keys, empty segments, ragged batches, pipelined pieces), scratch poisoned; 410/410 ok. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
64c652f01e
commit
6a7824a837
6 files changed
+553
-16
No files matched your search
@@ -121,6 +121,11 @@ int r4d_rad_attn_decode_h256_bf16 (const RadArgs*, RadStream);
|
||||
int r4d_rad_attn_decode_h128_fp8 (const RadArgs*, RadStream);
|
||||
int r4d_rad_attn_decode_h128_bf16 (const RadArgs*, RadStream);
|
||||
int64_t r4d_rad_attn_decode_h256_scratch(const RadArgs*);
|
||||
/* The prefill rows' KV-split partials (r4d_attn_paged_h256_gqa6.hip, prefill_scratch), by cache
|
||||
* row: fp8 and bf16, fp8_v4, k6_v4. */
|
||||
int64_t r4d_rad_attn_prefill_h256_scratch(const RadArgs*);
|
||||
int64_t r4d_rad_attn_prefill_h256_v4_scratch(const RadArgs*);
|
||||
int64_t r4d_rad_attn_prefill_h256_k6_scratch(const RadArgs*);
|
||||
int64_t r4d_rad_attn_decode_h128_scratch(const RadArgs*);
|
||||
/* Gemma 4 dense sliding window (r4d_attn_paged_h256_gqa2.hip): head_dim 256, 2 queries per KV
|
||||
* head. Both bands: decode (q_len*gqa <= 64, verify width 32 against the gqa6 leg's 10) and
|
||||
|
||||
Reference in new issue
Block a user