Repository navigation
[gfx1250] [Perf] FP8 varlen ASM prefill: split the keys of a non-causal call that underfills the GPU - #7946
[gfx1250] [Perf] FP8 varlen ASM prefill: split the keys of a non-causal call that underfills the GPU#7946gbyu-amd wants to merge 1 commit into
Conversation
… that underfills the GPU
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
…rfills the GPU (#7946 @ 88c4ddf, head 2026-11-13T18:08:12Z) Applied as the diff 74a3010..88c4ddf (3 files) onto the rebased 1116 tree; PR state: draft, author gbyu-amd, base main. (cherry picked from commit 572a65d) Rebase onto main 12-03: imports fast_launch from aiter.ops.triton.utils.fast_launch; main's #8061 moved it there from _triton_kernels/kimi_delta_attn/.
Problem
fmha_fwd_fp8_varlen_asm(gfx1250, FP8 per-tensor, D192x128) launchesceil(max_seqlen_q / 256) x heads x batchworkgroups, and each one walks its sequence's whole key range. A chunked-prefix prefill call — 1024 new query tokens, 12 heads (a 96-head model at TP8), one sequence, a 16384-key cached chunk — is 48 workgroups on a 256-CU MI455X. Such a call is bound by one workgroup's walk over the keys, so its time barely depends on the query length: 512, 1024 and 4096 queries against 16384 keys take 109, 113 and 125 µs.Change
New
aiter/ops/fmha_fp8_split_kv.py, called from the top offmha_fwd_fp8_varlen_asmfor non-causal calls:Scontiguous parts and given to the same ASM kernel asSsequences of one varlen batch.Sdoubles whiletiles x Sstays within the CU count and every part keeps at least 512 keys.cu_seqlensstay monotone and K/V are read in place.cu_seqlensand repeats each query rowStimes.Spartial outputs by their LSE.fast_launch(the eager prefill path would otherwise wait on Triton's argument binding).outis [total_q, H, 128] bf16 andlseis the natural-log [total_q, H, 1].q.AITER_FMHA_FP8_SPLIT_KV=0turns it off and=NforcesNparts.Results
MI455X, one GPU. Times are profiler kernel time, median of 10 calls, with inputs rotated so they are not cache-resident. "Plain" is the ASM kernel alone; "split" is the query copy, the ASM kernel and the merge.
Three kinds of call are unchanged: causal calls, calls whose grid already fills the GPU (e.g. 1 x 4096 x 16384), and calls with fewer than 8192 keys.
Wall clock of back-to-back calls (CUDA events,
python op_tests/test_fmha_fp8_split_kv.py): 1.38–1.81x on the split cases and 1.00x elsewhere. With nothing else queued on the GPU this loop includes the host side, so it understates the kernel gain.Correctness
python -m pytest op_tests/test_fmha_fp8_split_kv.py: 20 passed. The test covers:Sin {2, 4, 8};The output matches the unsplit call to ~1e-5. The kernel's LSE is the log of the sum of the FP8-rounded probabilities, so a part with its own running max rounds slightly differently: |ΔLSE| ≤ ~5e-3. The test tolerance is 2e-2.
Testing
aiter/ops/mha.py(main 74a3010 plus the dispatch) and the new module and test, on MI455X (gfx1250).module_fmha_fwd_fp8_varlen_asmand hsaco come from main of 2026-11-11. Neither the kernel nor its ABI has changed since [ASM] [HIP] [FlyDSL] [gfx1250] asm mha fp8 fwd: add D192x128 per-tensor varlen kernel #7375.