Skip to content

[Triton/Gluon] [FlyDSL] [gfx1250] Cut remaining host overhead in GEMM wrappers - #6948

Closed
yhl-amd wants to merge 1 commit into
ROCm:mainfrom
yhl-amd:rocm-gfx1250-host-fastpath
Closed

yhl-amd wants to merge 1 commit into
ROCm:mainfrom
yhl-amd:rocm-gfx1250-host-fastpath

Conversation

@yhl-amd

@yhl-amd yhl-amd commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

What

Complements #6946 (merged; caches compiled FlyDSL launchers and covers the MoE launch paths). This PR keeps only the host-side savings #6946 does not cover. No kernel changes; kernel selection and outputs are unchanged.

  • mxfp8_32 untuned-shape kernel pick memoised per M class (batched_gemm_a8w8_gfx1250): the heuristic depends on M only through ceil(M / tile_m) per candidate tile (saturated past the M-block limit), plus M parity when an A-preshuffle candidate exists, so that tuple is the cache key; kernel-name parsing is cached too. Identical result to the per-M heuristic; prefill hands every linear a new M each step.
  • get_mxscale_bpreshuffle_config: early return for an N/K with no tuned row at any M, and the "untuned" warning is logged once per (N, K, w_scale) instead of once per M.
  • Nested custom ops call the registered body directly (gemm_a8w8_blockscale → gemm_a8w8_blockscale_bpreshuffle, tuned_gemm.gemm_a16w16 / gemm_a16w16_out → triton gemm_a16w16_) via torch_compile_guard's new _eager_body attribute, instead of a second torch.ops dispatch. A rebound module attribute is still honoured.
  • Triton gemm_a16w16 gluon path: WMMA / shared layouts memoised per tile config.
  • grouped_gemm_gfx1250_a8w4: _grouped_dbg strings are built only when AITER_GROUPED_DEBUG is on, and the arch-override env reads are skipped on native gfx1250.

Dropped from the earlier version of this PR: the _stream.py / current_stream rewrites (same call sites as #6946) and the ptr_arg fast path (no measurable gain). Fixed the Black / Ruff (UP033) failures that gated CI.

Why

DeepSeek-V4.1-Flash serving on MI455X (gfx1250, ATOM TP4): prefill steps were dominated by Python dispatch in the op wrappers rather than GPU work.

Host us/call, gfx1250, DSV4.1 TP4 shapes, M=1758 (#6946 → #6946 + this PR):

path before after
6 mx32 linears, new M each call 2962 157
6 mx32 linears, fixed M 164 151
gemm_a16w16 71 28
fused_moe a8w4 229 206

Outputs bitwise identical.

Testing

Applied on current main (which includes #6946; the commit applies cleanly), gfx1250 (MI455X):

  • New op_tests/test_gemm_host_dispatch_cache.py (each cache checked against the uncached answer; CPU contracts plus bitwise GPU comparisons): 43 passed.
  • op_tests/test_gemm_group32_interface.py: 119 passed, 50 skipped.
  • op_tests/test_flydsl_batched_gemm.py (script, 90 shapes): all error columns 0, accuracy columns identical to the run on [FlyDSL] Cache compiled FlyDSL launchers on host paths #6946's head.
  • black --check and ruff check (0.16.0, repo config) clean on the changed files.

🤖 Generated with Claude Code

@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:windows Windows JIT op smoke test on the gfx1201 ROCm runner
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 6948 --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.

@yhl-amd
yhl-amd marked this pull request as ready for review October 26, 2026 14:05
@yhl-amd
yhl-amd requested a review from a team October 26, 2026 14:05
@github-actions github-actions Bot changed the title [FlyDSL] [gfx1250] Cut host overhead in GEMM/MoE wrappers [Triton/Gluon] [FlyDSL] [gfx1250] Cut host overhead in GEMM/MoE wrappers Oct 26, 2026
@Boss2002n
Boss2002n requested a balanced review from Copilot October 26, 2026 17: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.

🟡 Changes recommended

The backend changes need separation, and the M-class cache needs regression tests that verify unchanged kernel selection.

2 open issues
What changed in this PR

This PR reduces Python overhead in AITER’s gfx1250 GEMM and MoE launch paths without changing kernel bodies.

Changes:

  • Cache kernel selection, parsed configurations, Gluon layouts, and stream wrappers.
  • Avoid nested custom-op dispatch while preserving rebound module functions.
  • Reduce untuned-config lookup work and defer debug-message formatting.
File Description
aiter/​tuned_gemm.py Enables direct-body dispatch for nested Triton GEMM calls.
aiter/​ops/​triton/​gemm/​basic/​gemm_a16w16.py Caches Gluon layouts and supports direct-body dispatch.
aiter/​ops/​gemm_op_a8w8.py Shortens config misses, deduplicates warnings, and avoids nested dispatch.
aiter/​ops/​flydsl/​moe_kernels.py Uses cached current-stream wrappers.
aiter/​ops/​flydsl/​kernels/​tensor_shim.py Adds a pointer-conversion fast path for plain tensors.
aiter/​ops/​flydsl/​grouped_moe_gfx1250.py Defers debug formatting and uses cached stream wrappers.
aiter/​ops/​flydsl/​grouped_gemm_mxfp4.py Uses the shared stream-wrapper cache.
aiter/​ops/​flydsl/​batched_gemm_a8w8_gfx1250.py Caches kernel-name parsing and selection by M class.
aiter/​ops/​flydsl/​_stream.py Adds wrapper caching while querying the current stream each call.

Review effort: Balanced

Comment on lines +348 to +351
m_class = tuple(
(-(-m // tm) if sat is None else min(-(-m // tm), sat)) for tm, sat in params
)
key = (b, n, k, bool(w_scale_32x32), m_class, (m & 1) if parity else 0, m > 0)
Comment thread aiter/ops/flydsl/_stream.py Outdated
_STREAMS: dict = {}


def current_stream(device=None):
… wrappers

Complements ROCm#6946 (compiled FlyDSL launcher cache, merged) with
the host-side savings it does not cover:

- batched mxfp8_32 GEMM: memoise the untuned-shape heuristic per M class
  (ceil(M / tile_m) per candidate tile, saturated past the M-block limit,
  plus M parity when an A-preshuffle candidate exists) instead of per exact
  M, and cache kernel-name parsing. Prefill hands every linear a new M each
  step; the pick is identical to the per-M heuristic.
- get_mxscale_bpreshuffle_config: answer an N/K with no tuned row at any M
  without walking the padded-M levels, and log an untuned weight shape once
  per (N, K, w_scale_block) instead of once per M.
- gemm_a8w8_blockscale -> gemm_a8w8_blockscale_bpreshuffle and
  tuned_gemm.gemm_a16w16 / gemm_a16w16_out -> triton gemm_a16w16_: the outer
  custom op's body calls the nested op's body directly instead of a second
  torch.ops dispatch. torch_compile_guard exposes the body it registered as
  ``_eager_body``; a rebound module attribute is still honoured.
- triton gemm_a16w16 gluon path: memoise the WMMA/shared layouts per tile
  config.
- grouped_gemm_gfx1250_a8w4: build debug strings only when
  AITER_GROUPED_DEBUG is on and skip the arch-override env reads on gfx1250.

op_tests/test_gemm_host_dispatch_cache.py checks each cache against the
uncached answer (CPU contracts plus bitwise GPU comparisons).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@yhl-amd
yhl-amd force-pushed the rocm-gfx1250-host-fastpath branch from 62180cc to 482aa1b Compare October 27, 2026 07:54
@github-actions github-actions Bot changed the title [Triton/Gluon] [FlyDSL] [gfx1250] Cut host overhead in GEMM/MoE wrappers [Triton/Gluon] [FlyDSL] [JIT] [gfx1250] Cut host overhead in GEMM/MoE wrappers Oct 27, 2026
@github-actions github-actions Bot added the JIT label Oct 27, 2026
@yhl-amd yhl-amd changed the title [Triton/Gluon] [FlyDSL] [JIT] [gfx1250] Cut host overhead in GEMM/MoE wrappers [Triton/Gluon] [FlyDSL] [gfx1250] Cut remaining host overhead in GEMM wrappers Oct 27, 2026
@yhl-amd

yhl-amd commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #7006 (FlyDSL-only split; the Triton gemm_a16w16 changes are dropped).

@yhl-amd yhl-amd closed this Oct 27, 2026
yhl-amd added a commit that referenced this pull request Oct 27, 2026
…ppers (#7006)

FlyDSL-only split of #6948 (the Triton gemm_a16w16 changes are
dropped). Complements #6946 (compiled FlyDSL launcher cache).

- batched mxfp8_32 GEMM: memoise the untuned-shape heuristic per M class
  (ceil(M / tile_m) per candidate tile, saturated past the M-block limit,
  plus M parity when an A-preshuffle candidate exists) instead of per exact
  M, and cache kernel-name parsing. Prefill hands every linear a new M each
  step; the pick is identical to the per-M heuristic.
- get_mxscale_bpreshuffle_config: answer an N/K with no tuned row at any M
  without walking the padded-M levels, and log an untuned weight shape once
  per (N, K, w_scale_block) instead of once per M.
- gemm_a8w8_blockscale -> gemm_a8w8_blockscale_bpreshuffle: the outer custom
  op's body calls the nested op's body directly instead of a second torch.ops
  dispatch. torch_compile_guard exposes the body it registered as
  ``_eager_body``; a rebound module attribute is still honoured.
- grouped_gemm_gfx1250_a8w4: build debug strings only when
  AITER_GROUPED_DEBUG is on and skip the arch-override env reads on gfx1250.

op_tests/test_gemm_host_dispatch_cache.py checks each cache against the
uncached answer (CPU contracts plus bitwise GPU comparisons).

Co-authored-by: Claude Opus 5.5 <[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.

3 participants