Skip to content

[Triton/Gluon] [Bugfix] Compute Triton split-K partial offsets in int64 - #6758

Merged
azaidy merged 1 commit into
ROCm:mainfrom
siliangchen-amd:triton-splitk-int64
Oct 22, 2026
Merged

azaidy merged 1 commit into
ROCm:mainfrom
siliangchen-amd:triton-splitk-int64

Conversation

@siliangchen-amd

@siliangchen-amd siliangchen-amd commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Split-K GEMMs keep one fp32 (M, N) partial per split, and a reduce kernel sums them. Both sides address partial k as k * stride with pid_k / offs_k and the stride in int32, so the offset wraps once (NUM_KSPLIT − 1) · M · N reaches 2^31. On gfx942, gemm_a8w8_blockscale with M=4096, N=36864, K=2048 and an explicit 16-way split aborts on main:

Memory access fault by GPU node-2 (Agent handle: 0x491741e0) on address 0x70da2dc41000. Reason: Write access to a read-only page.

The shipped configs don't get there, since they pick split-K for small M. Explicit configs and the tuner do: a large-M sweep_configs.py run of gemm_a8w8_blockscale on gfx942 lost a worker to this on about 2,800 configs.

Change

Cast pid_k (writers) and offs_k (reducers) to int64 before scaling by the partial stride, in the Triton kernels under _triton_kernels that write or reduce split-K partials: the basic, batched and fused GEMMs, common/splitk_reduce.py and fused_bmm_rope_kv_cache.py. Row and column offsets were already int64, and the MoE GEMMs and the gfx1250 Gluon gemm_a16w16_persistent already cast pid_k this way.

The Gluon kernels under _gluon_kernels/gfx950 and _gluon_kernels/gfx1250 compute pid_k * stride_ck the same way. They need a newer Triton than 3.6 to compile, so I left them out rather than change code I can't build.

Test plan (MI325X, gfx942, ROCm 7.2.2, Triton 3.6.0)

  • The repro above, through the public wrapper against run_torch: aborts on main, passes with this PR.
  • gfx942 op tests of the touched kernels (gemm/basic, gemm/batched, gemm/fused, fusions/test_fused_bmm_rope_kv_cache.py): 3,207 passed. The only failures are test_gemm_afp8wfp8.py's 320, which fail to compile on main too.
  • The gfx950-only kernels (the fp4 GEMMs), compiled for gfx950 through their op tests without launching: 8,995 compiled, the same as main. The failures, the same 120 on main, are Gluon blockscale cases that need a newer PaddedSharedLayout.
  • gemm_afp8wfp8.py doesn't compile with Triton 3.6 on gfx942 or gfx950, on main or here, so its two lines are untested.
  • Timing of 4 split-K a8w8 blockscale cases (gfx942 tuned configs, CUDA graphs): within ±0.6% of main.

Found while tuning the gfx942 configs in #6757.


Powered by Hyperloom, with human review, writing and testing.

Split-K GEMMs write partial k of an (M, N) output at k * M * N elements
into the partial buffer, and the reduce kernels read it back the same
way. pid_k, offs_k and the partial strides are int32, so once
(NUM_KSPLIT - 1) * M * N reaches 2**31 the offset wraps: on gfx942, a8w8
blockscale with M=4096, N=36864, K=2048 and 16 splits writes into a
read-only page and aborts.

Cast pid_k and offs_k to int64 before scaling them by the partial
stride in the Triton split-K writers and reducers. Row and column
offsets were already int64. Timing is unchanged.

Co-authored-by: Cursor <[email protected]>
Signed-off-by: siliangchen-amd <[email protected]>
@siliangchen-amd
siliangchen-amd requested a review from a team October 21, 2026 05:35
@github-actions github-actions Bot changed the title [Bugfix] Compute Triton split-K partial offsets in int64 [Triton/Gluon] [Bugfix] Compute Triton split-K partial offsets in int64 Oct 21, 2026
@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 6758 --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.

@siliangchen-amd

Copy link
Copy Markdown
Contributor Author

@azaidy @omuhamma this one fixes the int32 split-K offset overflow I hit while tuning #6757. Could you take a look? Thanks!

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

A committed regression test must exercise both writing and reducing partials beyond the int32 offset boundary.

1 open issue
What changed in this PR

This PR prevents int32 overflow when Triton GEMMs address split-K partial buffers, fixing a fault found during gfx942 tuning.

Changes:

  • Cast split indices to int64 before stride multiplication in basic, batched, and fused GEMM writers.
  • Apply the same fix to shared and specialized reducers.
  • Leave Gluon kernels unchanged.

Paths below are relative to aiter/ops/triton/_triton_kernels/.

File Description
gemm/​fused/​fused_gemm_afp4wfp4_split_cat.py Widen writer and reducer offsets.
gemm/​fused/​fused_gemm_afp4wfp4_mul_add.py Widen writer and reducer offsets.
gemm/​fused/​fused_gemm_afp4wfp4_a16w16.py Widen both output paths and reducers.
gemm/​fused/​fused_gemm_a8w8_blockscale_split_cat.py Widen writer and reducer offsets.
gemm/​fused/​fused_gemm_a8w8_blockscale_mul_add.py Widen writer and reducer offsets.
gemm/​fused/​fused_gemm_a8w8_blockscale_a16w16.py Widen both output paths and reducers.
gemm/​fused/​fused_gemm_a16w16_quant_x.py Widen partial-write offsets.
gemm/​batched/​batched_gemm_bf16.py Widen partial-write offsets.
gemm/​batched/​batched_gemm_afp4wfp4.py Widen writer and reducer offsets.
gemm/​batched/​batched_gemm_a16wfp4.py Widen writer and reducer offsets.
gemm/​basic/​gemm_afp8wfp8.py Widen both writer variants.
gemm/​basic/​gemm_afp4wfp4.py Widen all three writer variants.
gemm/​basic/​gemm_a8wfp4.py Widen partial-write offsets.
gemm/​basic/​gemm_a8w8.py Widen partial-write offsets.
gemm/​basic/​gemm_a8w8_per_token_scale.py Widen partial-write offsets.
gemm/​basic/​gemm_a8w8_blockscale.py Widen both writer variants.
gemm/​basic/​gemm_a16wfp4.py Widen both writer variants.
gemm/​basic/​gemm_a16w8_blockscale.py Widen both writer variants.
gemm/​basic/​gemm_a16w16.py Widen partial-write offsets.
gemm/​basic/​gemm_a16w16_persistent.py Widen persistent-kernel partial offsets.
fusions/​fused_bmm_rope_kv_cache.py Widen writer and reducer offsets.
common/​splitk_reduce.py Widen shared GEMM and batched reduction offsets.

Review effort: Balanced

@azaidy
azaidy self-requested a review October 21, 2026 14:18
@azaidy azaidy self-assigned this Oct 21, 2026

@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!

@zufayu
zufayu requested review from a team and azaidy October 22, 2026 01:17
@siliangchen-amd

Copy link
Copy Markdown
Contributor Author

Thanks! The two failed MI35X Triton shards died in pip install -r .github/requirements/triton-test.txt (connection timeouts) before any test ran. Could you re-run them? I don't have permission to.

@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!

@azaidy
azaidy merged commit 0e83a83 into ROCm:main Oct 22, 2026
vgokhale added a commit that referenced this pull request Nov 19, 2026
…_afp8wfp8

The bf16x3 kernel had its own copy of the fused split-K code of
gemm_afp8wfp8, without the fallback for torch < 2.10. Now both ops use
one copy:

- _tile_on_xcd and _sum_splits_on_xcd move from the gemm_afp8wfp8 kernel
  file to _triton_kernels/common/splitk_reduce.py, without change.
- The counters and the partials buffer move from the gemm_afp8wfp8
  wrapper to utils/fused_splitk.py. fused_splitk_workspace() returns None
  when the counters cannot be made (first use inside a capture with
  torch < 2.10) or when the arch is not gfx950. Then gemm_a16w32 writes
  the partials and adds them with _gemm_splitk_reduce_kernel.
- The bf16x3 kernel computes the tile count in the kernel. GRID_MN was a
  compile-time value that changed with M, so each M gave a new compile.
- The partial and term offsets are int64: 2 * stride_bt and the partial
  slot offsets overflowed int32 when N * K >= 2**30 (as #6758 did).
- The masked K loads keep cache_modifier.

gemm_afp8wfp8 does not change: the instruction streams of its tile and
packed kernels (fused and unfused split-K) are identical before and after.
README.md and the review instructions name the new shared helpers.

Signed-off-by: Vinayak Gokhale <[email protected]>
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.

3 participants