Skip to content

[HIP] [CK] [FlyDSL] [gfx1250] K3 TP1 a8w8 GEMM: compute N tail, underfilled tiles, aligned A-scale loads, retuned rows - #8778

Open
aoli26 wants to merge 44 commits into
mainfrom
gfx1250/k3-tp1-flydsl-fp8-gemm
Open

aoli26 wants to merge 44 commits into
mainfrom
gfx1250/k3-tp1-flydsl-fp8-gemm

Conversation

@aoli26

@aoli26 aoli26 commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Kernel and table work for the Kimi-K3 TP1 / DSpark mxfp8_128 a8w8 GEMMs on gfx1250, on top of #8246. Against the base (#8246 code, #8601 table, open DSpark rows) the K3 decode step is 1-20% faster, the prefill step 6-8% and the DSpark step 2-54%.

Motivation

With #8246 and the table PRs #8586 / #8601 no K3 TP1 GEMM reaches the 7-8 PF/s target. The compute kernel could not serve N=49408 / N=2176 or M below its tile, an A-scale row that starts off a 4-byte boundary stalls its TDM load (+24-40%), the generic kernel refills the instruction cache on every kernel switch, and rows that win an isolated A/B can lose inside the step.

Changes

  • Compute kernel: N tail (bounded_n), N may end inside the last tile group; spare tiles are clamped to the last real tile.
  • Compute kernel: M below tile_m is a legal tile for tuned rows (replaces the guard of [Fix][Perf] Guard underfilled MXFP8 compute tiles and tune K3 TP1 DSpark #8566); the untuned fallback still does not pick it.
  • Compute kernel: a_scale_unaligned variant, chosen by the wrapper from the x_scale address and row stride; aligned launches keep identical ISA.
  • Compute kernel: cleanup, 1977 -> 1580 lines, ISA unchanged.
  • Generic kernel: fused split-K reduces on split 0 when the row-stripe epilogue does not fit (split_k up to 16). When split_k does not divide the K tiles, a split one tile short counts its loop cluster barriers one tile ahead, so every split of a cluster takes the same number of them.
  • Generic kernel: prefetch the first 16 KiB of its code after the first loads (mx128, mx32, batched, PTPC).
  • Tuner: rank0 split-K, clusters of 3 / 5 M tiles, tile_m 96 / 160 / 192 and N-tail candidates, appended with kernelIds unchanged; the untuned fallback picks by tile cost (1.72x geomean over 611 untuned shapes).
  • Tables: K3 TP1 rows for 13 shapes at decode and prefill M, decided inside the step (205 rows change kernel, 563 added); 82 DSv4 rows move to a faster kernel. Every changed row was timed against the base row over each padded-M block it serves, including M 8193-16383 that an 8192 row serves when N > 4096: 5 rows were replaced where a block was slower, 4 guard rows added (12288x1536, M 1088-1280), 2 rows went back to the base kernel, and the us of 114 rows were re-measured (median of 5 tuner runs).
  • Add a gfx1250 K=128 N sweep to the MXFP8 tuner, public dispatch and AOT replay. It reuses each tile of A across up to 12 N tiles. Of the 42 K3 rows at N=12288, K=128, 12 select the sweep. The table keeps all 866 keys.

Performance (if applicable)

Step proxy: all a8w8 GEMMs of one step in one CUDA graph, per-layer weights, 4 process runs per side. Before = #8246 code with the #8601 table plus the 16 DSpark rows of #8566 / #8672 / #8677 / #8705 / #8706 / #8709 / #8710 / #8711. Over all measured M: decode -1.2% to -19.9%, prefill -6.2% to -7.5%, DSpark -1.5% to -53.6%.

Hardware Workload/configuration Before After Change
gfx1250 K3 decode step, M=120 4.48 ms 4.00 ms -10.6%
gfx1250 K3 decode step, M=160 5.73 ms 4.83 ms -15.7%
gfx1250 K3 decode step, M=250 6.83 ms 5.48 ms -19.9%
gfx1250 K3 decode step, M=320 7.87 ms 7.78 ms -1.2%
gfx1250 K3 decode step, M=475 10.11 ms 8.70 ms -14.0%
gfx1250 K3 decode step, M=640 12.55 ms 11.50 ms -8.3%
gfx1250 K3 decode step, M=960 15.28 ms 14.09 ms -7.8%
gfx1250 K3 prefill step, M=2048 37.74 ms 34.91 ms -7.5%
gfx1250 K3 prefill step, M=4096 69.01 ms 64.03 ms -7.2%
gfx1250 K3 prefill step, M=8192 133.23 ms 124.91 ms -6.2%
gfx1250 K3 prefill step, M=16384 262.39 ms 244.94 ms -6.7%
gfx1250 DSpark step, M=96 2.17 ms 1.01 ms -53.6%
gfx1250 DSpark step, M=128 1.07 ms 0.99 ms -7.4%
gfx1250 DSpark step, M=252 1.70 ms 1.52 ms -10.4%
gfx1250 DSpark step, M=512 2.07 ms 2.04 ms -1.5%
gfx1250 DSpark step, M=768 3.08 ms 2.75 ms -10.8%

Measured at ea7a5d8. The subsequent row changes through 204ce9d are outside these steps or within noise (q_b M 241-256 back to the base kernel: within +-0.4% in the decode step). Merging main changes no kernel binary: the step proxy before and after the merge differs by -0.7% to +0.8%, in both directions. Syncing with #8246 fd79db6 moves the step proxy by -1.0% to +1.1% (the #8737 flush adds up to about 1% on decode M that run many generic kernels); the five rows it brings are 8-35% faster over the M they serve.

For the K3 single GEMM at M=16384, N=12288, K=128 with BF16 output, eight paired graph timing rounds with 192 rotating weights measured 44.51 µs on 204ce9d and 23.61 µs with the sweep (+88.5% throughput). Across 782 tested M values, 607 selected the sweep. Three-seed paired medians improved for 592 of them, with a maximum throughput loss of 0.52% among the other 15. The step timings above predate the sweep.

Testing

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X
  • Tested on MI300X

Documentation

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

docs/flydsl_aot_cache.md documents the K=128 sweep specialization key and the layout and dtype variants built from a tuned row.

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

Stacked on #8246 (open), which must merge first. Synced with #8246 at 0d6cf15 (merged here): main's #8737 LDS flush before the TDM C store with #8246's port to the fused split-K epilogue, the pinned untuned-fallback picks, the re-measured us of #8246's rows, five faster rows (DSv4 4096x8192 M 16 / 32 / 64, K3 8448x7168 M 160, 1536x7168 M 544), and the bound that keeps split_k 2 output stripes of 4 GiB or more off the 32-bit lean epilogue (rank0 on the generic kernel, unfused on the compute and PTPC kernels; rank0 is in the generic specialization_key). Table rows whose kernel this PR changed or added stay as tuned here. The #8678 AOT-cache launchers are wired as in #8246: the launches go through gemm_a8w8_launcher.lazy() / _gemm_a8w8_compute_bound_launcher.lazy(), and the compute launch keeps bounded_n and a_scale_unaligned in its specialization_key. Contains the table PRs #8579, #8586 and #8601 (drafts on #8246) as merge commits. Builds on the merged #7868 and #8566. The DSpark row PRs #8672, #8677, #8705, #8706, #8709, #8710 and #8711 are not required and not included; they are only part of the "Before" baseline.

Breaking Changes

The gfx1250 2D MXFP8 blockscale path now raises ValueError for layouts its kernel descriptors cannot represent. For out=, use a unit column stride and non-overlapping rows. Row padding is supported. The previous path could overwrite gaps in a strided output view.

PR Self-Review

Reviewed revision

2dbfad4

Behavior and intent

A tuned compute row now serves M below its tile_m and an N that ends inside its last tile group instead of falling back to a generic kernel; a launch with unaligned A-scale rows loads them from the aligned floor; the generic kernel prefetches its code and can reduce fused split-K on split 0, with the same number of cluster barriers in every K split. Without these the K3 TP1 / DSpark step is 1-54% slower.

At K=128, the tuned K3 rows use the caller's true M to bound the final tile even when dispatch looked up a padded M. FP16 output, preshuffled A and row-padded output use the generic kernel for these rows.

Validation and unverified scope

At 2dbfad4 on gfx1250 with 256 CUs, ENABLE_CK=0 python3 op_tests/test_gemm_a8w8_blockscale.py --flydsl passed both K=128 regressions and all 54 default benchmark cases. The no-argument entry also ran both regressions before reaching the legacy benchmarks. A full no-argument run on the parent stopped at the FP32-scale ASM comparison, which has no gfx1250 kernel.

Four focused pytest cases passed, including validation of all 866 K3 kernel IDs against both catalogs. The 42-row K=128 CSV sweep passed with both input distributions. A custom 65x1664x128 row also selected its requested sweep.

The K=128 tests ran on gfx1250 with 256 CUs at revision e9906a1.

  • python3 op_tests/test_gemm_a8w8_blockscale.py --flydsl --w-scale-block 128x128 -m 16384 -nk 12288,128 passed. Scanning the same production table passed all 42 M values with both constant and random inputs. The tuner verified all 42 rows and timed 210 candidates across two shapes.
  • 2,924 geometry cases passed 5,848 guarded launches. Unmapped guard pages, output larger than 4 GiB, concurrent graph replay, event handoffs and concurrent first launches also passed.
  • Fresh AOT prebuild and check each passed 90 jobs. Verify and run-only each loaded 25 objects with zero JIT fallbacks. Three targeted pytest cases passed. The broader group32 and AOT replay suites had four and two failures respectively, also reproduced on 204ce9d.
  • Full-tree Black 26.10.1 and Ruff 0.16.0 checks passed, as did git diff --check.
  • One AOT audit reported a GPU page fault while the host was allocating a PyTorch reference result, before submitting the M=16257 GEMM. The faulting GPU instruction is unknown. Two unchanged repeats, CPU-reference verification and four-stream AOT replay passed.

Earlier PR validation ran on gfx1250 with 256 CUs at 204ce9d unless noted.

  • Op tests: op_tests/test_gemm_a8w8_mxfp8_bpreshuffle.py 120 passed (default mode, and on prebuilt AOT entries in verify mode; 118 on fewer shapes with the AOT cache off), op_tests/test_gemm_a8w8.py --no-flydsl-csv --no-legacy (PTPC fused split-K case) passed, batched a8w8 op test 137 passed (fused quant bit-exact), op_tests/test_gemm_host_dispatch_cache.py 40 passed, tuning config collision / CSV tests 53 passed, tests/test_flydsl_aot_launch.py + tests/test_flydsl_aot_cache.py 32 passed.
  • AOT: K3 and DSv4 tables prebuilt (390 entries) and --check pass; tuner --run_config on the prebuilt cache in verify mode: K3 866 and DSv4 211 rows OK, none fell back to the JIT path. The base, DSv4.1, MiniMax-M3 mxscale tables and the PTPC table also prebuild and --check (878 replays, 0 failed).
  • Output row strides past the 32-bit range (Out stripes of 8 GiB): the split_k 2 fused launches of the generic, compute and PTPC kernels wrote wrong rows at c99781c (40 of 40, 200 of 200 and 17 of 33) and none here. 20 more large-stride cases are correct: split_k 4 row-stripe, rank0, plain, and this PR's compute paths (N tail, ps2, M below the tile, unaligned A scale, tile_m 160) with tile spans up to 8 GiB.
  • [FlyDSL] Work around gfx1250 LDS-to-TDM store corruption #8737 (at c99781c; concurrent graph replay, [FlyDSL] [Bugfix] gfx1250 FP8 GEMM: store C from registers / LDS read-back, not a TDM store from LDS #8486 reproducer adapted to mx128, 90 s per kernel): the row-stripe fused split-K kernel gave 11 bad replays before the sync and 0 after; rank0, an sk1 cluster kernel and three compute kernels gave 0. The compute kernels have no flush, as on main.
  • ISA: 0d6cf15 changes no kernel: all 333 compute and 479 of 480 generic specializations the tables reach are identical to c99781c (the other one compiles nondeterministically on both sides). At c99781c the generic kernel's source change was exactly [HIP] [CK] [FlyDSL] [gfx1250] Fused split-K for the generic a8w8 GEMM; retune K3 mx128 rows #8246's merge change (the [FlyDSL] Work around gfx1250 LDS-to-TDM store corruption #8737 flush), and all 20,443 generic catalog candidates fit LDS with the flush area.
  • Uneven K splits (at 167b242): 115 tuned rank0 rows x 4 runs (13,800 launches) and 204 synthetic uneven-split kernels (21,960 launches) bit-equal to the previous barrier schedule, no hang.
  • Stress: ragged M, output and scratch out-of-bounds and replay races on 186 kernel x shape entries, including the five new rows (8,500 ragged runs, 37,200 replays), 0 failures; 403 runs with inputs ending at the end of a mapping, no fault.
  • Tables: every changed row was swept against the base row over each padded-M block it serves (at 167b242); the five rows from [HIP] [CK] [FlyDSL] [gfx1250] Fused split-K for the generic a8w8 GEMM; retune K3 mx128 rows #8246 were swept again at c99781c.
  • Earlier, at ea7a5d8: cleanup ISA identical on 193 GPU-traced and 633 compile-only specializations, 52/52 outputs bit-equal; generic prefetch A/B on 664 tuned rows of the mx128, mx32, PTPC and batched tables, outputs bit-equal, family geomeans -0.1% to -0.6%.
  • black, ruff, git diff --check pass.

Unverified: not tested on MI250X / MI300X (gfx1250-only paths); no end-to-end model run; generic rows above 33 us not A/B tested. At 204ce9d, tests/test_flydsl_aot_replay.py had 3 failures that clean main had too (the sandbox does not allow signalling its pool workers). Known regression: DSv4.1 5120x2304 at M=1 / M=3, +1.3-2.6% / +0.6-1.4% back to back.

PR-specific question

Which architecture, dtype and shape boundaries select the changed kernel path, and what invariant prevents unsupported inputs from reaching it?

Only gfx1250 rows and wrappers reach these kernels, with FP8 E4M3 inputs and E8M0 block scales. Tuned rows and the untuned fallback both pass kernel_fits_shape: an underfilled M tile needs cluster_m 1, the fallback also needs M >= tile_m for compute kernels, the N tail needs split_k=1, and split_k > 1 is fused only. Partial tiles bound their TDM loads and C stores, so no access leaves the tensors. The csrc/ changes are the two tuner scripts, which filter candidates with the same predicate.

The K=128 sweep consumes (16,16)-preshuffled weights with 128x128 E8M0 weight scales. Before launch, the wrapper checks that M is positive, N is a positive multiple of 128, the operands are contiguous and 16-byte aligned, and the output dtype is BF16.

Changed op tests

  • op_tests/test_gemm_a8w8_mxfp8_bpreshuffle.py: test_mx128_kernel_direct launches the N-tail, underfilled-M and unaligned-A-scale compute tiles (BOUNDED_CASES); test_fused_splitk*, test_untuned_fallback_pick and test_tuner_catalog cover the fused split-K kernels (uneven K splits with 3 and 4 buffers among them), the fallback choice (including [HIP] [CK] [FlyDSL] [gfx1250] Fused split-K for the generic a8w8 GEMM; retune K3 mx128 rows #8246's pinned picks at 256 CUs) and the appended catalog. The ID check covers both the generic and K=128 sweep catalogs and rejects overlapping ID ranges. test_fused_splitk_large_row_stride (from [HIP] [CK] [FlyDSL] [gfx1250] Fused split-K for the generic a8w8 GEMM; retune K3 mx128 rows #8246) launches a split_k 2 kernel with a 2^29 Out row stride; reduce launches are counted through splitk_reduce_launcher.lazy. None of these kernels or choices exists before this PR.
  • op_tests/test_gemm_a8w8.py (from [HIP] [CK] [FlyDSL] [gfx1250] Fused split-K for the generic a8w8 GEMM; retune K3 mx128 rows #8246): a PTPC fused split-K case checked against FP32, its unfused twin and graph replay, with no reduce kernel launched.
  • op_tests/test_gemm_host_dispatch_cache.py: test_mxscale_compute_row_serves_underfilled_m_tile asserts the lookup returns the tuned compute row for M below its tile; it replaces the tests of the [Fix][Perf] Guard underfilled MXFP8 compute tiles and tune K3 TP1 DSpark #8566 guard, which this PR removes.
  • op_tests/test_gemm_a8w8_blockscale.py exercises the public allocating and buffered paths through the existing 128x128 CSV and MNK runner. A ragged M=79 must reach the sweep launcher. Non-unit output column strides and overlapping output rows must raise before writing the backing storage. The default gfx1250 script runs the stride checks and, on the 256-CU K3 target, the sweep dispatch check. Explicit MNK and CSV runs retain their shape selection.

aoli26 and others added 30 commits November 18, 2026 07:52
A compute GEMM that runs right after another compute specialization is
1.2-1.7x slower: its code was evicted from the CU's instruction cache, and
s_prefetch_inst is a no-op while MODE.SCALAR_PREFETCH_EN is clear, which is
how waves start once the program was preloaded on the WGP.

Set the bit at kernel entry and prefetch the kernel's code (up to 56 KiB,
split across the waves). Output is unchanged. The new test runs two compute
kernels alternately and checks the cost stays within 10% of running them
back to back.
Two a4w4 compute kernels run alternately cost 1.5-2.2x of back to back,
for the same reason as the a8w8 ones: their code does not fit the
instruction cache together. Call prefetch_kernel_code at the entry of
kernel_gemm_a4w4_256x256.

A launch holds up to three kernels (tail_mode 2, 0, -1), so
prefetch_kernel_code takes the kernel's position in its module and uses
it for its label and .Lfunc_end. a8w8 keeps index 0 and its code objects
are unchanged.

Add test_compute_switch_penalty to test_gemm_a4w4.py. It runs only when
FlyDSL is installed, and checks each kernel's output against the
reference before timing. The a8w8 switch test in
test_flydsl_batched_gemm.py gets the same check, sharing its reference
with the compute cases.
…ill rows

- Key bounded_m only for fused split-K, its only reader.
- From 4 M-tiles per cluster row (split_k 1), pad grid.x to whole cluster
  rows instead of falling back to a smaller cluster_m; padded workgroups
  load and store zero rows. 1x32 and 128x128 rows keep the fallback.
- Restore the DSv4.1 Flash 32x32 M=16384 rows; add M=8192 compute rows for
  O-B, shared gate/up and down, and Engram (it serves M in (4096, 16256]).
- Pass the cluster_m that fits M as a launch argument (i32_cm) to the
  a8w8 and a4w4 compute kernels and the a4w4 general kernel, instead of
  compiling one variant per fitted cluster_m. A launch of one workgroup
  runs the plain kernel (use_cluster False). Kernel symbol names lose
  _cm; tuned kernelNames are unchanged.
- Drop the a8w8 padded grid for the cluster_m fallback: the tuned
  cluster_m if it tiles M, else the largest power of two that does
  (cm=3 fits measured worse).
- Drop bounded_m: the fused split-K epilogue always stores through the
  buffer descriptor.
- AOT: update the docs and comments for the above.
- test_flydsl_batched_gemm.py: use get_gfx_runtime in
  test_compute_switch_penalty. test_gemm_a4w4.py: add off-grid shapes
  for the shrunk clusters.
…luster_m

The generic a8w8 kernel (mx128, mx32, ptpc) reduced split-K through an FP32
plane per split and a separate reduce kernel. With fused_splitk the K splits
of a tile are one cluster along grid.z and reduce through the shared fused
epilogue, as the compute and a4w4 kernels already do; the sum stays in FP32
and in split order, so the output is bitwise equal to the unfused path.

- cluster_m is a launch argument (use_cluster + i32_cm) like the compute
  kernel, so one binary serves every M; kernel symbols drop _cm and gain
  _fsk / _plain.
- The epilogue helper handles tiles with fewer than one thread pass of
  reduced rows (small tile_m / split_k); its other paths are unchanged.
- mx128/mx32, ptpc and the batched entries call the new signature; the ptpc
  kernelName parser reads _fsk. fused_splitk_ok and fused_splitk_partial_shape
  are shared by the entries.
…d ptpc

Every split_k > 1 candidate gets a fused twin (_fsk) appended at the end of
kernels_list, so existing kernelIds keep their kernels. The mx128 and ptpc
tuners keep split_k > 1 only as fused; the runtime fallback heuristics are
unaffected because ties still pick the earlier split_k 1 candidate.
…28 and mx32 GEMM

Each case runs the unfused kernelName and its _fsk twin on a NaN-filled
output: the bytes must match, the fused launch must skip the reduce kernel,
the result must match an FP32 reference, and a CUDA graph replay must give
the same bytes. Cases cover split_k 2/4/8, a one-row tile and clusters along
M and N, at ragged M.
…ider cluster space

Widen the mx128 tuner candidates (fused split-K, generic clusters, compute 1x1 and
power-of-two clusters; appended so existing kernelIds are unchanged, and fused
clusters are capped at 16 workgroups) and retune the K3 a8w8 mxscale table: 64 rows
changed and 130 added. Shared DSv4 keys are updated where the new kernel is faster.
Rows that were slower in two independent sweeps stay on their old kernel.
… reference in the fused test

The shared fused epilogue wraps peer stripes with `& (split_k - 1)`, which mixes
output rows for split counts that are not a power of two (e.g. 3 gave a wrong
result at M=48, N=128, K=1536). fused_splitk_ok now accepts only 2/4/8 splits, so
other counts take the unfused reduction. test_fused_splitk now fails on a mismatch
with the FP32 reference instead of only logging it.
The fused epilogue stores whole passes of rows_per_iter * unroll rows, so a stripe that
is not a whole number of passes leaves its tail unwritten: a 192x256 tile with two
splits wrote 64 of 192 rows. fused_splitk_ok, and the matching check in the generic
kernel, now require a whole number of passes, so such configs take the unfused
reduction. None of the tuner candidates or tuned rows changes legality. Add a
regression for the 192x256 tile.
…rnel set

The fallback for shapes without a tuned row (_flydsl_mxfp8_fallback_kernel) iterated
kernels_list, so the widened tuner candidates changed its pick: on 15572 sampled untuned
shapes 8004 chose a different kernel than on main, 30% of those more than 3% slower.
Iterate only the original unfused kernels (fallback_kernels()), the leading part of
kernels_list; the tuners keep the full list. The picks equal main's on 15572 + 13020
sampled shapes and on the K3 batched shapes.
…inst tile_n*cluster_n in the ptpc wrapper

The fused epilogue sizes its load batch per 128 threads, so a two-wave block divided by zero while tracing; fused_splitk_ok and the kernel guard now refuse it and the dispatch falls back to the unfused launch. The ptpc wrapper only checked N against tile_n, so a cluster along N could be launched on a grid.y it does not divide; it now checks N against tile_n*cluster_n like the mx128/mx32 wrapper.
…load, nlb twin, sk1 op_tests, table rows

- Opt-in mxscale quadrant schedule (_qe) and its tuned K3 rows: 2176x7168 M=512, 7168x1536 M=320 (sampled Q1 -4.5% to -5.3%).
- Opt-in no-loop cluster barrier (_nlb): 1536x7168 M=320 takes the _qe_nlb_fsk twin (sampled Q1 -3.7% to -4.2%).
- LDS row pad for the fused split-K epilogue (K3 rows up to M=240).
- 2304x1536 M=16384 row to the cm2 compute kernel (sampled Q1 about 0.81; public entry M=14848..16384 passes).
- 7168x1536 M=512 row kept at its pre-landing cm8 form (sampled Q1 -0.9%, below the 3% rule).
- op_tests: explicit-name sk1 mx128 check.
- Squashed from 10 local commits (6f4558777..cd5e11f9a); this commit is local only and is not pushed.
Conflicts resolved:
- aot/flydsl README and gemm.py: take main's wording (compute kernel).
- splitk_fused_epilogue_gfx1250: keep main's stripe_rows cap (rows past M can exceed 4 GiB per stripe) in the lean output descriptor, and keep the idle-row path (rows_per_iter > reduce_m) and the _store helper from this branch. Both branches removed bounded_m; the store branches are identical.
…x32 modes, tighten tests

- Untuned fallback: iterate fallback_kernels() with the original ranking again, so
  shapes without a tuned row keep main's picks; the tile-cost rule leaves this PR.
- mx32 entry forwards c_pad, quad_early and no_loop_cbar like the mx128 entry.
- no_loop_cbar is rejected for compute kernels and for clusters along M or N.
- Batched candidates skip the opt-in schedules, which the batched launch lacks.
- Dispatcher computes use_cluster once for both kernel paths.
- Tests: zero-mismatch asserts against the FP32 reference; _cp4 / _qe_nlb fused
  cases and the sk1 _qe rows (test_mx128_kernel_direct) run from main; the
  fallback test pins main's picks.
- Black formatting and shorter comments.
… f_b

Kimi-K3 runs its attention at TP1 on the DP8EP8 decode node (DP attention),
so every rank reads the full N x K weights. The tuned table only held the
power-of-two M rows of these shapes, so M = 315 ran the M = 512 tile,
M = 640 the M = 1024 tile, and f_b (12288 x 128) had no row at all.

Rows for the decode buckets M <= 640 of seven TP1-only shapes:
kda_in_proj 49408x7168, o_proj 7168x12288, mla_gate / shexp_gate_up
12288x7168, kda_f_b 12288x128, shexp_down 7168x6144, dense FFN
67584x7168 and 7168x33792. 81 rows added, 12 replaced.

Every candidate of the #8246 space that launches over the whole bucket was
timed with cold weights (rotating copies >= 2 GB) as CUDA-graph replays.
The top candidates were then re-timed against the kernel the runtime picks
today in 7 interleaved rounds. A row is written only when its median paired
ratio is <= 0.97 and every round is faster.

Public entry, M = 1..1024 on all nine K3 TP1 shapes: errRatio <= 0.017 vs
the FP32 reference and graph replay bitwise equal to eager.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
mla_qkv_a 2176x7168 and mla_q_b 18432x1536 have the same N and K at TP1 and
TP8, so these rows also change the TP8 decode picks of #8246's retune.
They come from the same cold-weight CUDA-graph sweep and paired re-timing as
the previous commit. 11 rows added, 13 replaced; most qkv_a gains are
8-22 %.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ket up to 1024

The PD decode node (DP8EP8, attention at TP1) runs its dense A8W8 GEMMs at
M = 5 tokens x requests per rank, about 120 to 960 for c192 to c1536. The K3
mx128 table had only power-of-two M rows for these TP1 shapes, so M=315 ran the
M=512 tile and M=640/960 the M=1024 tile; KDA f_b (12288x128) had no row; and
the o_proj / dense down M128 rows and the dense gate_up M256 row launch a
compute tile taller than part of the M range they serve.

194 rows added, 44 replaced over 9 shapes, kernels from #8246's space:
- 210 rows >= 3% faster than today's launch for their bucket in an ABBA A/B;
- 16 rows replace kernels that do not fit every M of their bucket;
- 12 rows pin today's kernel where a replaced power-of-two row would make the
  buckets falling through to it more than 1% slower.
Every row fits both ends of its bucket (kernel_fits_shape). Dense FFN M=1024
rows (#8557) and rows above M=1024 are unchanged.

Main-stream decode GEMMs per step (one CUDA graph, per-layer weights):
-11.4% at c192, -14.9% at c512, -19.9% at c1024, -20.0% at c1536.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…r rows

At M=315 (c512) a 128-row tile gives 3 M-tiles, which no power-of-two
cluster_m covers, so each M-tile read the whole weight on its own. A cluster of
3 (or 5) M-tiles shares each weight read through TDM multicast.

- Eight opt-in candidates with cluster_m 3 or 5 appended to kernels_list
  (existing kernelIds unchanged); kernel_fits_shape accepts the compute
  clusters (3, 1) and (3, 4) they use.
- Eight rows at M 160 and 320, each >= 3% faster than the previous row for
  its bucket in an ABBA A/B: kda_in_proj M320 1.11x, o_proj M320 1.15x,
  mla_q_b M160 1.10x, mla_gate M320 1.10x, mla_q_b M320 1.06x, kda_f_b M160
  1.06x, shexp_down M160 / M320 1.04x.
- All 457 such variants of the decode buckets' best kernels were launched
  once on hardware first, at both ends of their bucket: none hung, all but
  one _nlb variant (rejected before launch) matched the FP32 reference.
- Variants at M640 that were faster alone gave no gain inside the decode
  step (0.0% with the table order shuffled), so they are not included.

Decode-step proxy (main-stream GEMMs, 4 GPUs): c512 -26.0% against the old
table (was -14.9% with the previous commit), c256 -14.6%.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The PD prefill node (PP8 x TP1) runs these GEMMs at about 16K tokens a forward.
The power-of-two rows from 2048 up serve every M above 1024 (getPaddedM gl=1;
for N > 4096 every M above 8192 without an exact row lands on the 8192 row).

20 rows replaced and 4 added (kda_f_b had none above 1024), each >= 3% faster at
its M in an ABBA A/B and not below 0.99x at two interior points of the range the
row serves. kda_in_proj moves from the generic kernel to compute t256x256 with
cluster_m 4 (1.23-1.27x).

Prefill proxy (all TP1 GEMMs of one forward, per-layer weights): -12.9% at
M=16384, -12.4% at 8192, -10.8% at 4096. Large-M correctness: 9 shapes x 24
M points, 0 failures.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…es, tile-cost fallback

A fused (_fsk) generic kernel that the row-stripe epilogue does not fit now reduces
on split 0 in the same launch: split_k up to 16, K tiles split unevenly, no new
kernelName suffix. The mx128 tuner catalog gains the rank0 split_k candidates
(appended, kernelIds unchanged) and fits them in kernel_fits_shape; a cluster along
N no longer needs a second M tile.

The untuned-shape fallback takes the unfused, unsplit tile of up to 256 columns with
the lowest waves * sqrt(tile area): 1.72x geomean over 611 untuned shapes.
…uster and missing decode M

K3 table: 106 rows move to a faster kernel. DSv4 table: 70 rows move to a faster
kernel; no row is added. The rows come from the mxfp8_128 tuner. Every M <= 640
whose kernel changed was measured against the previous tables (cold weights, four
passes, alternating order): 4101 points, 1.18x geomean, and no padded-M block of 16
or 32 M is slower than before.
… candidates

A compute kernel now serves an N that ends inside its last group of
tile_n * cluster_n * persistent_n_tiles columns (bounded_n, split_k=1): the grid
is padded to whole groups, spare tiles skip their B / B-scale loads and C stores,
and a partial tile bounds its TDM loads, its C store and the persistent per-wave
store. K3 TP1 in_proj (N=49408) and q_a+kv_a (N=2176) gain cn2 / cn4 / ps tiles.

The mx128 tuner catalog appends clusters of 3 / 5 M tiles (generic and compute)
and generic tile_m 96 / 160 / 192 (kernelIds unchanged); the tuner admits the
N-tail compute tiles that pad at most half the N tiles. The untuned fallback and
the batched candidates keep to power-of-two geometry.
…, decode and prefill M

Kimi-K3 TP1 128x128 table, 13 shapes: 71 rows changed, 390 added at the padded-M
buckets of decode (M <= 1024) and prefill (to 16384); every row written by the
repo tuner. A row is adopted when its padded-M bucket geomean beats the current
public entry by >= 1.03x in two cold, interleaved passes; 23 buckets whose
16-aligned M (the CUDA-graph decode sizes) regress keep today's kernel.

Served-kernel A/B against the previous table at M % 4 == 0 (and decode M < 8),
1287 M points up to 16384: geomean 1.11x, time-weighted 1.10x; M=16384 in_proj
1.33x, q_a+kv_a 1.49x, DSpark q_b 1.45x, the 13 GEMMs together 1.15x.
Conflict in the K3 mxfp8_128 table only. Both sides tuned the same decode buckets,
so the resolution keeps this branch's row unless the PR's row was measured faster
inside the K3 decode step (all GEMMs of a step in one CUDA graph, per-layer
weights, 4 serial runs agreeing): 3 rows of the PR are taken as they are
(f_b M384, mla_qkv_a M112, mla_q_b M256).
…to the K3 TP1 table

Table: this branch's row is kept unless the PR's row was measured faster, inside
the K3 decode step for the shapes that step runs (4 serial runs agreeing) and by a
3-pass isolated A/B for shared down and dense gate_up. 27 rows of the PR are
taken (8 of them new buckets); two of them name cluster_m 3 / 5 kernels, whose
kernelId is the one of this branch's catalog.

Candidate list: this branch's is kept. It already holds 7 of the PR's 8
cluster_m 3 / 5 candidates among its npot families; the eighth
(t64x128x512 cm3 _qe) is used by no row taken here.

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 cross-workgroup synchronization, split-K scratch exchange, and dispatch changes lack independently verified, head-matched gfx1250 hardware results needed to establish correctness and performance.

1 open issue

Review effort: Balanced

…ter kernels for five rows

us / tflops / bw of the 384 rows this PR adds or changes are re-measured on
one GPU the way --run_config times them (tuner data, production entry,
run_perftest), median of 6-8 runs in two time windows. The previous values
were single tuner runs with outliers up to +40% (e.g. DSv4 4096x8192 M 16).

Five rows take a kernel that is faster over every M they serve (CUDA graph,
cold weights, paired, two runs on different GPUs):
- DSv4 4096x8192 M 16 / 32 / 64: fused split-K tiles, 1.50x / 1.28x / 1.29x;
  M 16 was slower than M 32.
- K3 8448x7168 M 160: 1.09x. K3 1536x7168 M 544: the M 576 kernel, 1.11x.
Conflict resolved (from #8737, LDS flush before TDM stores):
- gemm_a8w8_gfx1250: keep this branch's rank0 epilogue (direct global
  stores, no LDS) ahead of main's C offset. The rotated fused split-K rows
  and the row-stripe epilogue use the C staging at c_base_ptr, like the
  plain TDM store.

Merged cleanly but needed changes:
- splitk_fused_epilogue_gfx1250: an optional flush_addr flushes the reduced
  rows before their LDS -> TDM store (split_k > 2). The generic kernel
  passes its flush scratch; the compute and a4w4 callers are unchanged.
  With the #8486 two-stream reproducer, a split_k 4 row-stripe kernel gave
  140 bad replays in 4 minutes without it and 0 with it.
…GiB off the lean epilogue, PTPC fused test

The split_k 2 row-stripe epilogue stores its output stripe through a 32-bit
buffer descriptor, so a stripe of 4 GiB or more was written wrong (all rows
at M 8 with an Out row stride of 2^29). Such launches now take rank0 on the
generic kernel and the unfused reduction on the compute and PTPC kernels;
rank0 joins the generic kernel's specialization key.

Tests: that 2^29-stride case, and a PTPC _fsk case (per-token / per-channel
scales, ragged M) checked against FP32, its unfused twin and graph replay,
with no reduce kernel launched.
Brings in #8246's merge of main (#8737: flush LDS before the TDM C store,
ported to the fused split-K epilogue), its pinned untuned-fallback picks,
the re-measured us of its rows and five faster rows (DSv4 4096x8192 M 16 /
32 / 64, K3 8448x7168 M 160, 1536x7168 M 544).

Conflicts resolved:
- Tuned tables, per row against 5a73f40: rows whose kernel this branch
  changed or added stay as here; rows whose kernel only #8246 changed, and
  rows with the same kernel and new us, take #8246's line.
- test_gemm_a8w8_mxfp8_bpreshuffle.py: #8246's comment on the uneven splits;
  test_untuned_fallback_pick keeps the underfill check and the pinned picks.
Copilot AI balanced review requested due to automatic review settings December 1, 2026 02:44

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 split-K row-stripe selector permits output stripes exceeding 32-bit addressing limits, risking dropped or misaddressed stores; both selectors need stride-aware bounds, and the generic specialization key must include the shape-dependent rank0 flag.

1 open issue
1 resolved since last review

Review effort: Balanced

Brings in #8246's fix for split_k 2 row-stripe launches whose output stripe
reaches 4 GiB (the lean epilogue stores through a 32-bit buffer descriptor):
they take rank0 on the generic kernel and the unfused reduction on the
compute and PTPC kernels, and rank0 joins the generic specialization key.
Also its tests: the 2^29 row stride case and a PTPC fused split-K case.

No conflicts.
Copilot AI balanced review requested due to automatic review settings December 1, 2026 03:26

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 gfx1250 synchronization and shared GEMM changes require target-GPU review because no head-bound validation report was supplied, and correctness, concurrent replay safety, and paired performance could not be independently verified.

1 open issue

Review effort: Balanced

gbyu-amd pushed a commit that referenced this pull request Dec 1, 2026
#8978)

* K3 TP1 a8w8 GEMM: compute N tail, underfilled tiles, aligned A-scale loads, retuned rows (#8778 @ ea7a5d8)

#8778 (aoli26; base main; open) applied to k3-455-dev as its net change on its 19 files at head
ea7a5d8 (2026-11-26T14:47:07Z), 3-way against the PR's main base adbb6ac. The 8 files k3-455-dev had
changed (all only by #8246 @ 15808c7) take the PR's version, so all 19 files equal the PR head. It
carries the newer #8246 (ccc4270), the table PRs #8579 / #8586 / #8601 and main's #8566 (its compute
guard, which #8778 replaces); no other main change rides in.

Validated in the K3 1P1D integration branch (aiter zejun/k3-455-dev 627e1eb) on 16 MI455X
(wuhuikx/LLM-Booster#578). The PR head has moved on since (204ce9d: merges of #8246 @ 0d6cf15 and of
main, which brings #8737); those can follow when #8778 lands.

Co-authored-by: zejunchen-zejun <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Update K3 FP8 kernels to c997 and add exact-M tuning

Preserve the existing dev wrappers and bucket tables. Add 162 accepted retuned exact configurations and 3 c997-default compatibility records, with CPU dispatch coverage for all 675 measured points. Backport the three kernel files from c99781c without merging main history. Integrated-head GPU validation remains outstanding.

---------

Co-authored-by: aoli26 <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Zhang <[email protected]>
zejunchen-zejun added a commit to ROCm/ATOM that referenced this pull request Dec 1, 2026
…sted PRs have landed (#4048)

- The E17 runs' aiter `d03870f19` is a local commit, not on GitHub: it is
  `k3-455-dev` @ 17ee18a80 with ROCm/aiter#8778 @ ea7a5d83 cherry-picked.
  Say so, and note what `k3-455-dev` gained since (aiter#8978, a later
  revision of the same GEMM work, and #8993).
- R9c's block verify ran through a local env gate; it is now the K3 draft's
  class flag on `k3-455-dev` (#4046).
- R5b and R9c ran D at gpu-mem 0.92, against the script's 0.93.
- ATOM#3948, ATOM#4021 and aiter#8978, listed as open, all landed on
  `k3-455-dev` on 12-01.

Co-authored-by: Claude Opus 5.5 <[email protected]>
Reuse each A tile across N tiles and bound loads and stores by the
runtime M. Register the sweep with the tuner and AOT replay. Select it
for 12 existing Kimi-K3 rows at N=12288, leaving the table keys intact.

Cover ragged rows and out= through the blockscale test. Reject layouts
the 2D descriptors cannot represent before launching the generic kernel.

At M=16384, N=12288, K=128, paired graph replay with 192 rotating
weights takes 23.61 us, down from 44.51 us on the previous PR head.
Copilot AI balanced review requested due to automatic review settings December 2, 2026 04:01

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 catalog lookup raises KeyError and aborts gfx1250 validation, while the script entry point omits the sweep-dispatch and output-layout checks used by CI.

2 open issues
1 resolved since last review

Review effort: Balanced

Comment thread op_tests/test_gemm_a8w8_blockscale.py Resolved
Validate K3 kernel IDs against the generic and sweep catalogs. Check
that the ID ranges are disjoint. The generic catalog alone raised
KeyError on the first sweep row.

Run the output-stride checks from the default gfx1250 blockscale script.
On the 256-CU target, also check that a ragged M reaches the tuned sweep.
Explicit MNK and CSV runs continue to exercise the requested shapes.
Copilot AI balanced review requested due to automatic review settings December 2, 2026 04: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.

🔵 Needs a closer look

The gfx1250 synchronization and LDS/TDM scheduling changes require hardware/compiler review, with no head-matched runtime validation available and an unresolved GPU page fault reported during AOT auditing.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

gbyu-amd pushed a commit that referenced this pull request Dec 3, 2026
#8978)

* K3 TP1 a8w8 GEMM: compute N tail, underfilled tiles, aligned A-scale loads, retuned rows (#8778 @ ea7a5d8)

#8778 (aoli26; base main; open) applied to k3-455-dev as its net change on its 19 files at head
ea7a5d8 (2026-11-26T14:47:07Z), 3-way against the PR's main base adbb6ac. The 8 files k3-455-dev had
changed (all only by #8246 @ 15808c7) take the PR's version, so all 19 files equal the PR head. It
carries the newer #8246 (ccc4270), the table PRs #8579 / #8586 / #8601 and main's #8566 (its compute
guard, which #8778 replaces); no other main change rides in.

Validated in the K3 1P1D integration branch (aiter zejun/k3-455-dev 627e1eb) on 16 MI455X
(wuhuikx/LLM-Booster#578). The PR head has moved on since (204ce9d: merges of #8246 @ 0d6cf15 and of
main, which brings #8737); those can follow when #8778 lands.

Co-authored-by: zejunchen-zejun <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Update K3 FP8 kernels to c997 and add exact-M tuning

Preserve the existing dev wrappers and bucket tables. Add 162 accepted retuned exact configurations and 3 c997-default compatibility records, with CPU dispatch coverage for all 675 measured points. Backport the three kernel files from c99781c without merging main history. Integrated-head GPU validation remains outstanding.

---------

Co-authored-by: aoli26 <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Zhang <[email protected]>
(cherry picked from commit 1cc9d02)

Rebase onto main 12-03: the 19 files keep this commit's content; only main's later changes are added: the AOT launcher factories of #8678 (mxfp8 / batched wrappers launch gemm_a8w8_launcher.lazy(), _gemm_a8w8_compute_bound_launcher.lazy(), splitk_reduce_launcher.lazy(); _lazy_import keeps _data_ptr), #7449's deferred split-K entry points and #8636's ragged-K fallback. gemm_a8w8_gfx1250.py: this commit's rank0 split-K epilogue and flush_addr (it already carries #8737's flush). gemm_op_a8w8.py: main's #8566 guard in get_mxscale_bpreshuffle_config (no padded row below a compute kernel's M tile) is removed, as on the #8778 head, because the c997 compute kernel serves underfilled tiles; test_gemm_host_dispatch_cache.py takes #8778's test_mxscale_compute_row_serves_underfilled_m_tile in place of main's two guard tests. kimik3 mxscale tuned CSV: this commit's rows (626 changed or added) replayed by key; the result equals this commit's table.

Rebase onto main 12-03: main #7449 moved the bpreshuffle row lookup into _bpreshuffle_config(XQ, WQ); this commit's Kimi-K3 exact-row lookup there needs x_scale, w_scale and Y, so _bpreshuffle_config takes them (the deferred split-K path passes a meta tensor of the output's shape and dtype, so it picks the same row as gemm_a8w8_bpreshuffle).

Rebase onto main 12-03: op_tests/test_gemm_a8w8_mxfp8_bpreshuffle.py counts reduce launches through splitk_reduce_launcher.lazy (main #8678 replaced _compile_splitk_reduce).
gbyu-amd pushed a commit to ROCm/ATOM that referenced this pull request Dec 3, 2026
…sted PRs have landed (#4048)

- The E17 runs' aiter `d03870f19` is a local commit, not on GitHub: it is
  `k3-455-dev` @ 17ee18a80 with ROCm/aiter#8778 @ ea7a5d83 cherry-picked.
  Say so, and note what `k3-455-dev` gained since (aiter#8978, a later
  revision of the same GEMM work, and #8993).
- R9c's block verify ran through a local env gate; it is now the K3 draft's
  class flag on `k3-455-dev` (#4046).
- R5b and R9c ran D at gpu-mem 0.92, against the script's 0.93.
- ATOM#3948, ATOM#4021 and aiter#8978, listed as open, all landed on
  `k3-455-dev` on 12-01.

Co-authored-by: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 2c8c504)

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.

5 participants