Skip to content

strix-hip: 27B prefill attention: K/V via registers, V as f16 once, all-thread softmax (bit-identical, +3% at 12.5k) - #259

Merged
AzeezIsh merged 2 commits into
mainfrom
perf/hip-attn-bf16-regkv
Oct 29, 2026
Merged

AzeezIsh merged 2 commits into
mainfrom
perf/hip-attn-bf16-regkv

Conversation

@AzeezIsh

Copy link
Copy Markdown
Contributor

gfx1151 only. Changes inferspark_prefill_paged_64 for the BF16 paged entry, which is the 27B prefill attention.

What changes

  • b43d5b4: K/V tiles go through registers. V's global load is in flight during Q·K^T + softmax, and the next K's load during P·V. V is stored to LDS as f16 once, instead of converting bf16→f32→f16 per element inside every P·V fragment. Per tile per wave, the ISA drops from 256 ds_load_u16 + ~540 VALU to d16/d16_hi loads.
  • 0d95833 (cherry-pick of f96e0fe04): online softmax on all 256 threads. It was neutral on the old kernel, where P·V dominated.
  • The strix-hip inferspark_prefill_paged.cu becomes a local copy of the gb10 file (it was a symlink) so the gate define touches no NVIDIA build. FP8 / NVFP4 / batched entries are unchanged.

Bit-identical. The harness output hash equals main at kv 2k/8k/20k. Greedy logprob probes are IDENTICAL (dlp 0) on strix (s119, s122) and on DevLab.

Measured

where 1.9k 7.4k 12.5k–14.4k
kernel, strix harness, one 2048-row chunk (s117/s118/s121) 6.1 → 4.8 ms 8k: ~57 → ~43 ms 20k: ~203 → ~156 ms
e2e DevLab desktop Strix Halo, 4 rounds interleaved (run 40912659688) 409–417 → 412–417 (neutral) 370–374 → 378–381 (+1.6%, 4/4) 347–350 → 359–361 (+3.0%, 4/4)
e2e strix Z13 (s122, 3 rounds) noise noise 14.4k 242/248/246 → 248/255/251 (+2.0..2.8%, 3/3)

Attention is 8% of a 6.6k prefill and 20% of a 20k prefill (s109/s111 rocprof), so the gain grows with context.

DevLab build of the branch: 40898966157 (success).

🤖 Generated with Claude Code

AzeezIsh and others added 2 commits October 29, 2026 10:47
…d as f16 once (bit-identical, -8..-28%)

inferspark_prefill_paged_64 on gfx1151 converted every V element
bf16 -> f32 -> f16 inside each P.V fragment: 256 ds_load_u16 plus ~540 VALU
per KV tile per wave, for 16 WMMAs. It also loaded K and V synchronously
into one shared buffer with nothing overlapping.

The BF16 paged entry now sets ATLAS_STRIX_ATTN_BF16_REGKV, and its _64
kernel:
- issues V's global load before Q.K^T and stores it after softmax;
- issues the next tile's K load before P.V;
- stores V to LDS as f16 (the same (__fp16)(float)bf16 value, computed once),
  so the P.V fragments are plain d16 / d16_hi loads.

Every value and every summation order are unchanged, so the output is
bit-identical: the harness output hash equals main's at kv 2k/8k/20k.

strix kernel harness (27B geometry: 24 q / 4 kv heads, d=256, one
2048-row chunk, scattered paged BF16 KV), s117 + s118, interleaved x3, per
chunk:
- kv 2k: 6.0-6.5 ms -> 4.8-5.0 ms
- kv 8k: 55-63 ms -> 43-52 ms
- kv 20k: 197-213 ms -> 175-187 ms

Prefetch alone is neutral, and V-f16 alone gets about half the gain.

The strix-hip inferspark_prefill_paged.cu becomes a local copy of the gb10
file (it was a symlink) so the define touches no NVIDIA build. FP8 / NVFP4
/ batched entries never set the gate (the register loader is BF16-only).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
At BR64=64 the online softmax ran one thread per row (64 of 256), with a
32-deep serial exp chain per row per tile.

Four threads per row now do the mask, the row max (order-independent) and
p = sw_exp(s - m_new) for 8 columns each, the same expressions as before.
One thread per row then sums p from shared memory in the original c order
and updates m / l, so the output is bit-identical. The explicit masked
p = 0 is kept.

strix kernel bench, 27B geometry (s86): kv 2k 0.99-1.03x, 8k 1.05-1.12x,
16k 1.07-1.08x, 100% bit-equal.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant