Skip to content

[Triton/Gluon] [Bugfix] Fix gfx1250 gemm_a16w16 dropping output rows past 2**31 bytes - #6629

Merged
azaidy merged 1 commit into
ROCm:mainfrom
yichiche:gfx1250-a16w16-2gb-store-fix
Oct 20, 2026
Merged

azaidy merged 1 commit into
ROCm:mainfrom
yichiche:gfx1250-a16w16-2gb-store-fix

Conversation

@yichiche

Copy link
Copy Markdown
Contributor

Motivation

What goes wrong
On gfx1250, _gemm_a16w16_bandwidth_bound_kernel writes C with buffer_store(acc, c_ptr, offs_c), where offs_c = stride_cm * offs_cm + stride_cn * offs_cn is measured from the start of C. buffer_store offsets are 32-bit, so once a row starts past 2**31 bytes of C the store is dropped. The kernel returns without error, and every row from 2**31 // (N * 2) on keeps whatever was in that memory before.

Where it shows up
Any bf16/fp16 GEMM whose output is larger than 2 GiB and that dispatches to the bandwidth_bound gluon kernel, which is what the gfx1250 configs select for large M (including the Wan2.2 configs from #6032). Wan2.2-T2V-A14B at 1280x720x193 frames hits it on the FFN up-projection (M=90000, N=13824, K=5120, 2.49 GB output): rows 77672..89999 are never written. Through SGLang's tgemm route (SGLANG_USE_ROCM_AITER_TGEMM=1) the generated video ends in noise, or is fully black when the stale memory holds NaN. The compute_bound kernel stores C through a TDM descriptor and is not affected (verified with a forced compute_bound config on the same >2 GiB shapes).

How to fix
Move C's base pointer to this block's (M, N) offset in int64 before buffer_store, so the 32-bit offsets stay within one block. This is the same rebasing the kernel already does for the A and B descriptors.

Modifications

  • aiter/ops/triton/_gluon_kernels/gfx1250/gemm/basic/gemm_a16w16.py: in _gemm_a16w16_bandwidth_bound_kernel, compute c_base = c_ptr + (pid_m * BLOCK_M).to(int64) * stride_cm + (pid_n * BLOCK_N).to(int64) * stride_cn and store with block-local offsets. The store mask is unchanged.
  • op_tests/triton_tests/gemm/basic/test_gemm_a16w16.py: add test_gemm_a16_w16_large_output (gluon only). It fills the output with NaN, runs the Wan2.2 FFN shape (M=90000, N=13824, K=5120), and checks the first rows, the rows around the 2**31-byte boundary, and the last rows against F.linear.

Accuracy Tests

Kernel-level check on gfx1250 (MI450). Before each call, the cached output block is filled with NaN. bad rows = rows with max abs error > 10% of the reference row max, or any NaN. The reference is F.linear in fp32.

M N K Output size bad rows before bad rows after rel. error after
90000 13824 5120 1.16 x 2^31 B 12328 (first: 77672) 0 1.66e-3
78000 13824 5120 1.00 x 2^31 B 328 (first: 77672) 0 1.66e-3
77000 13824 5120 0.99 x 2^31 B 0 0 1.66e-3
250000 5120 5120 1.19 x 2^31 B 40285 0 1.66e-3
90000 5120 13824 0.43 x 2^31 B (input 1.16 x 2^31 B) 0 0 1.66e-3
512 / 4096 13824 / 5120 5120 / 13824 small 0 0 1.66e-3

Unit tests:

Test Before After
test_gemm_a16w16.py -k gluon (existing) - 468 passed
test_gemm_a16_w16_large_output (new) failed (50% mismatched in the boundary slice) passed

End to end: Wan2.2-T2V-A14B in SGLang, 1280x720, 193 frames, 8 steps, 2 GPUs with CFG parallel, SGLANG_USE_ROCM_AITER_TGEMM=1, eager. The comparison is against the same run with SGLANG_USE_ROCM_AITER_TGEMM=0 (F.linear).

Run Video PSNR vs F.linear run
Before last ~15 frames are noise 12.9 dB
After clean 138.1 dB

Benchmarking and Profiling

gfx1250 (MI450), bf16, the bandwidth_bound kernel selected by the shipped gluon config, mean of 5 runs:

M N K Before After
90000 13824 5120 16.94 ms (752 TFLOPS, output incomplete) 17.36 ms (734 TFLOPS)
90000 5120 13824 15.22 ms (837 TFLOPS) 15.24 ms (836 TFLOPS)
90000 5120 5120 6.94 ms (680 TFLOPS) 6.92 ms (682 TFLOPS)
250000 5120 5120 18.75 ms (699 TFLOPS, output incomplete) 19.14 ms (685 TFLOPS)
4096 5120 13824 0.82 ms 0.82 ms

Shapes whose output fits in 2 GiB are unchanged. On the >2 GiB shapes, the "before" time skipped storing the dropped rows, so the small increase is the cost of writing the full output. End to end (Wan2.2 run above, warm kernel cache): 167.8 s before, 169.1 s after.

Checklist

  • Format with black and ruff (ruff 0.16.0, as pinned in pre-checks.yaml)
  • Add a unit test that fails before the fix and passes after
  • Accuracy and performance results above

@yichiche
yichiche requested a review from a team October 16, 2026 15:27
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

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

Extended tests (opt-in via labels):

Label Tests
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 gfx1201 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 6629 --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.

@yichiche

Copy link
Copy Markdown
Contributor Author

@k50112113 Could you help review this PR? It is a follow-up to #6032 that fixes an overflow when the buffer exceeds 2GB (when the image is large enough).

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.

🔵 Needs a closer look

The reported gfx1250 correctness and performance results need final human confirmation because independent GPU validation was unavailable.

0 open findings

What changed in this PR

Fixes missing output rows in gfx1250 Gluon A16W16 GEMM when output exceeds 2 GiB, including large Wan2.2 workloads.

Changes:

  • Rebase the output pointer with 64-bit arithmetic and use block-local store offsets.
  • Add a NaN-filled regression test that checks rows around the size boundary and output ends.
File Description
op_tests/​triton_tests/​gemm/​basic/​test_gemm_a16w16.py Adds large-output regression coverage.
aiter/​ops/​triton/​_gluon_kernels/​gfx1250/​gemm/​basic/​gemm_a16w16.py Rebases output stores to avoid offset overflow.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@zufayu
zufayu requested review from a team and Dewei-Wang-sh October 18, 2026 23:31

@azaidy azaidy 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.

LGTM!

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