Skip to content

[ASM] [HIP] [OPUS] Add narrow-head (H<=32) gfx1250 MLA sparse-prefill kernels for DSv4 TP - #5228

Merged
kaiyang-1 merged 9 commits into
mainfrom
kaiyang-1/dsv4_prefill_head_16_32
Sep 9, 2026
Merged

kaiyang-1 merged 9 commits into
mainfrom
kaiyang-1/dsv4_prefill_head_16_32

Conversation

@kaiyang-1

@kaiyang-1 kaiyang-1 commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

DSv4 under tensor parallelism leaves each rank with only 16 or 32 query heads. The existing gfx1250 code object 16mx4_64nx1 covers Q_TILE_SIZE(16) * T_M(4) = 64 heads per workgroup, so at H=16/32 half to three quarters of the workgroup's head slots are idle.

  • Add four prebuilt code objects under hsa/gfx1250/mla_v4_opus/: 16mx1_16nx4 and 32mx1_16nx4, for both bf16 (a16w16) and mxfp8 (a8w8). These use T_M=1 and spread the 4 waves along N (KV) instead of along heads, so a 16- or 32-head workgroup still fills the whole block.
  • Dispatch by head count in both gfx1250 entry points (opus_mla_v4_prefill_a16w16_gfx1250_fwd and opus_mla_v4_prefill_a8w8_gfx1250_fwd): H <= 16 picks 16mx1_16nx4, H <= 32 picks 32mx1_16nx4, everything else keeps the current clustered 16mx4_64nx1 path unchanged. The narrow-head paths always launch with grid.y == 1, so they skip the cluster gather and its "cluster width must divide grid.y" constraint entirely.
  • Rebuild the existing 16mx4_64nx1 bf16/fp8 code objects from the same source revision; launch geometry and dispatch for H > 32 are untouched.

Naming unification

The op previously mixed three vocabularies (pa_sparse_prefill_* in the host layer, pa_prefill_* in the device templates, mla_prefill_* in the code objects). Everything below the Python layer now follows a single opus_mla_v4_prefill_<dtype>_<layout>[_<variant>] grammar, with a16w16/a8w8 as the uniform precision notation:

  • Sources and JIT module: csrc/include/pa_sparse_prefill_opus.h → mla_v4_prefill_opus.h (same for _kernels.cu / _pybind.cu), and module_pa_sparse_prefill_opus → module_mla_v4_prefill_opus.
  • Code objects: all six gfx1250 .co files and their exported symbols are now opus_mla_v4_prefill_a{16w16,8w8}_<layout>[_cy{1,2}], matching the kernel templates and traits they were built from.
  • C++ host entries: pa_sparse_prefill[_fp8]_gfx{950,1250}_opus_fwd → opus_mla_v4_prefill_{a16w16,a8w8}_gfx{950,1250}_fwd. The m.def binding strings in rocm_ops.hpp are deliberately left unchanged, so the pybind-exported names and the entire Python layer are untouched.

No Python-level or public API change: aiter/ops/pa_sparse_prefill_opus.py and op_tests/test_pa_sparse_prefill.py are byte-identical to main. gfx950 is functionally untouched (renames only).

Test plan

On gfx1250, after clearing the JIT cache and rebuilding the module from scratch:

  • PYTHONPATH=. pytest op_tests/test_pa_sparse_prefill.py — 24 passed. The sweep covers H = 16 / 32 / 64 / 128 across {bf16, fp8} x {sparse, dense, empty}; the first two head counts exercise the new narrow-head code objects and the last two confirm the H > 32 clustered path is unchanged.
  • PYTHONPATH=. python3 op_tests/test_pa_sparse_prefill.py --prec bf16 fp8 --h_q 16 32 64 128 --mode sparse dense empty --backend opus — 24/24 with err = 0.0 on every shape. All eight gfx1250 code-object symbols (16mx1, 32mx1, 16mx4_64nx1_cy1, 16mx4_64nx1_cy2 x a16w16, a8w8) are exercised by this sweep.

@kaiyang-1
kaiyang-1 requested review from a team and a lite review from Copilot September 3, 2026 05:49
@github-actions

github-actions Bot commented Sep 3, 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 5228 --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 [OPUS] Add narrow-head (H<=32) gfx1250 MLA sparse-prefill kernels for DSv4 TP [ASM] [HIP] Add narrow-head (H<=32) gfx1250 MLA sparse-prefill kernels for DSv4 TP Sep 3, 2026
@kaiyang-1 kaiyang-1 changed the title [ASM] [HIP] Add narrow-head (H<=32) gfx1250 MLA sparse-prefill kernels for DSv4 TP [OPUS] [HIP] Add narrow-head (H<=32) gfx1250 MLA sparse-prefill kernels for DSv4 TP Sep 3, 2026

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 new launch paths can attempt a kernel launch with gridDimY=0 when H==0, which should be guarded with an early return (or equivalent validation) to avoid an invalid HIP launch configuration.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds narrow-head (H<=32) gfx1250 sparse-prefill prebuilt-kernel dispatch to improve utilization under tensor parallelism, while preserving the existing clustered path for larger head counts.

Changes:

  • Introduces gfx1250 narrow-head code-object identifiers (16mx1_16nx4 and 32mx1_16nx4) for bf16 (a16w16) and fp8 (a8w8).
  • Adds head-count-based dispatch in bf16 and fp8 gfx1250 sparse-prefill launchers: H<=16 → 16mx1, H<=32 → 32mx1, else keep 16mx4_64nx1 clustered behavior.
File summaries
File Description
csrc/py_itfs_cu/pa_sparse_prefill_opus_kernels.cu Adds new gfx1250 code-object paths/constants and dispatch logic to select narrow-head kernels for H<=32.
Review details

Suppressed comments (1)

csrc/py_itfs_cu/pa_sparse_prefill_opus_kernels.cu:664

  • If H==0, ceil_div(H, ...) becomes 0 and the kernel launch will use gridDimY=0, which is invalid for hipModuleLaunchKernel. Consider early-returning on empty head dimension (similar to the existing N==0 early return) before selecting a code object.
    size_t arg_size = sizeof(args);

    // 16mx1_16nx4 for H <= 16, 32mx1_16nx4 for H <= 32, else the clustered 16mx4_64nx1.
    if(H <= kGfx1250Heads16mx1)
    {
  • Files reviewed: 1/7 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@kaiyang-1
kaiyang-1 marked this pull request as draft September 3, 2026 10:26
@kaiyang-1
kaiyang-1 marked this pull request as ready for review September 3, 2026 11:14
Copilot AI review requested due to automatic review settings September 3, 2026 11:14
@github-actions github-actions Bot changed the title [OPUS] [HIP] Add narrow-head (H<=32) gfx1250 MLA sparse-prefill kernels for DSv4 TP [ASM] [HIP] Add narrow-head (H<=32) gfx1250 MLA sparse-prefill kernels for DSv4 TP Sep 3, 2026
@kaiyang-1 kaiyang-1 changed the title [ASM] [HIP] Add narrow-head (H<=32) gfx1250 MLA sparse-prefill kernels for DSv4 TP [OPUS] [HIP] Add narrow-head (H<=32) gfx1250 MLA sparse-prefill kernels for DSv4 TP Sep 3, 2026

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 new dispatch paths should guard against H==0 to avoid attempting a zero-sized HIP grid launch, and a small constant-coupling tweak would prevent future divergence.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Suppressed comments (2)

csrc/py_itfs_cu/pa_sparse_prefill_opus_kernels.cu:663

  • If H==0, this path will compute a 0 grid.y via ceil_div(H, ...) and attempt to launch a zero-sized grid. Add an early-return for H==0 before the new narrow-head dispatch/launch logic.
    size_t arg_size = sizeof(args);

    // 16mx1_16nx4 for H <= 16, 32mx1_16nx4 for H <= 32, else the clustered 16mx4_64nx1.
    if(H <= kGfx1250Heads16mx1)

csrc/py_itfs_cu/pa_sparse_prefill_opus_kernels.cu:488

  • If H==0 (valid tensor shape in PyTorch), ceil_div(H, ...) will produce a 0 grid.y and hipModuleLaunchKernel will be called with a zero-sized grid, which is typically invalid. Add an explicit early-return for H==0 before selecting and launching any prebuilt kernel.
    size_t arg_size = sizeof(args);

    // 16mx1_16nx4 for H <= 16, 32mx1_16nx4 for H <= 32, else the clustered 16mx4_64nx1.
    if(H <= kGfx1250Heads16mx1)
  • Files reviewed: 1/7 changed files
  • Comments generated: 1
  • Review effort level: Lite

Copilot AI review requested due to automatic review settings September 4, 2026 02:48
@github-actions github-actions Bot changed the title [OPUS] [HIP] Add narrow-head (H<=32) gfx1250 MLA sparse-prefill kernels for DSv4 TP [ASM] [HIP] Add narrow-head (H<=32) gfx1250 MLA sparse-prefill kernels for DSv4 TP Sep 4, 2026
@kaiyang-1 kaiyang-1 changed the title [ASM] [HIP] Add narrow-head (H<=32) gfx1250 MLA sparse-prefill kernels for DSv4 TP [OPUS] [HIP] Add narrow-head (H<=32) gfx1250 MLA sparse-prefill kernels for DSv4 TP Sep 4, 2026

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 new narrow-head launch paths can still attempt a HIP launch with gridDimY=0 when H==0, which is an invalid launch configuration and should be guarded.

Review details

Suppressed comments (3)

csrc/py_itfs_cu/pa_sparse_prefill_opus_kernels.cu:487

  • When H==0 (possible with an empty [N,0,D] tensor), this path will compute gdy=ceil_div(0, …)==0 and attempt a HIP launch with gridDimY=0, which is invalid. Consider early-returning on H==0 (mirroring the existing N==0 guard) before selecting/launching a code object.
    size_t arg_size = sizeof(args);

    // 16mx1_16nx4 for H <= 16, 32mx1_16nx4 for H <= 32, else the clustered 16mx4_64nx1.

csrc/py_itfs_cu/pa_sparse_prefill_opus_kernels.cu:662

  • Same issue as the bf16 path: if H==0, gdy becomes 0 and the kernel launch uses gridDimY=0. Adding an early return for H==0 avoids an invalid launch for empty-head tensors.
    size_t arg_size = sizeof(args);

    // 16mx1_16nx4 for H <= 16, 32mx1_16nx4 for H <= 32, else the clustered 16mx4_64nx1.

csrc/py_itfs_cu/pa_sparse_prefill_opus_kernels.cu:369

  • kGfx1250Heads16mx1 duplicates kGfx1250QTileSize (16) and kGfx1250Heads32mx1 is a simple multiple of it; defining these in terms of kGfx1250QTileSize reduces the chance of the dispatch thresholds drifting if the underlying tile size changes.
// Narrow-head variants: T_M=1, so heads per workgroup is Q_TILE_SIZE alone.
constexpr int kGfx1250Heads16mx1 = 16;
constexpr int kGfx1250Heads32mx1 = 32;
  • Files reviewed: 1/7 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Copilot AI review requested due to automatic review settings September 7, 2026 09:42
@github-actions github-actions Bot changed the title [OPUS] [HIP] Add narrow-head (H<=32) gfx1250 MLA sparse-prefill kernels for DSv4 TP [ASM] [HIP] [OPUS] Add narrow-head (H<=32) gfx1250 MLA sparse-prefill kernels for DSv4 TP Sep 7, 2026

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

It changes low-level GPU kernel dispatch and relies on prebuilt gfx1250 code objects, which warrants human validation (correctness/perf) beyond static review.

Review details
  • Files reviewed: 6/12 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread aiter/ops/pa_sparse_prefill_opus.py Resolved
Copilot AI review requested due to automatic review settings September 8, 2026 06:35

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

It changes GPU-kernel dispatch and ABI-sensitive prebuilt code-object loading paths (gfx1250), which is high impact and warrants final human review despite limited textual diffs.

Review details

Suppressed comments (1)

aiter/ops/pa_sparse_prefill_opus.py:28

  • The docstring points to aiter/csrc/include/mla_v4_prefill_opus.h, but that path does not exist in the repo; the header lives under csrc/include/mla_v4_prefill_opus.h. This makes the reference misleading for users trying to find the C++ API.
See ``aiter/csrc/include/mla_v4_prefill_opus.h`` for the C++ API.
  • Files reviewed: 6/12 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Copilot AI review requested due to automatic review settings September 8, 2026 06:56

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

There are confirmed correctness/documentation issues in the updated gfx1250 launch paths (missing H==0 early-return leading to invalid zero-dimension kernel launches) and an incorrect header path reference in the Python docstring.

Review details

Suppressed comments (3)

Previously missed (1) — in code that hasn't changed since the last review.

csrc/py_itfs_cu/mla_v4_prefill_opus_kernels.cu:498

  • If H == 0, this path will compute grid.y = ceil_div(0, ...) == 0 and still attempt a HIP module launch. hipModuleLaunchKernel does not accept zero grid dimensions, so this should early-return before dispatch.

This issue also appears on line 674 of the same file.

aiter/ops/pa_sparse_prefill_opus.py:28

  • The docstring points to aiter/csrc/include/mla_v4_prefill_opus.h, but that path does not exist in the repo (the header lives under csrc/include/). This makes the reference misleading for readers.
See ``aiter/csrc/include/mla_v4_prefill_opus.h`` for the C++ API.

csrc/py_itfs_cu/mla_v4_prefill_opus_kernels.cu:677

  • If H == 0, this path will compute grid.y = ceil_div(0, ...) == 0 and still attempt a HIP module launch. hipModuleLaunchKernel does not accept zero grid dimensions, so this should early-return before dispatch.
  • Files reviewed: 7/13 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Copilot AI review requested due to automatic review settings September 9, 2026 02:52

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 new/updated launch paths can still attempt invalid HIP launches when H==0 (grid.y==0), and the PR description claims the Python file is unchanged despite a real module-name/doc change.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Suppressed comments (4)

csrc/py_itfs_cu/mla_v4_prefill_opus_kernels.cu:86

  • If H==0 (but N>0), the launch grid.y becomes 0 (via ceil_div(H, ...)), which is an invalid HIP launch configuration and will error at runtime. Consider early-returning (or validating) on H==0 the same way as N==0.
    csrc/py_itfs_cu/mla_v4_prefill_opus_kernels.cu:242
  • If H==0 (but N>0), subsequent grid.y computations become 0 and the kernel launch will fail. Add an H==0 early return (or validation) alongside the existing N==0 guard.
    csrc/py_itfs_cu/mla_v4_prefill_opus_kernels.cu:644
  • If H==0 (but N>0), the narrow-head/cluster dispatch will compute a grid.y of 0 (ceil_div(H, ...)) and the prebuilt-kernel launch will fail. Add an H==0 early return alongside the existing N==0 guard.
    csrc/py_itfs_cu/mla_v4_prefill_opus_kernels.cu:469
  • If H==0 (but N>0), the narrow-head/cluster dispatch will compute a grid.y of 0 (ceil_div(H, ...)) and the prebuilt-kernel launch will fail. Consider guarding H==0 the same way as N==0.
  • Files reviewed: 7/13 changed files
  • Comments generated: 2
  • Review effort level: Lite

Comment thread aiter/ops/pa_sparse_prefill_opus.py Resolved
Comment thread aiter/ops/pa_sparse_prefill_opus.py Resolved
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Copilot AI review requested due to automatic review settings September 9, 2026 03:06

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

It changes GPU dispatch behavior and relies on prebuilt gfx1250 code objects/ABI matching that can’t be fully validated from the diff alone.

Review details

Suppressed comments (1)

Previously missed (1) — in code that hasn't changed since the last review.

csrc/include/mla_v4_prefill_opus.h:44

  • The comment "gfx1250: only the bf16 variant is built into the code object." is now ambiguous/misleading because this header also declares the gfx1250 fp8 entry point below; it reads like gfx1250 has no fp8 support. Consider clarifying that this applies to the bf16 (a16w16) code objects/entry point only.
  • Files reviewed: 7/13 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@kaiyang-1
kaiyang-1 merged commit a0f1561 into main Sep 9, 2026
56 of 58 checks passed
@kaiyang-1
kaiyang-1 deleted the kaiyang-1/dsv4_prefill_head_16_32 branch September 9, 2026 08:43
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.

3 participants