Skip to content

[CK] [JIT] feat(cktile a8w8-bpreshuffle): add rowcol_wp_v2 as a selectable kernel type - #5280

Merged
valarLip merged 5 commits into
ROCm:mainfrom
ThomasNing:thomas/cktile-rowcol-wp2-kernel-type
Sep 10, 2026
Merged

valarLip merged 5 commits into
ROCm:mainfrom
ThomasNing:thomas/cktile-rowcol-wp2-kernel-type

Conversation

@ThomasNing

@ThomasNing ThomasNing commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Adds rowcol_wp_v2 as a selectable kernel type in the cktile a8w8_bpreshuffle family: CK's QuantGemmKernel in RowColQuant mode driving the plain weight-preshuffle pipeline (WP2). Per-token × per-channel scales are exactly what this op already carries, so the tuner gains a genuinely different kernel to choose between per shape.

Why

a8w8_bpreshuffle already hands the kernel a shuffle_weight(16,16)-preshuffled B and native (M,)/(N,) ptpc scales — which is precisely RowColQuant's contract. Until now the cktile libtype meant exactly one thing (FlatmmPipelineAGmemBGmemCRegV1), so a better pipeline could not be nominated by the tuner even where it wins.

Results (gfx950 / MI350X)

Correctness: errRatio 0.0000 on every one of 1754 measurements, including all 44 rowcol candidates.

Performance, measured against the full candidate space (single tune, --libtype all, 2804 candidates — not a cktile-only comparison):

shape (M,N,K) champion, all libtypes best rowcol rowcol rank
2048, 6144, 12288 151.788 µs — ck a8w8_bpreshuffle_256x256x192x128 156.512 µs 5 / 1624
16384, 6144, 12288 1018.110 µs — flydsl_bpreshuffle_8w_256x256x128 1186.285 µs 30 / 1144

On the shapes measured here, rowcol_wp_v2 is not selected. A ck or flydsl kernel wins every one. Within the CK-Tile family it beats flatmm at large M (+9.8% / +7.4%), but that is a comparison against its own family's twin, not against the dispatched kernel, and it is not the basis for merging this.

The case for it is coverage:

  • at M=2048 it is 5th of 1624 valid candidates, ~3.1% off the champion — a credible candidate on a route that could not be expressed before this PR;
  • it costs nothing when it loses: the tuner simply does not select it;
  • sPipeline is a new axis, so future improvements to the weight-preshuffle pipeline reach this op without new plumbing.

Padding safety

rowcol_wp_v2 is instantiated without M or K padding and therefore requires exact tile divisibility. Serving lookup entries now carry supports_m_padding and supports_k_padding metadata:

  • an exact-M rowcol winner dispatches normally;
  • fine- and coarse-grained padded-M lookup skip unpadded rowcol entries;
  • lookup retains the padded weight width as its dispatch key but also receives the activation's actual K, so a padded-K match skips rowcol unless that entry supports K padding;
  • the search can continue to a padding-safe flatmm entry or the existing heuristic.

This prevents arbitrary shapes such as M=2000, or an activation K smaller than its padded weight K, from selecting a rowcol winner that would reject the real input shape.

Compatibility

  • Existing flatmm instances are untouched. All 259 keep byte-identical names and ids 0..258; rowcol occupies 259..302 via a secondary table expanded and appended after the primary one.
  • The pipeline suffix is added to the kernel name only for non-default pipelines, so existing tuned CSVs keep resolving.
  • Tune-mode codegen remains a plain function-pointer lookup; padding metadata is emitted only for serving dispatch.
  • No tuner data-prep change: rowcol consumes the same preshuffled B and native scales flatmm already receives. The only tuner edit is a tile-divisibility skip.

Verified

  1. codegen — tune-mode and serving lookup generation both succeed;
  2. regression test — op_tests/test_gemm_codegen.py: 40 passed;
  3. lint/format checks pass for the changed code;
  4. GPU compile, tuning, and serving validation were completed on gfx950 for the original implementation.

Note on the CK bridge

KtWp2RowcolPipeline exists only because WeightPreshufflePipelineAGmemBGmemCRegV2 does not expose PreshuffleB, and QuantGemmKernel detects preshuffle by SFINAE on that member — defaulting to false when absent, which silently makes it read preshuffled weights as a plain B. The upstream CK fix is ROCm/rocm-libraries#11721; the wrapper can be removed once the pinned CK contains it.

…l 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.
@ThomasNing
ThomasNing requested a review from a team September 5, 2026 01:26
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 5, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-05T03:55:04.014040Z 9e9a180 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs; main branch always runs both MI35X and MI300X
multigpu 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: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
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 5280 --add-label <label>

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 opt this PR out.

@github-actions github-actions Bot changed the title feat(cktile a8w8-bpreshuffle): add rowcol_wp_v2 as a selectable kernel type [CK] feat(cktile a8w8-bpreshuffle): add rowcol_wp_v2 as a selectable kernel type Sep 5, 2026
@github-actions github-actions Bot added the CK label Sep 5, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d5f50c601b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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]>
@ThomasNing

Copy link
Copy Markdown
Contributor Author

Correcting the performance claim in the description — it overstates this PR, and the correction matters for how you'd want to review it.

The table said rowcol_wp_v2 wins 2 of 6 shapes. That was measured with --libtype cktile, i.e. rowcol against flatmm only. Re-run as a single tune with --libtype all (2804 candidates, same host/GPUs), against the full space AITER would actually choose from:

shape (M,N,K) champion, all libtypes best rowcol rowcol rank
2048, 6144, 12288 151.788 µs — ck a8w8_bpreshuffle_256x256x192x128 156.512 µs 5 / 1624
16384, 6144, 12288 1018.110 µs — flydsl_bpreshuffle_8w_256x256x128 1186.285 µs 30 / 1144

So on these shapes rowcol_wp_v2 would never be dispatched: it wins 0 of 6, not 2 of 6. A ck or flydsl kernel takes both. My earlier framing compared it to the wrong baseline — a win against a family's own twin is not a win against the dispatched kernel, which is exactly the mistake I flagged on ROCm/rocm-libraries#11721 and then repeated here.

What I think is still true, stated without the inflation: at M=2048 it lands 5th out of 1624 valid candidates, ~3.1% off the champion, on a route that could not be expressed at all before this PR. It is a credible candidate rather than a winner, and it costs nothing when it loses — the tuner simply does not select it. The reason to carry it is that sPipeline is a new axis: any future improvement to the weight-preshuffle pipeline, or kPadM support (which would let it serve M=1, where it currently cannot dispatch at all), reaches this op through it without new plumbing.

If the project's bar is "a new kernel type must win a shape today", this does not clear it on the shapes I measured, and I would rather you know that from me than find it in review. All correctness claims are unaffected: 1754 measurements at errRatio 0.0000, flatmm ids 0-258 byte-identical, serving-path dispatch verified.

@github-actions github-actions Bot changed the title [CK] feat(cktile a8w8-bpreshuffle): add rowcol_wp_v2 as a selectable kernel type [CK] [JIT] feat(cktile a8w8-bpreshuffle): add rowcol_wp_v2 as a selectable kernel type Sep 5, 2026
@github-actions github-actions Bot added the JIT label Sep 5, 2026
@ThomasNing

ThomasNing commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor Author

The real CI failure on 9e9a18088 was Black formatting; Aiter Test and OPUS then failed only because they gate on Checks. Fixed on bbb073b03 and verified locally with the exact Black 26.5.1 version used by CI.

The replacement fork workflows now require maintainer approval: Checks, Aiter Test, and OPUS Test.

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d875cb2b19

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ThomasNing

Copy link
Copy Markdown
Contributor Author

The padded-K follow-up is pushed and its thread is resolved. @codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 9e9a180883

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@zufayu
zufayu requested a review from amd-ruitang3 September 7, 2026 01:16
@ThomasNing

Copy link
Copy Markdown
Contributor Author

@amd-ruitang3 Could you take a look and let the CICD workflow run? Thanks!

@valarLip
valarLip merged commit 58d9202 into ROCm:main Sep 10, 2026
56 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants