Skip to content

feat(ck_tile): make weight-preshuffled B usable with RowCol (per-token × per-channel) scales - #3772

Closed
ThomasNing wants to merge 2 commits into
ROCm:developfrom
ThomasNing:thomas/rowcol-preshuffleb-enable
Closed

ThomasNing wants to merge 2 commits into
ROCm:developfrom
ThomasNing:thomas/rowcol-preshuffleb-enable

Conversation

@ThomasNing

@ThomasNing ThomasNing commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Replaces my #3770, which I withdrew because its evidence was vacuous — the -preshuffleb flag was not part of the rowcol LUT key, so both arms of that "before/after" ran the same non-preshuffle kernel. This PR fixes that (among other things) and the test now genuinely toggles.

Two commits: the first is #3769 (the rowcol BQ-extent fix), included because the enablement cannot be evaluated without it — rowcol fails its own verification until BQN = N. If #3769 merges first this rebases cleanly.

The defect

WeightPreshufflePipelineAGmemBGmemCRegV2 never announced PreshuffleB. QuantGemmKernel detects a preshuffled B by SFINAE on GemmPipeline::PreshuffleB (gemm_quant_kernel.hpp:104-106) and defaults to false when the member is absent — so pairing the quant kernel with the weight-preshuffle pipeline made it read preshuffled weights as a plain B. No error, just wrong numbers.

Measured by removing the announcement again on an otherwise-identical build (gfx950):

result
rowcol + preshuffleb, without the announcement fail — 39.47% wrong, max err 386.78
rowcol + preshuffleb, with it correct
rowcol, preshuffleb=0 (control) correct in both builds

Making the combination reachable

  • rowcol routes to the weight-preshuffle pipeline when PreshuffleB is set (it was pinned to GemmPipelineAgBgCrCompV3 unconditionally);
  • new GemmConfigPreshuffleB_RowCol_Prefill;
  • -preshuffleb joins the rowcol LUT key — without it the flag selected the same kernel either way, so the configuration could not be tested at all;
  • RowColQuant leaves the PreshuffleB rejection list.

Results in this example (gfx950 / MI350X, fp8, verification on)

shape preshuffleb=0 preshuffleb=1
512³ correct correct
1024×2688×6144 0.1014 ms, 333 TF 0.0471 ms, 718 TF
2048×6144×12288 0.7211 ms, 429 TF 0.2102 ms, 1471 TF

Caveat: the two arms differ in tile shape as well (the existing rowcol config is decode-shaped 16×64, the new one prefill-shaped 128×128), so read these as the new preshuffled config vs the only rowcol config the example had at these shapes, not as preshuffle in isolation.

Independent measurement, stated carefully

Driving this same composition through AITER's tuner on MI350X — 1754 measurements across 6 GLM-shaped GEMMs, full candidate space (259 flatmm tiles + 44 rowcol tiles), errRatio 0.0000 on every one:

shape (M,N,K) best rowcol best flatmm winner
1, 2688, 6144 — (no divisible tile) 11.008 µs flatmm
64, 2688, 6144 12.640 µs (rank 5) 11.325 µs flatmm, −11.6%
256, 2688, 6144 19.190 µs (rank 10) 17.590 µs flatmm, −9.1%
1024, 2688, 6144 41.226 µs (rank 35) 35.491 µs flatmm, −16.2%
2048, 6144, 12288 158.661 µs (rank 1) 175.943 µs rowcol, +9.8%
16384, 6144, 12288 1165.842 µs (rank 1) 1258.569 µs rowcol, +7.4%

So it is a genuine per-shape winner on large-M / prefill-shaped GEMMs and not a global replacement; across 184 matched (tile, BlockPerCu) pairs the median is −0.9%, with the advantage concentrated in wide-N tiles and growing with M. Also note M=1 cannot dispatch to this route — no MTile divides 1 and it is instantiated unpadded; that needs kPadM wired through separately.

(Earlier revisions of this description quoted "+8-11% over flatmm" from a restricted candidate set; the table above supersedes it. See the comments for the full correction history.)

Per-token × per-channel scales on preshuffled weights is the standard shape for FP8 LLM inference with online activation quantization, so having it reachable — and not silently mis-typed as plain B — matters beyond this example.

🤖 Generated with Claude Code

ThomasNing and others added 2 commits September 5, 2026 05:52
… N scales

Same change as ROCm#3769, included here because the enablement in the next commit
cannot be evaluated without it: the rowcol path fails its own verification
non-deterministically (8.2%/7.8% wrong, max err inf) until BQN is N.

Co-Authored-By: Claude Fable 5 <[email protected]>
…n x per-channel) scales

RowCol scales are applied by the epilogue, so the quant mode and the B layout
are independent axes -- a preshuffled B is just a different B layout. That
combination was unreachable, and one piece of it was silently wrong.

The core defect: WeightPreshufflePipelineAGmemBGmemCRegV2 never announced
PreshuffleB. QuantGemmKernel detects a preshuffled B by SFINAE on
GemmPipeline::PreshuffleB (gemm_quant_kernel.hpp:104-106) and defaults to
*false* when the member is absent, so pairing the quant kernel with the
weight-preshuffle pipeline made it read preshuffled weights as a plain B --
no error, just wrong numbers. Measured on gfx950 by removing the announcement
again: 39.47% of values wrong, max err 386.78, while the non-preshuffle
control stays correct.

Around that fix, the combination is now reachable and exercised:
  * rowcol routes to the weight-preshuffle pipeline when PreshuffleB is set
    (it was pinned to GemmPipelineAgBgCrCompV3 unconditionally);
  * GemmConfigPreshuffleB_RowCol_Prefill;
  * -preshuffleb joins the rowcol LUT key -- without this the flag selected the
    same kernel either way, so the configuration could not be tested at all;
  * RowColQuant leaves the PreshuffleB rejection list.

Measured, gfx950 / MI350X, fp8, verification on:

  shape                preshuffleb=0        preshuffleb=1
  512x512x512          correct              correct
  1024x2688x6144       0.1014 ms  333 TF    0.0471 ms   718 TF
  2048x6144x12288      0.7211 ms  429 TF    0.2102 ms  1471 TF

Note the two arms differ in tile shape as well (the existing rowcol config is
decode-shaped 16x64, the new one prefill-shaped 128x128), so read those as
'the new preshuffled config vs the only rowcol config the example had at these
shapes', not as preshuffle in isolation.

Independently, this same composition through AITER on MI350X gives errRatio
0.0000 across 7 GEMM shapes and beats the flatmm path by 8-11% at three of
them -- it is the standard shape for FP8 LLM inference with online activation
quantization.

Co-Authored-By: Claude Fable 5 <[email protected]>
@ThomasNing

Copy link
Copy Markdown
Contributor Author

Correcting the AITER-side performance claim in this PR's description.

I wrote that this composition "beats the flatmm path by 8-11% at three shapes". That number came from a run with a restricted candidate set, and it is not a fair statement of the comparison. A full sweep since then (283 candidates: 259 flatmm tiles + 24 rowcol tiles, 566 measurements, gfx950/MI350X) gives:

shape best rowcol best flatmm (full space) matched-tile comparison (128x128x256)
2048×6144×12288 180.70 µs (rank 2/283) 175.96 µs rowcol 181.44 vs flatmm 234.74 → rowcol +22.7%
256×2688×6144 24.70 µs (rank 40/283) 17.56 µs (48×64×256) rowcol 35.34 vs flatmm 39.52 → rowcol +10.6%

So the accurate statement is: at a matched tile the rowcol + weight-preshuffle route is 10-23% faster than the same-tile flatmm kernel, and at large M it lands within 3% of the best kernel overall — but with the tile set I gave it (N_Tile=128 only) it does not win outright at either shape against the full flatmm tile space. Whether it wins overall is a tuning-coverage question I have not answered yet.

All 566 measurements were at errRatio 0.0000, including all 48 rowcol candidates.

None of this affects the correctness argument this PR rests on, which is unchanged and independently measured: without the PreshuffleB announcement the quant kernel reads preshuffled weights as plain B and returns 39.47% wrong values (max err 386.78) while the non-preshuffle control stays correct; and the in-example numbers (333→718 TF, 429→1471 TF, with the tile-shape caveat already noted) come from this repository, not from AITER.

Apologies for the imprecision — the composition is worth having reachable and correct either way, but the perf claim needed to be stated against a like-for-like baseline.

@ThomasNing

ThomasNing commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor Author

Final, complete performance picture — this supersedes both of my earlier comments on this PR. A wider sweep changed the numbers again, so here is the whole thing in one place rather than another partial revision.

Setup: gfx950 / MI350X, AITER's a8w8-bpreshuffle tuner, 1754 measurements across 6 GLM-shaped GEMMs, full candidate space (259 flatmm tiles + 44 rowcol tiles). errRatio 0.0000 on every measurement.

shape (M,N,K) best rowcol best flatmm winner
1, 2688, 6144 — (no divisible tile) 11.008 µs flatmm
64, 2688, 6144 12.640 µs (rank 5) 11.325 µs flatmm, −11.6%
256, 2688, 6144 19.190 µs (rank 10) 17.590 µs flatmm, −9.1%
1024, 2688, 6144 41.226 µs (rank 35) 35.491 µs flatmm, −16.2%
2048, 6144, 12288 158.661 µs (rank 1) 175.943 µs rowcol, +9.8%
16384, 6144, 12288 1165.842 µs (rank 1) 1258.569 µs rowcol, +7.4%

So: a genuine per-shape winner on large-M / prefill-shaped GEMMs, and not a global replacement. Two further honest notes:

  • My earlier "+22.7% / +10.6% at matched tile" generalised from a single matched tile — the one where rowcol is strongest. Across all 184 matched (tile, BlockPerCu) pairs the median is −0.9%, i.e. roughly neutral. The advantage is concentrated in the wide-N tiles (128x128x256, 256x192x128) and grows with M; it is negative on the narrow family (16x64x512, 64x64x256).
  • M=1 cannot dispatch to this route at all: no MTile divides 1 and the route is instantiated unpadded. Decode-M=1 would need kPadM wired through — a separate change.

What this PR rests on is unchanged and is a correctness argument, not a perf one: without the PreshuffleB announcement the quant kernel reads preshuffled weights as a plain B and returns 39.47% wrong values (max err 386.78) while the non-preshuffle control stays correct. The in-example throughput numbers in the description come from this repository and are unaffected.

I'd rather over-correct than leave a number that does not reproduce.

(edited: two tile names were lost to shell quoting when this comment was first posted)

@ThomasNing

Copy link
Copy Markdown
Contributor Author

Closing here and reopening in the active repository: ROCm/rocm-libraries#11721. This mirror is read-only, so a PR against it cannot land. Content is unchanged, including the corrected 6-shape performance table (per-shape winner at large M, not a global replacement).

@ThomasNing ThomasNing closed this Sep 5, 2026
valarLip pushed a commit to ROCm/aiter that referenced this pull request Sep 10, 2026
…table kernel type (#5280)

* feat(cktile a8w8-bpreshuffle): add rowcol_wp_v2 as a selectable kernel type

The cktile a8w8-bpreshuffle family has exactly one device composition today:
FlatmmKernel + FlatmmPipelineAGmemBGmemCRegV1. This adds a second one, and the
plumbing that lets the tuner choose between them per shape and a tuned CSV row
route to it at serving time.

kernelInstance gains `sPipeline` ("flatmm_v1" | "rowcol_wp_v2"). The tile
geometry stays the axis it always was; the new field selects what consumes it.
It is part of the kernel name, so a tuned row that picks the non-default
pipeline is self-describing and round-trips through build_tune_dict()'s
kernelName lookup. The name is only extended for non-default pipelines, and the
rowcol candidates live in their own table that is BlockPerCu-expanded and
appended after the flatmm table, so every existing flatmm_v1 name AND kernelId
is unchanged -- already-tuned CSVs keep resolving.

rowcol_wp_v2 is ck_tile::QuantGemmKernel in QuantType::RowColQuant mode driving
WeightPreshufflePipelineAGmemBGmemCRegV2. ptpc is CK's RowColQuant: the kernel
views the aq window with strides (1, 0) and the bq window with (0, 1), so the
per-token (M,) and per-channel (N,) scale vectors AITER already passes are
consumed natively -- no replication, and B stays in the same
shuffle_weight(16, 16) layout flatmm_v1 uses. Host-side inputs are therefore
identical for the two pipelines; only the device composition differs.

One bridge is needed for now: QuantGemmKernel detects a preshuffled B by SFINAE
on GemmPipeline::PreshuffleB, which the weight-preshuffle pipeline does not
expose (the detection then silently defaults to false and the kernel reads
shuffled B as plain). KtWp2RowcolPipeline adds the alias; it can be dropped once
ROCm/composable_kernel#3772 lands in the pinned CK.

Measured on MI350X (gfx950, 256 CU), fp8 ptpc, six GLM-5.2 shapes swept with the
a8w8-bpreshuffle tuner --libtype cktile against the full 303-candidate space.
All 1754 measurements report errRatio 0.0000.

  M      N     K      best rowcol     rank    best flatmm    winner
  1      2688  6144   (no candidate)   --     11.0080us      flatmm_v1
  64     2688  6144    12.6396us       5/283  11.3251us      flatmm_v1
  256    2688  6144    19.1900us      10/303  17.5901us      flatmm_v1
  1024   2688  6144    41.2261us      35/303  35.4906us      flatmm_v1
  2048   6144  12288  158.6612us       1/303 175.9431us      rowcol_wp_v2  +9.8%
  16384  6144  12288 1165.8424us       1/303 1258.5691us     rowcol_wp_v2  +7.4%

So it is a genuine per-shape winner on the large-M (prefill-shaped) GEMMs and
flatmm_v1 stays the winner at small M -- which is what the tuner is for. Across
all 184 matched (tile, BlockPerCu) pairs the median delta is -0.9%: the
advantage is not uniform, it is concentrated in wide-N tiles (128x128x256
+10.6..+24.6%, 256x192x128 +13..+18%) and grows with M (median -2.9% at M=64,
+3.9% at M=2048).

The quant route is instantiated with the pads clamped false, so codegen emits a
single body plus a divisibility TORCH_CHECK for it, and the tuner only offers a
non-default-pipeline instance for tile-divisible shapes. One consequence: M=1
has no rowcol candidate at all, since no MTile divides 1.

* docs: point the CK citation at the active repository

ROCm/composable_kernel is now a read-only mirror; the PreshuffleB fix this
wrapper waits on lives at ROCm/rocm-libraries#11721.

Co-Authored-By: Claude Fable 5 <[email protected]>

* fix(cktile): guard padded-M rowcol dispatch

* fix(cktile): guard padded-K rowcol dispatch

* style(cktile): satisfy black spacing

---------

Co-authored-by: ThomasNing <[email protected]>
Co-authored-by: Claude Fable 5 <[email protected]>
illsilin pushed a commit to ROCm/rocm-libraries that referenced this pull request Sep 25, 2026
…n × per-channel) scales (#11721)

ISSUE ID : ROCm/composable_kernel#3766

Replaces my #3770, which I withdrew because its evidence was vacuous —
the `-preshuffleb` flag was not part of the rowcol LUT key, so both arms
of that "before/after" ran the same non-preshuffle kernel. This PR fixes
that (among other things) and the test now genuinely toggles.

Two commits: the first is #3769 (the rowcol BQ-extent fix), included
because the enablement cannot be evaluated without it — rowcol fails its
own verification until `BQN = N`. If #3769 merges first this rebases
cleanly.

## The defect

`WeightPreshufflePipelineAGmemBGmemCRegV2` never announced
`PreshuffleB`. `QuantGemmKernel` detects a preshuffled B by SFINAE on
`GemmPipeline::PreshuffleB` (`gemm_quant_kernel.hpp:104-106`) and
**defaults to false when the member is absent** — so pairing the quant
kernel with the weight-preshuffle pipeline made it read preshuffled
weights as a plain B. No error, just wrong numbers.

Measured by removing the announcement again on an otherwise-identical
build (gfx950):

| | result |
|---|---|
| rowcol + preshuffleb, **without** the announcement | **fail — 39.47%
wrong, max err 386.78** |
| rowcol + preshuffleb, **with** it | correct |
| rowcol, preshuffleb=0 (control) | correct in both builds |

## Making the combination reachable

- rowcol routes to the weight-preshuffle pipeline when `PreshuffleB` is
set (it was pinned to `GemmPipelineAgBgCrCompV3` unconditionally);
- new `GemmConfigPreshuffleB_RowCol_Prefill`;
- `-preshuffleb` joins the rowcol LUT key — without it the flag selected
the same kernel either way, so the configuration could not be tested at
all;
- `RowColQuant` leaves the `PreshuffleB` rejection list.

## Results in this example (gfx950 / MI350X, fp8, verification on)

| shape | preshuffleb=0 | preshuffleb=1 |
|---|---|---|
| 512³ | correct | correct |
| 1024×2688×6144 | 0.1014 ms, 333 TF | **0.0471 ms, 718 TF** |
| 2048×6144×12288 | 0.7211 ms, 429 TF | **0.2102 ms, 1471 TF** |

**Caveat**: the two arms differ in tile shape as well (the existing
rowcol config is decode-shaped 16×64, the new one prefill-shaped
128×128), so read these as *the new preshuffled config vs the only
rowcol config the example had at these shapes*, not as preshuffle in
isolation.

## Independent measurement, stated carefully

Driving this same composition through AITER's tuner on MI350X — 1754
measurements across 6 GLM-shaped GEMMs, full candidate space (259 flatmm
tiles + 44 rowcol tiles), **errRatio 0.0000 on every one**:

| shape (M,N,K) | best rowcol | best flatmm | winner |
|---|---|---|---|
| 1, 2688, 6144 | — (no divisible tile) | 11.008 µs | flatmm |
| 64, 2688, 6144 | 12.640 µs (rank 5) | 11.325 µs | flatmm, −11.6% |
| 256, 2688, 6144 | 19.190 µs (rank 10) | 17.590 µs | flatmm, −9.1% |
| 1024, 2688, 6144 | 41.226 µs (rank 35) | 35.491 µs | flatmm, −16.2% |
| **2048, 6144, 12288** | **158.661 µs (rank 1)** | 175.943 µs |
**rowcol, +9.8%** |
| **16384, 6144, 12288** | **1165.842 µs (rank 1)** | 1258.569 µs |
**rowcol, +7.4%** |

So it is a genuine per-shape winner on large-M / prefill-shaped GEMMs
and **not** a global replacement; across 184 matched (tile, BlockPerCu)
pairs the median is −0.9%, with the advantage concentrated in wide-N
tiles and growing with M. Also note **M=1 cannot dispatch to this
route** — no MTile divides 1 and it is instantiated unpadded; that needs
`kPadM` wired through separately.

(Earlier revisions of this description quoted "+8-11% over flatmm" from
a restricted candidate set; the table above supersedes it. See the
comments for the full correction history.)

Per-token × per-channel scales on preshuffled weights is the standard
shape for FP8 LLM inference with online activation quantization, so
having it reachable — and not silently mis-typed as plain B — matters
beyond this example.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---

*Migrated from ROCm/composable_kernel#3772 — that repository is now a
read-only mirror. All measurements quoted above were taken on the CK
tree at the time of that PR and are unchanged; the diff applies cleanly
to `develop` here.*

---------

Co-authored-by: ThomasNing <[email protected]>
Co-authored-by: Claude Fable 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant