attn prefill h256: the small-launch KV split for every GQA geometry

The KV split of the head-256 / GQA-6 prefill kernel (few workgroups -> split the KV walk into segments,
f32 partials, the split-KV merge with a cu span) now serves every head-256 prefill row: GQA 12
(4-token pages: fp8, bf16, fp8_v4, k6_v4), GQA 6 with 4-token pages (the same four), GQA 8, GQA 4 and
GQA 2 (fp8, bf16). The fewer KV heads a rank holds, the more it matters: at TP 2 Qwen4-Exp (GQA 12) and
Qwen3.5-35B-A3B (GQA 8) keep one KV head per rank, so a 53-row tail runs 2 workgroups on 32 WGPs.

The host side (the law, the scratch sweep, the scratch-capped count, R4D_PREFILL_SPLITS, the merge
launch) moves into r4d_attn_prefill_split.h; each unit passes its own geometry (query rows per workgroup
= 24 * 16 / gqa, tile 48). The GQA-6 unit is refactored onto it with the same law (Qwen3.8-27B in the
engine: greedy top-5 logprobs bit-identical before and after at 300 positions after 25k and 41k prompts).

Left unsplit: GQA-2 launches with a sliding window (the partition has no window floor; a 1024 window
walks at most ~26 tiles), the lossy e4m3 legs, and the head-128 / head-64 legs sharing the bodies.

Split count, one sequence, N query rows -> S: GQA 12 with 1 KV head: 1-32 -> 32, 53 -> 16, 160 -> 6,
1024 -> 1; GQA 8 with 1 KV head: 53 -> 16, 345 -> 4; GQA 2 with 4 KV heads: up to 160 -> 8. Scratch at
declare at most 25.4 MB per row. Split vs unsplit: at most 0.000488 (fp8 KV) and 0.0039 (bf16, fp8_v4,
k6_v4; about 1 bf16 ulp).

Tests: the split tests generalised over geometry for all 18 split rows (query lengths 1-640 over 8k-20k
keys, empty segments, ragged batches, pipelined pieces, poisoned scratch, oracle rows at each tile edge,
declare-time scratch): 1782 ok; the mixed-step case over 9 geometry x cache pairs: 54 ok. Every kernel
that existed before is byte-identical (311 of 311).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
mici81andClaude Opus 5.5 committed 2026-10-26 09:25:35 +01:00
1 parent 22df1c7264
commit 96bc0465b3
8 files changed
+433 -226

No files matched your search

+28 -14
View File
@@ -6425,7 +6425,8 @@ static const RadKernelInfo kKernels[] = {
"bf16 query, fp8-e4m3 kv cache with per-(seq,head) descales, bf16 out",
RAD_DOMAIN_DEVICE, R4D_PRIO_ATTN_PREFILL,
ROW(cAttnPrefillH256Gqa2Fp8), NOTUNE,
nullptr, nullptr, r4d_rad_attn_prefill_h256_gqa2_fp8, nullptr, nullptr, nullptr,
nullptr, nullptr, r4d_rad_attn_prefill_h256_gqa2_fp8, r4d_rad_attn_prefill_h256_gqa2_scratch,
nullptr, nullptr,
r4d_shape_attn_paged },
{ "attn_prefill_h256_gqa2_bf16kv", "attn_paged", "attn",
@@ -6435,7 +6436,8 @@ static const RadKernelInfo kKernels[] = {
"bf16 query, bf16 kv cache, bf16 out",
RAD_DOMAIN_DEVICE, R4D_PRIO_ATTN_PREFILL,
ROW(cAttnPrefillH256Gqa2Bf16), NOTUNE,
nullptr, nullptr, r4d_rad_attn_prefill_h256_gqa2_bf16, nullptr, nullptr, nullptr,
nullptr, nullptr, r4d_rad_attn_prefill_h256_gqa2_bf16, r4d_rad_attn_prefill_h256_gqa2_scratch,
nullptr, nullptr,
r4d_shape_attn_paged },
{ "attn_decode_h256_gqa2_fp8kv", "attn_paged", "attn",
@@ -6590,7 +6592,8 @@ static const RadKernelInfo kKernels[] = {
"bf16 query, fp8-e4m3 kv cache with per-(seq,head) descales, bf16 out",
RAD_DOMAIN_DEVICE, R4D_PRIO_ATTN_PREFILL,
ROW(cAttnPrefillH256G8Fp8), NOTUNE,
nullptr, nullptr, r4d_rad_attn_prefill_h256_gqa8_fp8, nullptr, nullptr, nullptr,
nullptr, nullptr, r4d_rad_attn_prefill_h256_gqa8_fp8, r4d_rad_attn_prefill_h256_gqa8_scratch,
nullptr, nullptr,
r4d_shape_attn_paged },
{ "attn_prefill_h256_gqa8_bf16kv", "attn_paged", "attn",
@@ -6599,7 +6602,8 @@ static const RadKernelInfo kKernels[] = {
"bf16 query, bf16 kv cache, bf16 out",
RAD_DOMAIN_DEVICE, R4D_PRIO_ATTN_PREFILL,
ROW(cAttnPrefillH256G8Bf16), NOTUNE,
nullptr, nullptr, r4d_rad_attn_prefill_h256_gqa8_bf16, nullptr, nullptr, nullptr,
nullptr, nullptr, r4d_rad_attn_prefill_h256_gqa8_bf16, r4d_rad_attn_prefill_h256_gqa8_scratch,
nullptr, nullptr,
r4d_shape_attn_paged },
{ "attn_decode_h256_gqa8_fp8kv", "attn_paged", "attn",
@@ -6628,7 +6632,8 @@ static const RadKernelInfo kKernels[] = {
"bf16 query, fp8-e4m3 kv cache with per-(seq,head) descales, bf16 out",
RAD_DOMAIN_DEVICE, R4D_PRIO_ATTN_PREFILL,
ROW(cAttnPrefillH256G4Fp8), NOTUNE,
nullptr, nullptr, r4d_rad_attn_prefill_h256_gqa4_fp8, nullptr, nullptr, nullptr,
nullptr, nullptr, r4d_rad_attn_prefill_h256_gqa4_fp8, r4d_rad_attn_prefill_h256_gqa4_scratch,
nullptr, nullptr,
r4d_shape_attn_paged },
{ "attn_prefill_h256_gqa4_bf16kv", "attn_paged", "attn",
@@ -6637,7 +6642,8 @@ static const RadKernelInfo kKernels[] = {
"bf16 query, bf16 kv cache, bf16 out",
RAD_DOMAIN_DEVICE, R4D_PRIO_ATTN_PREFILL,
ROW(cAttnPrefillH256G4Bf16), NOTUNE,
nullptr, nullptr, r4d_rad_attn_prefill_h256_gqa4_bf16, nullptr, nullptr, nullptr,
nullptr, nullptr, r4d_rad_attn_prefill_h256_gqa4_bf16, r4d_rad_attn_prefill_h256_gqa4_scratch,
nullptr, nullptr,
r4d_shape_attn_paged },
{ "attn_decode_h256_gqa4_fp8kv", "attn_paged", "attn",
@@ -6716,7 +6722,8 @@ R4D_WIN_PAIR(512, 1) R4D_WIN_PAIR(512, 2) R4D_WIN_PAIR(512, 4) R4D_WIN_PAIR(512,
"bf16 query, fp8-e4m3 kv cache with per-(seq,head) descales, bf16 out",
RAD_DOMAIN_DEVICE, R4D_PRIO_ATTN_PREFILL,
ROW(cAttnPrefillH256G12Fp8), NOTUNE,
nullptr, nullptr, r4d_rad_attn_prefill_h256_gqa12_fp8, nullptr, nullptr, nullptr,
nullptr, nullptr, r4d_rad_attn_prefill_h256_gqa12_fp8, r4d_rad_attn_prefill_h256_gqa12_scratch,
nullptr, nullptr,
r4d_shape_attn_paged },
{ "attn_prefill_h256_gqa12_bf16kv", "attn_paged", "attn",
@@ -6725,7 +6732,8 @@ R4D_WIN_PAIR(512, 1) R4D_WIN_PAIR(512, 2) R4D_WIN_PAIR(512, 4) R4D_WIN_PAIR(512,
"bf16 query, bf16 kv cache, bf16 out",
RAD_DOMAIN_DEVICE, R4D_PRIO_ATTN_PREFILL,
ROW(cAttnPrefillH256G12Bf16), NOTUNE,
nullptr, nullptr, r4d_rad_attn_prefill_h256_gqa12_bf16, nullptr, nullptr, nullptr,
nullptr, nullptr, r4d_rad_attn_prefill_h256_gqa12_bf16, r4d_rad_attn_prefill_h256_gqa12_scratch,
nullptr, nullptr,
r4d_shape_attn_paged },
{ "attn_decode_h256_gqa12_fp8kv", "attn_paged", "attn",
@@ -6782,7 +6790,8 @@ R4D_WIN_PAIR(512, 1) R4D_WIN_PAIR(512, 2) R4D_WIN_PAIR(512, 4) R4D_WIN_PAIR(512,
"bf16 query, fp8-e4m3 kv cache with per-(seq,head) descales, bf16 out",
RAD_DOMAIN_DEVICE, R4D_PRIO_ATTN_PREFILL,
ROW(cAttnPrefillH256G6Bs4Fp8), NOTUNE,
nullptr, nullptr, r4d_rad_attn_prefill_h256_gqa6_fp8, nullptr, nullptr, nullptr,
nullptr, nullptr, r4d_rad_attn_prefill_h256_gqa6_fp8, r4d_rad_attn_prefill_h256_gqa6_scratch,
nullptr, nullptr,
r4d_shape_attn_paged },
{ "attn_prefill_h256_gqa6_bs4_bf16kv", "attn_paged", "attn",
@@ -6791,7 +6800,8 @@ R4D_WIN_PAIR(512, 1) R4D_WIN_PAIR(512, 2) R4D_WIN_PAIR(512, 4) R4D_WIN_PAIR(512,
"bf16 query, bf16 kv cache, bf16 out",
RAD_DOMAIN_DEVICE, R4D_PRIO_ATTN_PREFILL,
ROW(cAttnPrefillH256G6Bs4Bf16), NOTUNE,
nullptr, nullptr, r4d_rad_attn_prefill_h256_gqa6_bf16, nullptr, nullptr, nullptr,
nullptr, nullptr, r4d_rad_attn_prefill_h256_gqa6_bf16, r4d_rad_attn_prefill_h256_gqa6_scratch,
nullptr, nullptr,
r4d_shape_attn_paged },
{ "attn_decode_h256_gqa6_bs4_fp8kv", "attn_paged", "attn",
@@ -6846,7 +6856,8 @@ R4D_WIN_PAIR(512, 1) R4D_WIN_PAIR(512, 2) R4D_WIN_PAIR(512, 4) R4D_WIN_PAIR(512,
"bf16 query, fp8_v4 kv cache (E4M3 K, int4 V in groups of 32 with f16 scales), bf16 out",
RAD_DOMAIN_DEVICE, R4D_PRIO_ATTN_PREFILL,
ROW(cAttnPrefillH256G12Fp8v4), NOTUNE,
nullptr, nullptr, r4d_rad_attn_prefill_h256_gqa12_fp8v4, nullptr, nullptr, nullptr,
nullptr, nullptr, r4d_rad_attn_prefill_h256_gqa12_fp8v4, r4d_rad_attn_prefill_h256_gqa12_fp8v4_scratch,
nullptr, nullptr,
nullptr },
{ "attn_decode_h256_gqa12_fp8v4", "attn_paged", "attn",
@@ -6876,7 +6887,8 @@ R4D_WIN_PAIR(512, 1) R4D_WIN_PAIR(512, 2) R4D_WIN_PAIR(512, 4) R4D_WIN_PAIR(512,
"bf16 query, k6_v4 kv cache (int6 K, int4 V, each in groups of 32 with f16 scales), bf16 out",
RAD_DOMAIN_DEVICE, R4D_PRIO_ATTN_PREFILL,
ROW(cAttnPrefillH256G12K6v4), NOTUNE,
nullptr, nullptr, r4d_rad_attn_prefill_h256_gqa12_k6v4, nullptr, nullptr, nullptr,
nullptr, nullptr, r4d_rad_attn_prefill_h256_gqa12_k6v4, r4d_rad_attn_prefill_h256_gqa12_k6v4_scratch,
nullptr, nullptr,
nullptr },
{ "attn_decode_h256_gqa12_k6v4", "attn_paged", "attn",
@@ -6906,7 +6918,8 @@ R4D_WIN_PAIR(512, 1) R4D_WIN_PAIR(512, 2) R4D_WIN_PAIR(512, 4) R4D_WIN_PAIR(512,
"bf16 query, fp8_v4 kv cache (E4M3 K, int4 V in groups of 32 with f16 scales), bf16 out",
RAD_DOMAIN_DEVICE, R4D_PRIO_ATTN_PREFILL,
ROW(cAttnPrefillH256G6Bs4Fp8v4), NOTUNE,
nullptr, nullptr, r4d_rad_attn_prefill_h256_gqa6_fp8v4, nullptr, nullptr, nullptr,
nullptr, nullptr, r4d_rad_attn_prefill_h256_gqa6_fp8v4, r4d_rad_attn_prefill_h256_gqa6_fp8v4_scratch,
nullptr, nullptr,
nullptr },
{ "attn_decode_h256_gqa6_bs4_fp8v4", "attn_paged", "attn",
@@ -6936,7 +6949,8 @@ R4D_WIN_PAIR(512, 1) R4D_WIN_PAIR(512, 2) R4D_WIN_PAIR(512, 4) R4D_WIN_PAIR(512,
"bf16 query, k6_v4 kv cache (int6 K, int4 V, each in groups of 32 with f16 scales), bf16 out",
RAD_DOMAIN_DEVICE, R4D_PRIO_ATTN_PREFILL,
ROW(cAttnPrefillH256G6Bs4K6v4), NOTUNE,
nullptr, nullptr, r4d_rad_attn_prefill_h256_gqa6_k6v4, nullptr, nullptr, nullptr,
nullptr, nullptr, r4d_rad_attn_prefill_h256_gqa6_k6v4, r4d_rad_attn_prefill_h256_gqa6_k6v4_scratch,
nullptr, nullptr,
nullptr },
{ "attn_decode_h256_gqa6_bs4_k6v4", "attn_paged", "attn",