Repository navigation
[Triton/Gluon] [Bugfix] Compute Triton split-K partial offsets in int64 - #6758
Conversation
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]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
There was a problem hiding this comment.
🟡 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
|
Thanks! The two failed MI35X Triton shards died in |
…_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]>

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 * stridewithpid_k/offs_kand the stride in int32, so the offset wraps once (NUM_KSPLIT − 1) · M · N reaches 2^31. On gfx942,gemm_a8w8_blockscalewith M=4096, N=36864, K=2048 and an explicit 16-way split aborts on main: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.pyrun ofgemm_a8w8_blockscaleon gfx942 lost a worker to this on about 2,800 configs.Change
Cast
pid_k(writers) andoffs_k(reducers) to int64 before scaling by the partial stride, in the Triton kernels under_triton_kernelsthat write or reduce split-K partials: the basic, batched and fused GEMMs,common/splitk_reduce.pyandfused_bmm_rope_kv_cache.py. Row and column offsets were already int64, and the MoE GEMMs and the gfx1250 Gluongemm_a16w16_persistentalready castpid_kthis way.The Gluon kernels under
_gluon_kernels/gfx950and_gluon_kernels/gfx1250computepid_k * stride_ckthe 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)
run_torch: aborts on main, passes with this PR.gemm/basic,gemm/batched,gemm/fused,fusions/test_fused_bmm_rope_kv_cache.py): 3,207 passed. The only failures aretest_gemm_afp8wfp8.py's 320, which fail to compile on main too.PaddedSharedLayout.gemm_afp8wfp8.pydoesn't compile with Triton 3.6 on gfx942 or gfx950, on main or here, so its two lines are untested.Found while tuning the gfx942 configs in #6757.
Powered by Hyperloom, with human review, writing and testing.