Skip to content

[FlyDSL] Glm5 2 qkv proj opt for gfx950 - #6427

Merged
coderfeli merged 12 commits into
ROCm:mainfrom
IzacharyI:glm5_2_qkv_proj
Nov 4, 2026
Merged

coderfeli merged 12 commits into
ROCm:mainfrom
IzacharyI:glm5_2_qkv_proj

Conversation

@IzacharyI

@IzacharyI IzacharyI commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

[FlyDSL] Preload A16W16 kernargs; skinny rows for GLM-5.2 qkv_a_proj M <= 8

Stacked on the o_proj PR #6426 (glm52-o-proj-decode), which adds the sk policy. Numbers are against that branch.

Motivation

Technical Details

Test Plan

  • op_tests/test_flydsl_hgemm.py with qkv sk cases (eager and graph replay, fp32 reference); collision guard;
    AOT.
  • No impact elsewhere: merged bf16 table, FlyDSL kernel-name parsing and AOT job list against the base branch.
  • Numerics against the rows replaced: error against an fp32 reference and run-to-run reproducibility (20
    identical calls) at M=1/3/6/8.
  • Preload across models: 363 sampled tuned FlyDSL rows (all bias / fp32-out rows, M <= 256 and M > 256), tuner
    method, 3 rounds per side, per-row minimum.
  • Decode step, the base PR's harness: the rows alone in one process (ABBA, same-table control); the whole PR in
    separate processes (ABBA over 4 processes), since the preload is code.

Test Result

Decode step (bf16 GEMMs only), medians:

                 rows only (one process)          whole PR (separate processes)
  TP8 conc=1    2048.4 -> 1923.5 us   -6.10%      2077.5 -> 1928.7 us   -7.16%
  TP8 conc=2    2092.3 -> 2079.4 us   -0.61%      2122.9 -> 2088.1 us   -1.64%
  TP8 conc=3    2206.7 -> 2198.5 us   -0.37%      2227.0 -> 2209.5 us   -0.79%
  TP8 conc=4    2249.5 -> 2239.8 us   -0.43%      2252.1 -> 2248.6 us   -0.15%
  TP8 conc=5    2331.5 -> 2319.9 us   -0.50%      2341.6 -> 2319.3 us   -0.95%
  TP8 conc=6    2552.3 -> 2553.6 us   +0.05%      2588.4 -> 2540.8 us   -1.84%
  TP8 conc=7    2611.5 -> 2607.4 us   -0.16%      2645.8 -> 2600.3 us   -1.72%
  TP8 conc=10   2789.4 -> 2791.8 us   +0.09%      2799.4 -> 2778.6 us   -0.74%
  TP4 conc=4    3004.0 -> 2993.2 us   -0.36%      3016.9 -> 3000.7 us   -0.54%
  TP4 conc=8    3408.4 -> 3402.0 us   -0.19%      3459.0 -> 3416.4 us   -1.23%
  TP4 conc=10   3510.4 -> 3510.5 us   +0.00%      3568.8 -> 3527.5 us   -1.16%
  TP4 conc=14   3927.2 -> 3929.0 us   +0.05%      3960.1 -> 3940.0 us   -0.51%

Noise: same-table control -0.26% to +0.16%; across processes the two base runs agree within 0.03-0.96%. With
the base PR, against main: TP8 conc=1 -12.4%, conc=2 -7.2%, conc=3-5 -4.8% to -5.7%, conc=6-10 -1.1% to -2.0%;
TP4 -0.9% to +0.2%.

Per call, qkv_a_proj (cold weights): M=1-8 1.07-1.21x.

Numerics at M=1/3/6/8, split-K rows -> skinny rows: mean error 2.6e-3 -> 1.1e-3; outputs more than one bf16 ulp
from fp32 28-30% -> at most 0.01%; outputs equal to the fp32 result rounded to bf16 about 45% -> 99.95-100%;
distinct outputs over 20 identical calls 20 -> 1.

Kernarg preload over 363 rows: 1.017x geomean, median 1.014x, 5th percentile 0.993x; no group (M <= 256,
M > 256, bias, split-K) is slower.

All tests pass: 16 sk cases error ratio 0, collision guard 22 OK, AOT 5 + 6 ok. Only the five keys change: the
897 shared FlyDSL kernel names parse identically and the 5783 other AOT jobs are identical.

Submission Checklist

New "sk" HGEMM policy: one workgroup per N slab with the full K, fp32
partials reduced in LDS, no split-K scratch. Retune ten N=6144 K=2048
rows (M <= 32) to it: 1.08-1.27x per call on MI355X.
…M <= 8

Enable kernarg preload in gemm_a16w16_gfx950 (1.017x geomean over 363
tuned rows). Retune qkv_a_proj (N=2624 K=6144) M=1/2/4/6/8 rows to the
skinny policy: 1.07-1.21x per call.
@IzacharyI
IzacharyI requested a review from a team October 12, 2026 09:05
@github-actions

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 (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: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 6427 --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.

@github-actions github-actions Bot changed the title Glm5 2 qkv proj [FlyDSL] Glm5 2 qkv proj Oct 12, 2026
@IzacharyI IzacharyI changed the title [FlyDSL] Glm5 2 qkv proj [FLYDSL]Glm5 2 qkv proj opt for gfx950 Oct 12, 2026
@zufayu
zufayu requested a review from yadaish October 13, 2026 01:41
@zufayu
zufayu requested review from coderfeli and solinzby1 October 15, 2026 06:36
@solinzby1
solinzby1 requested a review from xytpai October 15, 2026 07:09
@zufayu
zufayu removed the request for review from solinzby1 October 15, 2026 07:16
@zufayu zufayu assigned coderfeli and unassigned yadaish Oct 15, 2026
@xytpai

xytpai commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Review decision: Request changes — do not approve yet

Reviewed commit: 756c0aa. I recommend fixing the following two correctness issues before merging.

1. [P2] Prevent 32-bit address wraparound for weights larger than 4 GiB

Location: gemm_a16w16_skinny_gfx950.py:219–223

chunk0_offset() truncates the global byte offset into B to i32, while the buffer descriptor remains based at the beginning of B. Since skinny_config_error() does not enforce an addressable-size limit, an accepted weight tensor larger than 4 GiB can silently read from the wrong rows.

Reproduced on gfx950 with:

  • M=1, N=262176, K=8192
  • Tile 8×32×128, stages=2, k_waves=2
  • A filled with ones; B filled with ones except its final 32 rows, which contain twos.

The final 32 outputs should be 16384, but the kernel returns 8192.

Requested change: Rebase the buffer descriptor using 64-bit workgroup offsets, or reject shapes exceeding the addressing limit. Add a boundary regression test. The currently tuned CSV shapes are unaffected, but the public sk interface accepts this input.

2. [P2] Restore device validation before launching with raw pointers

Location: gemm_a16w16_skinny_gfx950.py:420–441

The new skinny path bypasses the existing GEMM implementation’s device-consistency checks. It validates dtype, shape, and contiguity, but not whether A, B, and out are on the same CUDA device. The outer stream check only covers A.

Intercepting _run_compiled confirmed that both a CPU B and a CPU out reach the launch boundary with CUDA A. Passing those raw addresses to the GPU can cause an illegal memory access instead of a validation error.

Requested change: Validate that A/B/out are on the same CUDA device before conversion or launch, and add rejection tests.

Validation and scope

Targeted gfx950 tests covered all 16 added skinny configurations, dynamic-shape cache reuse, representative graph replay, and AOT-to-run-only execution without obvious failures. Full CI and end-to-end performance claims were not independently verified.

Both findings are in the stacked skinny implementation; no separate confirmed defect was found in the qkv tuning or kernarg-preload changes.

GitHub action: Select Request changes, not Approve. This is my recommendation; I have not submitted a review on GitHub.

@xytpai xytpai added the ci:atom label Oct 20, 2026
@xytpai

xytpai commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Review decision: Request changes — do not approve yet

Reviewed commit: 756c0aa. I recommend fixing the following two correctness issues before merging.

1. [P2] Prevent 32-bit address wraparound for weights larger than 4 GiB

Location: gemm_a16w16_skinny_gfx950.py:219–223

chunk0_offset() truncates the global byte offset into B to i32, while the buffer descriptor remains based at the beginning of B. Since skinny_config_error() does not enforce an addressable-size limit, an accepted weight tensor larger than 4 GiB can silently read from the wrong rows.

Reproduced on gfx950 with:

  • M=1, N=262176, K=8192
  • Tile 8×32×128, stages=2, k_waves=2
  • A filled with ones; B filled with ones except its final 32 rows, which contain twos.

The final 32 outputs should be 16384, but the kernel returns 8192.

Requested change: Rebase the buffer descriptor using 64-bit workgroup offsets, or reject shapes exceeding the addressing limit. Add a boundary regression test. The currently tuned CSV shapes are unaffected, but the public sk interface accepts this input.

2. [P2] Restore device validation before launching with raw pointers

Location: gemm_a16w16_skinny_gfx950.py:420–441

The new skinny path bypasses the existing GEMM implementation’s device-consistency checks. It validates dtype, shape, and contiguity, but not whether A, B, and out are on the same CUDA device. The outer stream check only covers A.

Intercepting _run_compiled confirmed that both a CPU B and a CPU out reach the launch boundary with CUDA A. Passing those raw addresses to the GPU can cause an illegal memory access instead of a validation error.

Requested change: Validate that A/B/out are on the same CUDA device before conversion or launch, and add rejection tests.

Validation and scope

Targeted gfx950 tests covered all 16 added skinny configurations, dynamic-shape cache reuse, representative graph replay, and AOT-to-run-only execution without obvious failures. Full CI and end-to-end performance claims were not independently verified.

Both findings are in the stacked skinny implementation; no separate confirmed defect was found in the qkv tuning or kernarg-preload changes.

GitHub action: Select Request changes, not Approve. This is my recommendation; I have not submitted a review on GitHub.

Recommendation: Approve with non-blocking follow-ups

Re-reviewed commit 756c0aa, including the qkv tuning, kernarg preload, and skinny GEMM integration. No blocking correctness issue was identified for the targeted gfx950 workloads with valid same-device inputs.

Targeted tests covered the added skinny configurations, dynamic-shape cache reuse, representative graph replay, and AOT-to-run-only execution without obvious failures.

Two follow-ups remain:

  • Large-buffer addressing: The confirmed 32-bit offset wraparound for weights exceeding 4 GiB should be guarded against or fixed. It does not affect the newly tuned shapes.
  • Device validation: Restore same-device checks for A, B, and the optional output before passing raw pointers to the kernel. This concerns invalid input combinations rather than normal execution.

These are worth tracking, but I would not block this workload-specific optimization on them. LGTM, subject to the required CI checks.

Full CI and end-to-end performance gains were not independently verified. This is a recommendation only; no approval has been submitted on GitHub.

xytpai
xytpai previously approved these changes Oct 20, 2026
@github-actions github-actions Bot changed the title [FLYDSL]Glm5 2 qkv proj opt for gfx950 [FlyDSL] Glm5 2 qkv proj opt for gfx950 Oct 23, 2026
@IzacharyI

Copy link
Copy Markdown
Contributor Author

Hi, @xytpai , the latest CI-status shows the changed of this pr is covered and passed. If no further CI validation is needed, would you mind helping proceed with the merge?

@zufayu
zufayu removed the request for review from yadaish October 29, 2026 10:17
@xytpai

xytpai commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Review result: Request Changes

Reviewed head: fb0f5478b

I re-reviewed all eight changed files and ran tests on gfx950. The targeted GLM qkv/o_proj configurations work correctly in the tested cases. However, both previously reported skinny-kernel issues remain reproducible on the current head.

1. [P2] Guard against 32-bit weight-offset wraparound

Location: gemm_a16w16_skinny_gfx950.py:219–223

chunk0_offset() truncates the global byte offset into B to i32, while b_rsrc remains based at the beginning of the entire weight tensor. Since skinny_config_error() does not enforce an addressable-size limit, an accepted weight tensor exceeding 4 GiB can silently read from the wrong rows.

I reproduced this on the current head with M=1, N=262176, K=8192, tile 8×32×128, stages=2, and k_waves=2. With A filled with ones and B filled with ones except for its final 32 rows filled with twos, those final outputs should be 16384, but all 32 are 8192. The configuration validator returns None, so this input is explicitly accepted.

Please rebase the buffer descriptor using a 64-bit workgroup offset and keep only local offsets in i32, or reject shapes outside the supported addressing range. Add a regression test around the 4-GiB boundary.

The currently tuned CSV shapes are unaffected, but the new public sk path accepts the failing shape. This is a confirmed numerical correctness defect, not merely a theoretical limitation.

2. [P2] Restore device validation before passing raw pointers to the kernel

Location: gemm_a16w16_skinny_gfx950.py:434–441

The new skinny path validates shapes, dtypes, and contiguity, but never verifies that A, B, and the optional output are on the same CUDA device. The outer stream validation only checks A. This bypasses the device-consistency checks performed by the existing GEMM implementation.

Intercepting _run_compiled() on the current head confirmed that both CUDA A + CPU B and CUDA A/B + CPU output reach the raw-pointer launch boundary. The existing ft path rejects the CPU-B case. Launching with these host addresses can cause an illegal memory access rather than a validation error.

Please validate a.is_cuda, b.device == a.device, and out.device == a.device when an output is provided, before conversion or launch. Add rejection tests for CPU operands/outputs and, where available, mismatched GPU devices.

For safety, the invalid-device tests intercepted the launch rather than dereferencing CPU pointers on the GPU.

Validation performed

Test Result
Default test_flydsl_hgemm.py sweep 47 cases, reported mismatch ratios all zero
Added skinny configurations 16 cases, eager and graph replay passed
HTI concurrent-copy regression 1,000 launches, zero differing launches
Actual tuned dispatch, including padded-M lookup and preallocated output 40 cases passed, including repeatability checks
Additional tile/K/stage configurations 32 cases passed
Isolated skinny AOT → fresh-process run-only + graph replay 15 CSV rows / 8 unique configurations passed
>4-GiB weight boundary Incorrect output reproduced
Device-mismatch validation Missing checks confirmed

AOT limitation: The full AOT module import was blocked by the installed FlyDSL version lacking check_smem_capacity, imported by an unchanged gfx1250 module. I therefore executed the skinny AOT functions in isolation, without changing their bodies. This validates the skinny artifacts, not the complete AOT entry point.

Bottom line

No additional confirmed defect was found in the qkv tuning or kernarg-preload changes. Both findings are in the stacked skinny implementation and remain unchanged from the previously reviewed version.

I recommend fixing the address-range guard and device checks before merging. Full CI and end-to-end performance claims were not independently verified.

@aiter-bot

aiter-bot commented Oct 29, 2026 •

Copy link
Copy Markdown

NOT READY FOR HUMAN REVIEW

PR Self-Review

Revision b9d0cc5d2156 · 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 — missing ### Reviewed revision in the PR description
  • FAIL — missing ### Behavior and intent in the PR description
  • FAIL — missing ### Validation and unverified scope in the PR description
  • FAIL — missing ### PR-specific question in the PR description
  • FAIL — missing ### Changed op tests in the PR description
  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA
  • FAIL — Behavior and intent has no substantive answer
  • FAIL — Validation and unverified scope has no substantive answer
  • FAIL — PR-specific question has no substantive answer
  • FAIL — changed op test not explained in Changed op tests: op_tests/test_flydsl_hgemm.py
  • FAIL — Changed op tests must explain why each changed op test is necessary and non-redundant

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

The DMA voffset is a single 32-bit VGPR and the offset is cast to a
signed i32, so a tensor-based descriptor wraps once n0 * k * 2 passes
2 GiB and the load reads whatever is mapped there. Fold n0 into the
64-bit base, make the voffset slab-relative, and bound the descriptor
with num_records so an offset bug returns zeros instead of faulting.

Also reject host tensors up front -- the launch hands the kernel raw
pointers, so a CPU a/b/out was a GPU memory fault, not a Python error.
xytpai
xytpai previously approved these changes Oct 30, 2026
@IzacharyI

Copy link
Copy Markdown
Contributor Author

Hi, @coderfeli, the latest CI-status shows the changed of this pr is covered and passed. If no further validation or changed requests is needed, would you mind helping proceed with the merge?

@coderfeli coderfeli left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Use flydsl_kernel_code_cleanup and unit test skill in aiter to do a clean

Raw arith/scf/index plumbing becomes fx values and plain Python control
flow: constant_vector -> fx.Vector.filled, index_cast -> fx.Int32/Int64,
truncf -> .to(), cmpi + scf.IfOp -> if. The three raw boundaries that stay
-- the DMA inline asm, the mfma intrinsic and the LDS buffer_ops addressing
-- are the hand-scheduled parts that have no builder form, and the module
docstring now says so. .ir_value() appears only where one of them needs an
unwrapped operand.

No functional change: 48 benchmark rows reproduce with err 0, the 7 policy
rejects and the 2 GiB weight case still pass.
Upstream added a gfx1250-strict target; keep both it and the skinny
policy in the kernel-name regex and the two dispatch sites.
coderfeli
coderfeli previously approved these changes Nov 3, 2026
The AOT GEMM module now replays each tuned row through the public
gemm_a16w16 entry (ROCm#6956), so it no longer dispatches on a per-kernel
kind. Drop the skinny registration it needed: tuned_gemm already routes
a psk row into flydsl_hgemm, which the replay reaches on its own.
@coderfeli
coderfeli merged commit 8f4fe9e into ROCm:main Nov 4, 2026
AndreasKaratzas added a commit to AndreasKaratzas/aiter that referenced this pull request Nov 8, 2026
Conflicts:
- gemm_a16w16_gfx950.py: keep the fp32 split-K workspace, the one-counter
  get_split_k_buffers(stream, device) and the up-front kernarg loads; take
  main's capture_scoped_cache, kernarg preload hints, k_stagger and
  b_non_temporal.
- aot/flydsl/gemm.py: take main's replay-based AOT build (ROCm#6956), which
  launches through the runtime and so needs no HGEMM-specific arguments.
- glm5/kimik3/minimax_m3_eagle tables: rows are merged one by one. Where both
  sides changed a row, main's row is kept: glm5 2624x6144 M=1/2/4/6/8 use
  the skinny kernel (ROCm#6427), and kimik3 64x20480x7168 uses the band-stream
  kernel (ROCm#7546). Neither uses split-K; both are exact and repeatable.
- test_graph_alloc.py: call get_split_k_buffers(s, dev), which no longer
  takes split_k.

Co-authored-by: Claude <[email protected]>
Signed-off-by: Andreas Karatzas <[email protected]>
shantipriya-amd pushed a commit to shantipriya-amd/aiter that referenced this pull request Nov 18, 2026
* [FlyDSL] Add skinny A16W16 policy for GLM-5.2 o_proj decode on gfx950

New "sk" HGEMM policy: one workgroup per N slab with the full K, fp32
partials reduced in LDS, no split-K scratch. Retune ten N=6144 K=2048
rows (M <= 32) to it: 1.08-1.27x per call on MI355X.

* [FlyDSL] Preload A16W16 kernargs; skinny rows for GLM-5.2 qkv_a_proj M <= 8

Enable kernarg preload in gemm_a16w16_gfx950 (1.017x geomean over 363
tuned rows). Retune qkv_a_proj (N=2624 K=6144) M=1/2/4/6/8 rows to the
skinny policy: 1.07-1.21x per call.

* fix(flydsl): base the skinny B descriptor at the workgroup slab

The DMA voffset is a single 32-bit VGPR and the offset is cast to a
signed i32, so a tensor-based descriptor wraps once n0 * k * 2 passes
2 GiB and the load reads whatever is mapped there. Fold n0 into the
64-bit base, make the voffset slab-relative, and bound the descriptor
with num_records so an offset bug returns zeros instead of faulting.

Also reject host tensors up front -- the launch hands the kernel raw
pointers, so a CPU a/b/out was a GPU memory fault, not a Python error.

* refactor(flydsl): move the skinny kernel onto the typed fx API

Raw arith/scf/index plumbing becomes fx values and plain Python control
flow: constant_vector -> fx.Vector.filled, index_cast -> fx.Int32/Int64,
truncf -> .to(), cmpi + scf.IfOp -> if. The three raw boundaries that stay
-- the DMA inline asm, the mfma intrinsic and the LDS buffer_ops addressing
-- are the hand-scheduled parts that have no builder form, and the module
docstring now says so. .ir_value() appears only where one of them needs an
unwrapped operand.

No functional change: 48 benchmark rows reproduce with err 0, the 7 policy
rejects and the 2 GiB weight case still pass.

---------

Co-authored-by: Yutao Xu <[email protected]>
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