Skip to content

[Triton/Gluon] [gfx950] Fix LDS WAR race in single-warp fp8_mqa_logits - #7823

Draft
akii96 wants to merge 2 commits into
ROCm:mainfrom
akii96:gluon-mqa-gfx950-race
Draft

akii96 wants to merge 2 commits into
ROCm:mainfrom
akii96:gluon-mqa-gfx950-race

Conversation

@akii96

@akii96 akii96 commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

On gfx950, fp8_mqa_logits can return wrong logits for num_heads > 32 and seq_len > 4096 with 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 the 3.8.0+git669b31ac build 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_logits kernel 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):

Shape (rows × sequences) Heads Config picked Main
16368 × 24 64 1 warp, BLOCK_KV=32 wrong every run, rel err up to 0.43
16380 × 12 64 1 warp, BLOCK_KV=32 wrong every run
8190 × 3 64 1 warp, BLOCK_KV=32 wrong every run, rel err 0.17 to 0.49
8191 × 1 64 1 warp, BLOCK_KV=32 wrong every run
4098 × 1 64 1 warp, BLOCK_KV=32 wrong in 2 of 10 runs
4096 × 2 64 2 warps, BLOCK_KV=64 correct
any of the above 32 2 warps, BLOCK_KV=64 correct

What the error looks like:

Example Row Column Gluon Reference
16368 × 24, H64 15761 15687 -166.87 15.39
8190 × 3, H64 1855 1792 -34.24 36.07

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):

Config Result
1 warp, BLOCK_KV=32 (main) wrong
1 warp, BLOCK_KV=64 correct
2 warps, BLOCK_KV=32 correct
2 warps, BLOCK_KV=64 correct
1 warp, BLOCK_KV=32, UNROLL=1 wrong
1 warp, BLOCK_KV=32, gl.barrier() before the prefetch wrong

So it needs both one warp and BLOCK_KV=32.

Root cause

Each loop iteration does this on one LDS slot:

Step Instruction What it does
1 ds_read_b128 × 4 read tile i from slot k
2 buffer_load ... lds start copying tile i+2 into slot k

Step 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.

Config What comes before the copy Safe?
2+ warps s_waitcnt lgkmcnt(0) + s_barrier yes
1 warp, BLOCK_KV=64 s_waitcnt lgkmcnt(0) (placed by the scheduler) yes, by luck
1 warp, BLOCK_KV=32 only s_waitcnt lgkmcnt(2) with 3.8.0+git669b31ac no: 2 of the 4 reads can still be in flight

With 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":

Build Source main this PR
3.8.0+amd.rocm7.2.0.git7cb7b059 .github/scripts/install_triton.sh (aiter CI) correct: the scheduler places lgkmcnt(0) before every copy correct
3.8.0+git669b31ac vllm/vllm-openai-rocm nightly images wrong: only lgkmcnt(2) before the first copy after the four ds_read_b128, none in the peeled tile correct

On 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 running install_triton.sh.

Changes

aiter/ops/triton/_gluon_kernels/gfx950/attention/fp8_mqa_logits.py, +18 lines:

  • New MQAAsyncKVLoader.wait_shared_reads(): emits s_waitcnt lgkmcnt(0) when NUM_WARPS == 1, nothing otherwise.
  • Called right before the prefetch in the main loop and in the peeled tile.

It is inline asm because this Gluon version has no primitive to wait for LDS reads.

Path Effect
1 warp one wait added before each prefetch
2+ warps none: ISA identical to main (H16, H32, H64 2-warp kernels)
Wrapper and config selection unchanged
Other archs unchanged

Performance

MI355X, causal, H64, µs, best of 3:

Shape Main This PR Change
8192 372.4 375.0 +0.7%
16384 1500.7 1511.1 +0.7%
32768 5929.1 5937.7 +0.1%
16384, 4 sequences 556.5 553.8 -0.5%
16380, 12 sequences 361.0 361.5 +0.1%

For comparison, avoiding the single-warp config entirely would cost 6 to 9% (16384: 1610 µs).

Testing

Test Main This PR
4098 × 1, H64 2/10 runs wrong 60/60 runs correct
16368 × 24, H64 wrong 15/15 runs correct
8190 × 3, 16380 × 12, 8191 × 1 (H64), 5 runs each wrong correct (rel err ~2e-5)
8190 × 3, 16380 × 12 (H32), 3 runs each correct correct
op_tests/triton_tests/attention/test_fp8_mqa_logits.py (rebased on 9ac5ce9) 254 passed
FlyDSL test_flydsl_fp8_mqa_logits.py packed shapes vs Gluon 38/48 48/48
test_fp8_mqa_logits_single_warp_tiles (MI350X, 3.8.0+git669b31ac, 10 runs) 10/10 fail 10/10 pass
black, ruff clean
  • Unit tests run
  • Performance benchmarks run

Documentation

  • No documentation change is needed

Dependencies

  • No new third-party dependencies added

Breaking Changes

None.

Related

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:

  • Whether the 8 copies issued before the loop can overlap the KV slots. Their offsets were checked by hand only.
  • Other archs, since this kernel is gfx950 only.
  • Which Triton commit makes the CI build place the wait. The root cause is that a one-wave barrier doesn't wait for pending LDS reads; if Triton guarantees that wait, this one becomes redundant.

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: adds test_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 with 3.8.0+git669b31ac but passes on main with the CI build, so CI won't catch a regression here.

@akii96
akii96 requested a review from a team November 11, 2026 12:54
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter standard tests on MI35X
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:mi300x Run Aiter standard tests on MI300X in PRs; main branch always runs them
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the Radeon R9700 ROCm runner
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 7823 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

Reviews:
A reviewer is usually assigned within one working day after the PR is ready for review (see Code Review Process). If nobody has responded for about a week, mention the area contact listed in CONTACTS.md. Want to help review? See REVIEWERS.md.

@aiter-bot

aiter-bot commented Nov 11, 2026 •

Copy link
Copy Markdown

DRAFT — evaluation paused

PR Self-Review

Revision 1541d07eb772 · mode shadow

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 emit s_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:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@akii96
akii96 marked this pull request as draft November 12, 2026 16:14
@zufayu
zufayu removed the request for review from cagrikymk November 13, 2026 00:03
@msaffari-amd

Copy link
Copy Markdown
Contributor

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?
Does the new test also fail on main with triton==3.8.0?
If it only fails on your Triton, the fix is still good to keep. Please just mention it in the description. If it also fails on 3.8.0, the real cause is probably something else.

@akii96

akii96 commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks @msaffari-amd for checking, you're right for the Triton that CI installs.

  1. Which Triton: I used 3.8.0+git669b31ac, the build in the vllm/vllm-openai-rocm nightly images. CI's install_triton.sh installs 3.8.0+amd.rocm7.2.0.git7cb7b059. Both report 3.8.0, but they schedule this kernel differently. With the CI build, main's single-warp kernel has lgkmcnt(0) before every buffer_load ... lds, which matches what you saw. With the other build, it has only lgkmcnt(2) before the first copy after the four ds_read_b128, and no wait in the peeled tile.

  2. Does the new test fail on main with 3.8.0: with the CI build, no, it passes. With 3.8.0+git669b31ac on current main (9ac5ce9), it fails 10 of 10 runs on MI350X, and this PR passes 10 of 10.

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]>
@akii96
akii96 force-pushed the gluon-mqa-gfx950-race branch from 1541d07 to 92ac950 Compare November 14, 2026 09:28
@msaffari-amd

Copy link
Copy Markdown
Contributor

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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants