Repository navigation
[MLA] [Test] Check the gfx950 FP8 QH16 qseqlen2 MLA decode for LDS races - #7621
AndreasKaratzas wants to merge 5 commits into
Conversation
mla_a8w8_qh16_qseqlen2_gqaratio16.co and its _ps variant have two cross-wave LDS races: - Q prologue: each wave DMAs 8 Q rows into 0x300-byte slots, but a row is 576 bytes. Group 1 of wave 3 ends at 0x3060 and overlaps the first 96 bytes of group 2 of wave 0 (query 1, head 0). Two waves write the same LDS bytes with no order. Move group 2 up by 0x60 (the m0 step and the 9 group-2 ds_read_b128 offsets). - Main loop: the query-1 P read (ds_read_b64 v[86:89], v6, LDS 0..0x478) and the next K-tile write (ds_write_b32 v22, LDS 0..0x4000) are in the same barrier interval. A fast wave overwrites P before a slow wave reads it. In each of the 4 loop halves, "s_waitcnt lgkmcnt(0); s_waitcnt vmcnt(37)" becomes "s_waitcnt vmcnt(37) lgkmcnt(0); s_barrier". The file size, the ELF layout and the branch targets do not change. There is no code motion. Add check_fp8_gqa16_multi_tile_batch to test_mla_persistent.py. It runs 128 rows of 3 KV tiles next to a copy on a side stream, for the persistent and the non-persistent qseqlen2 kernels. On main it fails in every run. With these .co files it passes. Co-authored-by: Claude <[email protected]> Signed-off-by: Andreas Karatzas <[email protected]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
NOT READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
|
Blocker beyond rebase: This overwrites the same gfx950 objects as #6277 ( Nit: side-stream buffers are CPU (see #7623). Helper is duplicated with #7623. Stack order: #6277 first, then this. |
Co-Authored-By: Claude <[email protected]> Signed-off-by: Andreas Karatzas <[email protected]>
MI355X (gfx950) verification, after updating with mainI merged Setup: MI355X, installed aiter 0.1.28.post1. Kernels were swapped through an
The repro results are the same with and without a different MLA decode run between calls ( Not fixed here, for awareness: both qseqlen2 kernels still have the KV slot 0 OOB read that #7872 fixed for other PS kernels. With NaN written into an unreferenced slot 0, they return NaN rows (ps: 26/27 shapes, non-ps: 24/27) on main and on this branch alike. As a control, AI assistance (Claude) was used for the merge and the verification runs. |
The rebuilt mla_a8w8_qh16_qseqlen2_gqaratio16{,_ps}.co objects were
committed as 100644, while main tracks them as 100755. Restore the
mode so this PR only changes the binary contents.
Co-Authored-By: Claude <[email protected]>
Signed-off-by: Andreas Karatzas <[email protected]>
|
Thanks for the review. Blocker: agreed on the order. #6277 should merge first. Once it does, I will rebase this PR onto its rebuilt CPU-buffer nit: the side-stream buffers are on the GPU. I also pushed 84ee885, which restores the 100755 mode on the two |
…qlen2_qlayout Co-authored-by: Claude <[email protected]> Signed-off-by: Andreas Karatzas <[email protected]>
Take main's rebuilt qseqlen2 .co files from #6277. They already fix both LDS races, so this branch keeps only the qlen 2 regression check. Co-authored-by: Claude <[email protected]> Signed-off-by: Andreas Karatzas <[email protected]>
|
thanks, merged main with #6277 in. turns out its rebuilt qseqlen2 on MI350X the new check fails 3/3 with the pre-#6277 |
Summary
This PR adds a regression check for the gfx950 FP8 QH16 qseqlen2 MLA decode kernels (
hsa/gfx950/mla/mla_a8w8_qh16_qseqlen2_gqaratio16.coandmla_a8w8_qh16_qseqlen2_gqaratio16_ps.co) toop_tests/test_mla_persistent.py. The check fails on the kernels that were on main before #6277 and passes on the kernels that #6277 rebuilt.The PR first shipped binary patches of these two
.cofiles. #6277 rebuilt both files from SP3, and the rebuilt kernels already fix the two LDS races that the patches fixed. The PR now uses main's.cofiles unchanged and keeps only the test.Motivation
These kernels run fp8 MLA decode with 16 heads and 2 query tokens per row, for example MTP speculative decode with 1 draft token. Before #6277, the output of query 1 was wrong for some heads under load, and the error was silent. Two cross-wave LDS races caused it:
The disassembly of the rebuilt kernels (
llvm-objdump --mcpu=gfx950, both.cofiles) shows that #6277 removes both races:s_add_u32 m0, m0, 0x2480, group-2ds_read_b128offsets 12416..12928). It no longer overlaps group 1.ds_write_b32 ... offset:34304,ds_read_b64 ... offset:34304/34336). The K tile writes keep their old offsets (0..12960 from the per-wave base), so the P read and the K write no longer use the same LDS bytes. The GPU runs below confirm this: 0 bad calls where the old kernels fail in every run.The existing checks did not catch the races: the existing calls of
check_fp8_gqa16_multi_tile_batchcover qlen 1 only, and the existing sweeps use small batches and no concurrent work. The new calls fail on every run with the old kernels. They keep a later rebuild of these two.cofiles from bringing the races back.Related: #7007 reports wrong, nondeterministic output of
qseqlen2_gqaratio16_psandqseqlen4_gqaratio16_v3_ps. #7617 and #7622 cover the qseqlen1 kernels, and #7623 the qseqlen4 v3 kernel. #7622 added the sharedcheck_fp8_gqa16_multi_tile_batchhelper; this PR and #7623 only add calls to it.Changes
op_tests/test_mla_persistent.py:main()calls the existingcheck_fp8_gqa16_multi_tile_batchon gfx950 for qlen 2, persistent and non-persistent (3 lines)..cochange. The branch takes main's ([ASM] [HIP] [CI] [MLA] [Bugfix] Fix and optimize the gfx942 MLA decode/prefill kernels #6277)mla_a8w8_qh16_qseqlen2_gqaratio16{,_ps}.co, byte for byte.Performance (if applicable)
Not applicable. The PR does not change a kernel.
Testing
The kernels are gfx950 only, so MI250X and MI300X do not apply.
Documentation
The PR adds a test only.
Dependencies
Breaking Changes
None.
PR Self-Review
Reviewed revision
d62112f
Behavior and intent
The PR adds two calls of an existing check to
main()ofop_tests/test_mla_persistent.py. The check runs the gfx950 fp8 gqa16 qlen 2 decode kernels (persistent and non-persistent) on 128 rows with 3 KV tiles each, next to a copy on a side stream, and compares every (row, query, head) output with an fp32 reference. Kernel behavior does not change.Validation and unverified scope
MI350X (gfx950), one GPU, PyTorch 2.13.0+rocm10.0.0, aiter main c2d0220 (#6277) merged into this branch. "Old" is the pair of
.cofiles from main before #6277 (c2d0220^), loaded through anAITER_ASM_DIRoverlay. "Main" is #6277's files, which this branch now ships..co.co(this branch)check_fp8_gqa16_multi_tile_batch(2)(ps)check_fp8_gqa16_multi_tile_batch(2, persistent=False)kv_len257..399, 2400 calls, ps / non-ps, idlekv_len1000..2100, 400 calls, ps / non-psIn the old runs, every wrong output is in query 1. The table's main column is from main; the same 1-row and 128-row runs on this branch also gave 0 bad calls (16,800 calls). On main, 84,000 more calls (5 more seeds, same shapes, 3 modes, both kernels) gave 0 bad calls.
python op_tests/test_mla_persistent.py -n 16,2 -d fp8 -kvd fp8, with and without-nps: 10 of 10 runs each exit 0, and the new check passes in every run. The sweep'scheckAllclosetallies have the same failure count per run as main (about 16 "golden vs aiter_asm" failures per run, the same on the old kernels).python op_tests/test_mla_ltx.py --preset qh16_fp8_q2 --ps ps nps --lse off --suites boundary over4g page16m mega([ASM] [HIP] [CI] [MLA] [Bugfix] Fix and optimize the gfx942 MLA decode/prefill kernels #6277's 64-bit KV test): 24 of 24 cases pass, including KV byte offsets above 4 GiB (up to 10.9 GB) and the 7.4M-token sequential case. With the old.cofiles, 10 of the 22 non-mega cases give a warning (max abs delta 0.033 against atol 0.03), all of them above 4 GiB.Not verified, and not changed by this PR:
kv_len5/300/1100, 3 index orders) give NaN rows, for ps and non-ps. With NaN in a different unreferenced slot, 0 of 27 do. [ASM] Fix MLA PS mode nan error for kv page0 has nan data and the LTD OOB read page0 data #7872 fixed this for other PS kernels. It needs a separate fix.mla_a8w8_qh16_qseqlen2_gqaratio16_ps_page.cois not inmla_asm.csv, so no path loads it. Not tested.PR-specific question
Only gfx950 fp8 MLA decode with fp8 Q, fp8 KV, 16 heads per KV head,
max_seqlen_q2, causal, and no LSE or context parallel reaches the kernels that the new check runs.mla_asm_decode_remapincsrc/py_itfs_cu/asm_mla.cumaps gqa 16 fp8 withmax_seqlen_q == 2toqSeqLen=2.hsa/gfx950/mla/mla_asm.csvhas twoqh16_qseqlen2_gqaratio16rows:ps=1loads_ps.coandps=0loads the non-persistent.co. The check is gated onget_gfx() == "gfx950", so it does not run on other archs. The PR does not change a kernel, the CSV or the dispatch.Changed op tests
op_tests/test_mla_persistent.py:main()now also calls the existingcheck_fp8_gqa16_multi_tile_batch(from #7622) with qlen 2, persistent and non-persistent. The helper runs 64 calls of 128 rows with 3 KV tiles each, next to a 256 MiB device-to-device copy on a side stream, and compares every (row, query, head) output with an fp32 reference. It fails on every run with the pre-#6277 kernels and passes on main. It takes less than 2 s per kernel.AI assistance (Claude Code) was used for the analysis and the verification runs. A human reviewed the change.