Repository navigation
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
DRAFT — evaluation pausedPR Self-ReviewRevision This pull request is a draft, so readiness evaluation is paused and no verdict applies. Evaluation resumes when it is marked ready for review and the required CI completes. |
There was a problem hiding this comment.
🟡 Changes recommended
The gfx950 branch lacks targeted regression coverage, and existing slice-aggregated error checks can hide sparse tile corruption.
1 open issue
What changed in this PR
This PR addresses a shared-memory race in the gfx950 Gluon fp8_mqa_logits kernel by waiting for reads to finish before a prefetch reuses the buffer.
Changes:
- Adds
wait_shared_reads()to emits_waitcnt lgkmcnt(0)only for single-warp configurations. - Calls the helper before prefetches in the main loop and peeled-tile path.
- Leaves public APIs, configuration selection, and other architectures unchanged.
| File | Description |
|---|---|
aiter/ops/triton/_gluon_kernels/gfx950/attention/fp8_mqa_logits.py |
Adds single-warp waits before shared-memory buffer reuse. |
Review effort: Balanced
| def wait_shared_reads(self): | ||
| # A one-wave barrier doesn't wait for LDS reads, so wait here before | ||
| # the async copy overwrites their buffer. | ||
| if self.kv_cfg.NUM_WARPS == 1: |
There was a problem hiding this comment.
Thanks, added test_fp8_mqa_logits_single_warp_tiles. It picks the single-warp config, checks each 32-column tile, fails 10/10 on main and passes 10/10 with this fix
|
Hi @akii96, thanks for the PR and the clear write-up! I compiled this kernel for gfx950 with triton==3.8.0 (used in CI) and triton==3.9.0 (newest release), with the single-warp config. In both versions, main already has s_waitcnt lgkmcnt(0) before every buffer_load ... lds. So the new wait in this PR is a duplicate there. It's harmless, but it doesn't change anything. Two questions: Which Triton did you use when you saw the failures? |
|
Thanks @msaffari-amd for checking, you're right for the Triton that CI installs.
So it only fails on the other build. As you suggested, I've kept the fix and updated the description. The underlying issue is that a one-wave barrier doesn't wait for pending LDS reads, so main relies on the scheduler placing the wait. This PR adds the wait explicitly, so the kernel is correct whichever 3.8.0 build is installed. One question: on the CI build the new test passes on main as well, so it won't catch a regression there. Would you rather keep it as a check for other builds, or drop it? |
The single-warp variant (num_warps=1, BLOCK_KV=32, picked for block_m=1 and seq_len > 4096) gave wrong, run-to-run varying logits: one row by up to one KV tile at a time. Each loop iteration reads K for tile i from an LDS slot (ds_read), then issues the async copy for tile i+2 into the same slot (buffer_load ... lds). The LDS-DMA write goes through the vector-memory path and is not ordered after the wave's pending ds_reads. With more than one warp, the barrier Triton puts before the copy is an s_barrier, and the waitcnt pass drains lgkmcnt(0) ahead of it. A one-wave workgroup gets that barrier lowered to a wave barrier, which waits for nothing. The copy could then land before the reads finished: only an lgkmcnt(2) for the first MFMA came before it. BLOCK_KV=64 happened to put an lgkmcnt(0) in front of the copy. Wait for the LDS reads explicitly before the prefetch when NUM_WARPS == 1. Multi-warp ISA is unchanged (identical hashes). The single-warp speed is kept: s=16384 H64 causal 1501us before, 1511us after, versus 1610us with the variant removed. Signed-off-by: Aakif Nawaz <[email protected]>
…_mqa_logits race Signed-off-by: Aakif Nawaz <[email protected]>
1541d07 to
92ac950
Compare
|
Thanks @akii96, that explains it, and the updated description is very clear. About your question: I'd keep the test. It's cheap, it catches the bug with the vLLM build, and it will catch it if CI ever moves to a build like that. LGTM. Please mark the PR as ready for review so CI can run. |

Summary
On gfx950,
fp8_mqa_logitscan return wrong logits fornum_heads > 32andseq_len > 4096with some Triton 3.8.0 builds. Those shapes use a single-warp config (num_warps=1,BLOCK_KV=32), where nothing in the kernel guarantees that a tile's LDS reads finish before the async copy of a later tile overwrites the same buffer. With one warp the barrier doesn't wait for pending LDS reads, so the wait depends on the scheduler: the Triton build installed by aiter CI happens to place it, while the3.8.0+git669b31acbuild in the vLLM ROCm nightly images does not. This PR adds the wait explicitly for the single-warp path, so the kernel is correct on either build. Other configs compile to the same ISA as before, and speed stays the same.Motivation
We found this while checking the FlyDSL
fp8_mqa_logitskernel against this Gluon kernel on MI355X (#6164). FlyDSL and a torch fp32 reference agreed with each other. Gluon did not.Which shapes break on main (MI355X, fp8, causal, Triton
3.8.0+git669b31ac):What the error looks like:
Each bad spot is one row with about 5 to 50 wrong columns, usually inside one 32-wide KV tile. The positions move between runs. Packing doesn't matter: a single 4098-row sequence fails too.
Narrowing it down (8190 × 3, H64, 3 to 4 runs each):
UNROLL=1gl.barrier()before the prefetchSo it needs both one warp and BLOCK_KV=32.
Root cause
Each loop iteration does this on one LDS slot:
ds_read_b128× 4ifrom slotkbuffer_load ... ldsi+2into slotkStep 2 writes LDS by a different path than step 1 reads it, so the hardware does not wait for step 1 to finish first. The code has to wait explicitly.
s_waitcnt lgkmcnt(0)+s_barriers_waitcnt lgkmcnt(0)(placed by the scheduler)s_waitcnt lgkmcnt(2)with3.8.0+git669b31acWith one warp the barrier becomes a wave barrier, which emits no wait. This is also why adding
gl.barrier()didn't help.Affected Triton builds
Both builds report
triton.__version__ == "3.8.0":3.8.0+amd.rocm7.2.0.git7cb7b059.github/scripts/install_triton.sh(aiter CI)lgkmcnt(0)before every copy3.8.0+git669b31acvllm/vllm-openai-rocmnightly imageslgkmcnt(2)before the first copy after the fourds_read_b128, none in the peeled tileOn current main (9ac5ce9) with
3.8.0+git669b31ac, the new test fails 10 of 10 runs on MI350X and this PR passes 10 of 10. The H64 shapes above are wrong in 1 to 10 of 10 runs on both MI355X and MI350X. With the CI build, the new test passes on main too, so CI won't catch a regression here.To reproduce, keep the image's Triton: install aiter with
AITER_USE_SYSTEM_TRITON=1 pip install -e .without runninginstall_triton.sh.Changes
aiter/ops/triton/_gluon_kernels/gfx950/attention/fp8_mqa_logits.py, +18 lines:MQAAsyncKVLoader.wait_shared_reads(): emitss_waitcnt lgkmcnt(0)whenNUM_WARPS == 1, nothing otherwise.It is inline asm because this Gluon version has no primitive to wait for LDS reads.
Performance
MI355X, causal, H64, µs, best of 3:
For comparison, avoiding the single-warp config entirely would cost 6 to 9% (16384: 1610 µs).
Testing
op_tests/triton_tests/attention/test_fp8_mqa_logits.py(rebased on 9ac5ce9)test_flydsl_fp8_mqa_logits.pypacked shapes vs Gluontest_fp8_mqa_logits_single_warp_tiles(MI350X,3.8.0+git669b31ac, 10 runs)Documentation
Dependencies
Breaking Changes
None.
Related
ds_readwait ordering race on gfx942.PR Self-Review
Reviewed revision
92ac950
Behavior and intent
The gfx950 single-warp config now waits for its LDS reads before the async copy reuses the same buffer. Output is correct and stable across runs on both Triton 3.8.0 builds, and speed matches main. Configs with 2+ warps compile to the same ISA as before.
Validation and unverified scope
Validated on MI355X with the repro shapes above and the FlyDSL comparison (48/48). After rebasing on 9ac5ce9, validated on MI350X with
3.8.0+git669b31ac: the full op test file passes (254), and the new regression test fails 10/10 on main and passes 10/10 with this fix.Remains unverified:
PR-specific question
Is inline
s_waitcnt lgkmcnt(0)fine here, or is there a Gluon primitive you would rather use to wait for LDS reads before an async copy into the same buffer?Changed op tests
op_tests/triton_tests/attention/test_fp8_mqa_logits.py: addstest_fp8_mqa_logits_single_warp_tiles(gfx950 only, about 1.4 s). With 64 heads and 8190 rows it is the only test that picks the single-warp config. It checks each 32-column tile against the fp32 reference, since the existing check averages over 32 rows and can miss a few bad columns. It runs 3 times because the race does not hit every run. It fails on main with3.8.0+git669b31acbut passes on main with the CI build, so CI won't catch a regression here.