Skip to content

[Triton/Gluon] Add gemm_a16w32: bf16 x fp32-weight GEMM (fp32 FMA at small M, bf16x3 MFMA above) - #7770

Merged
vgokhale merged 19 commits into
mainfrom
vinayak/gemm-a16w16x3
Nov 24, 2026
Merged

vgokhale merged 19 commits into
mainfrom
vinayak/gemm-a16w16x3

Conversation

@vgokhale

@vgokhale vgokhale commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR adds gemm_a16w32 to support f32 weights. This is used in some models like Minimax for the moe router. It takes bf16 activations and fp32 weights and returns fp32. At small M it uses fp32 FMA on the fp32 weight, and at larger M it uses bf16 MFMA on three exact bf16 terms of the weight (split_bf16x3()).

Changes

  • Two kernels and one call: gemm_a16w32(x, w, w_bf16x3=None). kernel_type in the config of each M bucket selects the kernel. With w_bf16x3=None, the bf16x3 kernel splits the fp32 weight after each load; with the split given, it reads the split (faster, same bits).
  • fp32 FMA kernel (bandwidth_bound): each program computes BLOCK_SIZE_M rows of the output for one row of W.
  • bf16x3 MFMA kernel (compute_bound): deterministic split-K in the kernel. It uses the fused split-K helpers that it now shares with gemm_afp8wfp8 (_triton_kernels/common/splitk_reduce.py, utils/fused_splitk.py). It compiles once for each config (M is not specialized).
  • Wrapper, unit test (fp64 reference and an exact test), benchmark (--model), gfx950 configs and registration in tuning/kernels.py. The tuner can now sweep the FMA kernel (BLOCK_SIZE_M 1 and 4, BLOCK_SIZE_N 1, only for kernels with vector_tiles=True).

Results (MI355X, N=128, K=6144, us per call, CUDA graph, cold weights)

M 1 8 32 64 256 1024 2047
us 2.45 3.27 5.81 8.17 11.30 18.54 24.67

With the shared split-K (head e8cb39b), the call with the split given is 4% to 15% faster for M of 33 and more: M=64 7.20 us, 256 10.22, 1024 16.13, 2048 22.95, 8192 55.90. M of 32 and less (FMA kernel) does not change.

Testing

  • At head a98b1b9 (main 008d53c merged): pytest op_tests/triton_tests/gemm/basic/test_gemm_a16w32.py: 78 passed. test_gemm_afp8wfp8.py: 453 passed, 274 skipped (MI355X, vLLM nightly image, Triton 3.8). It collects 727 cases, the same as the file on main. Main's [Triton/Gluon] Unify get_shapes for GEMMs #8214 made its shape list shorter.
  • bench_gemm_a16w32.py, and verify_configs.py gemm_a16w32 --expect-tuned at M = 1, 32 and 64: pass.
  • black and ruff 0.16.0: clean.

Limitations

  • Configs exist for gfx950 only.
  • Without the split (w_bf16x3=None), the bf16x3 kernel is up to 27% slower than with it at some M (for example M=8192), because the configs are tuned for the given split. Callers that can keep the split should pass it.

PR Self-Review

Reviewed revision

a98b1b9

Behavior and intent

This PR adds a new op, gemm_a16w32: bf16 activations times fp32 weights, with an fp32 output. MoE routers such as the MiniMax-M3.1 router (128 x 6144) keep fp32 weights. Before, a caller had to cast the activations to fp32 and run an fp32 GEMM, or write a model-specific kernel. At small M the op uses fp32 FMA. At larger M it uses bf16 MFMA on three exact bf16 parts of each weight. No existing op changes. This revision also moves the fused split-K helpers of gemm_afp8wfp8 into shared modules (_triton_kernels/common/splitk_reduce.py and utils/fused_splitk.py); gemm_afp8wfp8 compiles to the same instructions.

Validation and unverified scope

  • pytest op_tests/triton_tests/gemm/basic/test_gemm_a16w32.py at head a98b1b9 (main 008d53c merged; MI355X): 78 passed. At e8cb39b, with the third bf16 term removed from the kernel (a temporary mutation), the old tests pass but 8 new cases fail.
  • test_gemm_afp8wfp8.py: 509 passed and 330 skipped, before and after. The 229 kernels that it compiles have the same instruction streams before and after.
  • For N=128, K=6144 and M from 33 to 8192, the bf16x3 kernel compiles 5 times (before: 144).
  • int64 offsets: with N=131072 and K=8192, the previous head gave a GPU memory fault; this head gives correct results.
  • Tuner: the plans of the other GEMM families are the same before and after (24 family/backend pairs on gfx950, 25 on gfx1250, 14 values of M). verify_configs.py gemm_a16w32 --M 1 --N 128 --K 6144 --expect-tuned passes.
  • Unverified: other architectures (there are only gfx950 configs), N x K shapes other than 128 x 6144 (they use DEFAULT.json), and the full sweep_configs.py runs of the tuning checks.

PR-specific question

Only the new op gemm_a16w32 reads the new config files configs/gfx950/triton/gemm/gemm_a16w32/DEFAULT.json and GEMM-A16W32-N=128-K=6144.json. Calls with N=128 and K=6144 use the tuned file and select one config for each M bucket; other shapes use DEFAULT.json. The new SEARCH_SPACE values go only to kernels with vector_tiles=True (only gemm_a16w32), and the plans of all other families are the same as before, so the tuning of other ops keeps its previous selection.

Changed op tests

  • op_tests/triton_tests/gemm/basic/test_gemm_a16w32.py: new. It tests both kernels against an fp64 reference with a bound of 2^-21 x sum |x w|, an exact test with one power-of-two value in each row of x (it finds a lost third bf16 term), a split-K shape with a K tail (K=6112), the split in the kernel against the given split, and the split_bf16x3() limits. No other test covers this op.
  • op_tests/op_benchmarks/triton/bench_gemm_a16w32.py: new. It counts the bytes that the chosen kernel reads, supports --model, and rotates only the weight that the kernel reads.
  • op_tests/triton_tests/gemm/basic/test_gemm_afp8wfp8.py: only the monkeypatch target changes, to the shared helper in utils/fused_splitk.py. No test case changes.

…ne launch

Some MoE routers keep the gate weight in fp32 (MiniMax-M3.x: 128 x 6144).
This kernel computes Y = X @ W^T in fp32 from a bf16 X and a W that
split_bf16x3() splits into three bf16 terms. The sum of the terms is exactly W.
Each K step loads the X tile once and adds three bf16 MFMA dots into one fp32
accumulator. With split-K, the last split of each tile adds the partials in
split order. Thus the result does not depend on the workgroup order.

- Kernel, wrapper, unit test (fp64 reference) and benchmark.
- gfx950 configs: DEFAULT.json and the tuned N=128 K=6144 file (M <= 256).
- Registration in the tuning scripts (tuning/kernels.py).

Signed-off-by: Vinayak Gokhale <[email protected]>
Get the split-K arrival counters from capture_scoped_cache and
persistent_alloc in aiter.utility.graph_alloc, as gemm_afp8wfp8 does.
Thus a first split-K call inside a CUDA graph capture gets counters for
that graph only. Eager calls and other graphs do not use them.

- Pass None for the workspace and the counters when NUM_KSPLIT is 1.
- Add a test without split-K (small K).
- Add a test where the first split-K call is inside a capture. The graph
  then replays with new inputs, and an eager call follows.
- Skip the tests on archs other than gfx950, which have no configs.
- Add a docstring to the public wrapper.

Signed-off-by: Vinayak Gokhale <[email protected]>
@vgokhale vgokhale self-assigned this Nov 10, 2026
@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 7770 --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.

The config of each M bucket now selects the kernel with kernel_type:
- "bandwidth_bound": a new fp32 FMA kernel that reads the fp32 weight.
  Each program computes BLOCK_SIZE_M rows of the output for one row of W.
  K is a compile-time value, so the trip count of the K loop is known.
- "compute_bound": the bf16x3 MFMA kernel.

gemm_a16w16x3 now takes the fp32 weight and its bf16x3 terms:
gemm_a16w16x3(x, w, w_bf16x3). One call covers every M.

- gfx950 configs: the FMA kernel for M <= 32, in DEFAULT.json and in the
  N=128 K=6144 file. The other buckets do not change.
- Tests: every M from 1 to 33, and the FMA kernel in the repeat, CUDA
  graph and small-K tests.
- Tuning: the sweep times the bf16x3 tiles against the installed FMA
  config, because BLOCK_SIZE_N 1 is not in SEARCH_SPACE.

Signed-off-by: Vinayak Gokhale <[email protected]>
@vgokhale vgokhale changed the title [Triton/Gluon] Add gemm_a16w16x3: fp32-weight GEMM as three bf16 terms [Triton/Gluon] Add gemm_a16w16x3: fp32-weight GEMM (fp32 FMA at small M, bf16x3 MFMA above) Nov 10, 2026
Only git mv. The next commit changes the contents.

Signed-off-by: Vinayak Gokhale <[email protected]>
The op takes bf16 activations and fp32 weights, as the a{act}w{weight}
names of the other GEMMs tell (gemm_a16w16, gemm_a16wfp4). The bf16x3
split is a detail of the MFMA kernel.

- Public op gemm_a16w32, config name GEMM-A16W32 and the tuning entry
  gemm_a16w32. Kernels _gemm_a16w32_fma_kernel and
  _gemm_a16w32_bf16x3_kernel.
- split_bf16x3() and the kernel_type values do not change.

Signed-off-by: Vinayak Gokhale <[email protected]>
@vgokhale vgokhale changed the title [Triton/Gluon] Add gemm_a16w16x3: fp32-weight GEMM (fp32 FMA at small M, bf16x3 MFMA above) [Triton/Gluon] Add gemm_a16w32: bf16 x fp32-weight GEMM (fp32 FMA at small M, bf16x3 MFMA above) Nov 10, 2026
vgokhale added a commit to vgokhale/vllm that referenced this pull request Nov 10, 2026
ROCm/aiter#7770 renamed gemm_a16w16x3 to gemm_a16w32 (bf16 activations,
fp32 weights, fp32 output). Import the new name. No other change.

Signed-off-by: Vinayak Gokhale <[email protected]>
@vgokhale
vgokhale requested review from Boss2002n and azaidy November 11, 2026 00:15
@vgokhale
vgokhale marked this pull request as ready for review November 11, 2026 00:15
@vgokhale
vgokhale requested a review from a team November 11, 2026 00:15
@aiter-bot

aiter-bot commented Nov 11, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision cc6c5db67607 · mode shadow

Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision.

Questions to answer in the PR description

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. Which exact workload keys consume these configuration changes, and what evidence shows that unrelated shapes keep their previous selection?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

vgokhale added a commit to vgokhale/vllm that referenced this pull request Nov 11, 2026
On the ROCm bf16x3 router tier (gfx950, bf16 input, fp32 weight, fp32
output), below MIN_TOKENS (2048) call AITER's gemm_a16w32: one launch
for every M, fp32 FMA at small M and the bf16x3 MFMA kernel above.
2048 tokens and up keep the existing bf16x3 GEMM. When the installed
AITER does not have the kernel (import fails), the previous dispatch
runs: the fp32 Triton kernel up to 32 tokens, F.linear in fp32 above.

MiniMax-M3.1 router (N 128, K 6144), us a call, gemm_a16w32 vs today:
  M 1-32: 2.5-5.8 vs 2.4-6.2 (fp32 Triton kernel; within -17%..+6%)
  M 48 7.9 vs 11.8, 128 9.5 vs 14.6, 512 13.2 vs 22.4,
  1024 18.5 vs 34.4, 2047 24.7 vs 47.3 (F.linear fp32 path)

Needs ROCm/aiter#7770 (gemm_a16w32); without it nothing changes. Router
logits inside GateLinear match fp64 to 5e-9..7e-8 (relative to
sum |x||W|) at M = 1, 8, 32, 33, 512 and 2047, eager and in a replayed
CUDA graph. New device-free test of the dispatch.

Signed-off-by: Vinayak Gokhale <[email protected]>
@Boss2002n
Boss2002n requested a balanced review from Copilot November 11, 2026 02:33

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

Shared arrival counters across captured graphs and missing synchronization before split-K arrival publication can corrupt results during concurrent replay and multi-wave execution.

5 open issues
What changed in this PR

Adds gemm_a16w32 to AITER’s Triton GEMM support for BF16 activations and FP32 weights, including MoE router workloads.

Changes:

  • Adds FP32 FMA for small M and BF16x3 MFMA with deterministic split-K for larger M.
  • Adds the public wrapper, weight decomposition, gfx950 configs, and tuning registration.
  • Adds accuracy, repeatability, graph-capture tests, and a rotating-buffer benchmark.
File Description
op_tests/​triton_tests/​gemm/​basic/​test_gemm_a16w32.py Tests accuracy, shapes, strides, repeatability, and graph capture.
op_tests/​op_benchmarks/​triton/​bench_gemm_a16w32.py Adds latency, throughput, and bandwidth benchmarks.
aiter/​ops/​triton/​utils/​_triton/​tuning/​kernels.py Registers the GEMM family and candidate filter.
aiter/​ops/​triton/​gemm/​basic/​gemm_a16w32.py Adds weight decomposition, dispatch, and split-K workspace management.
aiter/​ops/​triton/​configs/​gfx950/​triton/​gemm/​gemm_a16w32/​GEMM-A16W32-N=128-K=6144.json Adds shape-specific gfx950 tuning values.
aiter/​ops/​triton/​configs/​gfx950/​triton/​gemm/​gemm_a16w32/​DEFAULT.json Provides default gfx950 dispatch and tuning values.
aiter/​ops/​triton/​_triton_kernels/​gemm/​basic/​gemm_a16w32.py Implements the FMA and BF16x3 MFMA kernels.

Review effort: Balanced

…ival

Split-K: one thread adds the arrival of a tile, and the release of that
atomic covers only its own wave. The other waves of the tile could still
have partial stores in flight, so the last split could read old
partials. Now each wave drains its stores (s_waitcnt vmcnt(0)) before a
barrier, and then the arrival is added, as _sum_splits_on_xcd in
gemm_afp8wfp8 does. The sum order does not change, so the results are
bitwise the same. The wait costs 0.1 to 0.7 us (1 to 5 %) at M = 64 to
2048 for N = 128, K = 6144.

Also:
- split_bf16x3 raises ValueError for values that round to inf in bf16
  (|w| >= 2**128 - 2**119). The docstring gives the range where the
  split is exact (2**-110 to that bound), and a test checks the limits.
- Benchmark: a call reads only w (FMA kernel) or only w_bf16x3 (bf16x3
  kernel). Only that weight rotates, and the other one is fixed, so the
  pool size counts only the bytes that the kernel reads.
- Docstring: graphs captured on one stream can share its split-K
  counters.

Signed-off-by: Vinayak Gokhale <[email protected]>
tl.dot in the bf16x3 kernel needs blocks of 16 or more in each dimension.
At M=1 every candidate had BLOCK_SIZE_M 8, so the sweep could not use the
oversized-tile retry. Now the plan at M=1 has only BLOCK_SIZE_M >= 16.

Signed-off-by: Vinayak Gokhale <[email protected]>

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

Must fix before merge

  1. The split-K code is a copy (kernel, wrapper): it is the same code as in gemm_afp8wfp8, but without its fallback for torch older than 2.10. Fix: share one helper in _triton_kernels/common/splitk_reduce.py.
  2. The kernel compiles too many times (kernel): GRID_MN is a compile-time value that changes with M. For N=128, K=6144, M from 33 to 8192 gives 72 compiles instead of 5. Fix: compute GRID_MN inside the kernel.
  3. Large weights read the wrong memory (kernel): 2 * stride_bt and pid_k * M * N are 32-bit and overflow when N × K ≥ 2^30 (for example N=131072, K=8192). Fix: cast to int64, as #6758 did.
  4. The tuner cannot tune the small-M kernel (tuning/kernels.py): SEARCH_SPACE has no BLOCK_SIZE_N of 1 and no BLOCK_SIZE_M of 1 or 4, so the tuner skips every FMA candidate. Fix: add these values.

Nice to fix

  • Make the test tolerance tighter: today a kernel that drops the third bf16 part still passes. Also add one split-K shape where K is not a multiple of BLOCK_SIZE_K (test).
  • Remove about 33 of the 89 test cases; they repeat other cases (test).
  • Split the fp32 weight inside the kernel, as #7832 does, so callers do not keep a second copy (w_bf16x3) (wrapper).
  • Benchmark: count the bytes that the chosen kernel really reads, support --model, and do not import from _triton_kernels/ (bench). Also keep cache_modifier on the masked K loads, and show the bad values in the assert messages.

…_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]>
SEARCH_SPACE had no BLOCK_SIZE_N of 1 and no BLOCK_SIZE_M of 1 or 4, so
should_skip rejected every candidate of the fp32 FMA kernel and the sweep
could not tune the small-M buckets.

- SEARCH_SPACE gets BLOCK_SIZE_M 1 and 4 and BLOCK_SIZE_N 1.
- These values are vector tiles (below MIN_DOT_TILE, 8). Only a kernel
  with vector_tiles=True gets them. gemm_a16w32 sets it. So the other
  families keep the candidate lists that they had.
- should_skip of gemm_a16w32 admits FMA candidates with BLOCK_SIZE_N 1,
  no split-K and no tile swizzle. It rejects an FMA candidate whose
  BLOCK_SIZE_M x BLOCK_SIZE_K fp32 sum is more than 256 values per thread.

The plans of the other families do not change: build_space gives the same
candidate values and the same configs for the other 24 (family, backend)
pairs on gfx950 and 25 pairs on gfx1250, at 14 values of M from 1 to 8192.
AGENTS.md and README.md tell the new rule.

Signed-off-by: Vinayak Gokhale <[email protected]>
Triton made a second variant of each config for the values of M that are
a multiple of 16. M only masks the rows of the last tile, so the bf16x3
kernel does not specialize on it now.

For N=128, K=6144 and each M from 33 to 8192, the bf16x3 kernel compiled
144 times before this series (72 GRID_MN values, each twice), 10 times
with GRID_MN in the kernel, and 5 times now: one compile for each config.

Signed-off-by: Vinayak Gokhale <[email protected]>
…16x3 optional

The bf16x3 kernel needed the terms (3, N, K) from split_bf16x3, so callers
kept a second copy of the weight, 1.5 times its size. Now the kernel can
read the fp32 weight and split each loaded tile into the three bf16 terms,
with the rounding of split_bf16x3 (as the router of #7832 splits its fp32
weight). The kernel picks the path from the dtype of the weight pointer.

w_bf16x3 is now optional, so gemm_a16w32(x, w) works. vLLM calls
gemm_a16w32(x, weight, weight_split): that call still works, and the kernel
reads the given terms, because that is faster. Both paths give the same
bits: same terms, same order of the dots. A test checks it at M 1, 33,
256, 2048 and 4096.

Bench (graph timing, cold weights, N=128, K=6144, gfx950, median of 3
runs in one session, us):

    M      before  given terms  split in kernel
    1-32   fp32 FMA kernel, not changed: within 1% (2.6% at M=8)
    33       7.66     6.95          7.79
    64       8.19     7.20          8.08
    128      9.23     8.13          9.03
    256     11.18    10.22         12.08
    512     13.02    11.11         12.69
    1024    17.97    16.13         19.71
    2048    23.92    22.95         23.94
    4096    48.05    44.41         45.69
    8192    58.54    55.90         74.15

"before" is the head of the PR, which needs the terms. The faster column
of the given terms comes from the shared split-K of the earlier commit.
The split in the kernel loads 4 bytes for each weight value, not 6, but
the warps that share a weight tile all split it, and the configs are tuned
for the given terms. So the kernel reads the terms when it gets them.

Without w_bf16x3, the bf16x3 kernel has the limits of split_bf16x3: exact
for 2**-110 <= |w| < 2**128 - 2**119, inf or NaN at or above that limit.
A probe with one-hot rows showed the same exact range for both paths.

Signed-off-by: Vinayak Gokhale <[email protected]>
…peated cases

- _check bounds each output by 2**-21 sum_k |x w|, not a global bound of
  4e-6 max sum_k |x w|: about 8 times tighter. The kernels stay below
  2**-21.9 of it at K = 96 and below 2**-23.6 at K >= 3072.
- A new exact test gives each row of x one value, a power of two. Then each
  output is that value times one weight, exact in fp32, and the test asks
  for the same bits. A kernel that drops the third bf16 term fails it (and
  _check fails at K = 96). A lost third term gives errors of 2**-22.7 sum
  |x w| or more, which a tolerance cannot tell from the fp32 rounding at
  large K.
- A split-K shape with a K tail: K = 6112 is not a multiple of BLOCK_SIZE_K.
- A graph capture test without counters: the partials go to the reduce
  kernel, as with torch < 2.10.
- The assert messages show the bad values.
- Removed 32 cases that repeat other cases:
  - test_gemm_a16w32_small_m ran each M from 1 to 33 (33 cases). M 1, 3,
    16, 32 and 33 are in test_gemm_a16w32. M 2 and 4 run the same compile
    and code path as M 3 (BLOCK_SIZE_M 1). M 13 to 31 repeat the
    remainders M % 4 and the compile of M 9 to 12 (the M_LEQ_32 config is
    the M_LEQ_16 config). It keeps M 5 to 12 (8 cases).
  - test_gemm_a16w32_repeats_bitwise: M 1, 8 and 32 run the FMA kernel,
    which has no split-K state to go stale. M 64 has the config and the
    split count of M 33. It keeps M 33 and 128.
  - test_gemm_a16w32_in_graph_capture: M 32 is the FMA kernel as M 1, and
    M 64 has the config of M 33. It keeps M 1 and 33.
  - test_gemm_a16w32_allocates_y_and_takes_strided_x: M 31 is the FMA
    kernel as M 1. It keeps M 1 and 512.

Signed-off-by: Vinayak Gokhale <[email protected]>
… kernel import

- The bandwidth counts the weight that the chosen kernel reads: the fp32
  weight for the FMA kernel and for the split in the bf16x3 kernel, the
  bf16 terms when the call gives them (--w-split, as vLLM calls the op).
  That weight rotates. A weight that the kernel does not read is fixed.
- --model benchmarks the MoE router GEMM of the models with num_expert in
  model_configs.json: N is num_expert, K is hidden_size. -M selects one M.
- The bench gets the kernel choice from get_gemm_config in utils/, not
  from _triton_kernels/.

Signed-off-by: Vinayak Gokhale <[email protected]>
should_skip_generic rejected num_stages 1 when a candidate has several K
steps, because Triton pipelines a dot kernel then. The fp32 FMA kernel has
no tl.dot, and its installed configs use num_stages 1, so the sweep could
not find them again. A vector BLOCK_SIZE_N (below MIN_DOT_TILE) now keeps
both num_stages values. Only gemm_a16w32 has vector tiles, so the other
plans do not change: build_space gives the same candidates and configs for
the other 24 (family, backend) pairs on gfx950 and 25 on gfx1250 at 14
values of M, and harness --plan is the same for gemm_afp4wfp4_preshuffle
and gemm_a16w16. At M 1, 8 and 32, the installed FMA config is in the plan
now.

Signed-off-by: Vinayak Gokhale <[email protected]>
The README's shared-helpers table names the new helpers. Leave .github out of
this PR.

Signed-off-by: Vinayak Gokhale <[email protected]>
@vgokhale

Copy link
Copy Markdown
Contributor Author

Thank you for the review. The changes are in a19b318 to e8cb39b.

Must fix

  1. Split-K copy: fixed in a19b318. _tile_on_xcd and _sum_splits_on_xcd moved to _triton_kernels/common/splitk_reduce.py without change. The counters and the partials moved to utils/fused_splitk.py, with the fallback for torch < 2.10. Both ops use them. Without counters, gemm_a16w32 writes the partials and uses _gemm_splitk_reduce_kernel. gemm_afp8wfp8 does not change: its tests give 509 passed and 330 skipped before and after, and the 229 kernels that its tests compile have the same instruction streams.
  2. Compiles: fixed in a19b318 and 55bc1f4. The kernel computes the tile count now, and it does not specialize on M. For N=128, K=6144 and M from 33 to 8192, the bf16x3 kernel compiles 5 times now, one time for each config. Before, it compiled 144 times.
  3. int64: fixed in a19b318. The term stride and the partial offsets are int64 now. With N=131072 and K=8192, the old code gave a memory fault. The new code gives correct results.
  4. Tuner: fixed in 465c4b6 and 2989271. SEARCH_SPACE has BLOCK_SIZE_M 1 and 4 and BLOCK_SIZE_N 1 now. Only a kernel with vector_tiles=True gets these values, so the plans of the other families do not change: I compared the plans of all families before and after, and only gemm_a16w32 changes. The FMA candidates keep num_stages 1. The plans include the installed FMA configs.

Nice to fix

  • Test tolerance: fixed in 8739854. The bound of each output is 2^-21 x sum |x w| now, about 8 times tighter. At large K, a tolerance cannot find a lost third term, because its error is near the fp32 rounding. So a new test puts one power-of-two value in each row of x and asks for the same bits. With the third term removed, all old cases pass, but 8 new cases fail. I also added a split-K shape with K = 6112.
  • Repeated cases: done in 8739854. I removed 32 cases. The commit message names each case and the case that covers it.
  • Split in the kernel: done in 84d0a01. The kernel splits the fp32 weight after each load, with the rounding of split_bf16x3. w_bf16x3 is optional now, and the old call works. When a caller gives the terms, the kernel reads them, because that is 3% to 33% faster at N=128, K=6144. Both paths give the same bits.
  • Benchmark: fixed in f055732, a19b318 and 8739854. The bench counts the bytes of the weight that the kernel reads. It supports --model (N is num_expert, K is hidden_size). It gets the config from utils/. The masked K loads keep cache_modifier. The assert messages show the bad values.

With the shared split-K, the call with the split given is 4% to 15% faster than before for M of 33 and more.

Bring in main 008d53c. It has #8313, the fix of
tests/test_ar_rmsnorm_routing.py that failed in the 1-GPU CI job.
There are no conflicts.

Signed-off-by: Vinayak Gokhale <[email protected]>

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

@vgokhale
vgokhale merged commit 76c1d87 into main Nov 24, 2026
66 of 67 checks passed
@vgokhale
vgokhale deleted the vinayak/gemm-a16w16x3 branch November 24, 2026 15:23
amd-bishwoadhikari pushed a commit to amd-bishwoadhikari/aiter that referenced this pull request Nov 24, 2026
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