Skip to content

[Triton/Gluon] Cache gfx1250 GEMM layout metadata on the host - #7090

Open
xytpai wants to merge 1 commit into
mainfrom
xyt/gfx1250-gemm-layout-cache
Open

xytpai wants to merge 1 commit into
mainfrom
xyt/gfx1250-gemm-layout-cache

Conversation

@xytpai

@xytpai xytpai commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Cache the tensor-independent layout metadata constructed by the gfx1250
non-persistent BF16/FP16 GEMM Python wrapper.

create_wmma_layouts and create_shared_layouts rebuilt the same Gluon
dataclasses on every invocation. cProfile identified repeated layout
construction / _unwrap_if_constexpr calls in the M3 router GEMM host path.

Add a private lru_cache(maxsize=128) keyed by:
(block_m, block_n, block_k, layout, elem_bits, num_warps).

  • No tensors, tensor pointers, outputs or GPU allocations are cache keys/values.
  • Only the non-persistent Gluon wrapper uses the cache. Shared factories,
    persistent dispatch, Triton dispatch and GPU kernel bodies are unchanged.
  • The current factory outputs depend only on those scalar configuration inputs;
    the gfx1250-only path does not need a device ordinal in the key.
  • The returned metadata is read-only to this caller. Tests snapshot nested
    fields/hashes before and after launch/compile, rather than assuming that a
    frozen dataclass makes its nested lists immutable.
  • Concurrent cache misses may construct equivalent values more than once;
    no exactly-once or cross-thread identity contract is assumed.

Related: https://github.com/wuhuikx/LLM-Booster/issues/188

This is separate from the existing sparse attention-plan reuse and index-score
tuning, and from #7080/#7082 and ATOM#2781.

Host-call measurement

Actual patched public GEMM call, warmed [2517,6144] @ [128,6144].T,
BF16, gfx1250. Layout caching enabled/disabled through the helper's original
implementation, in interleaved base/cache, cache/base, base/cache order.
Seven samples per arm, 100 asynchronous public calls per sample, synchronize
before each sample; host enqueue timing, not GPU execution latency.

  • Uncached medians: 77.325 / 78.052 / 77.781 us.
  • Cached medians: 30.709 / 30.432 / 30.541 us.
  • Median of the three medians: 77.781 -> 30.541 us (2.55x).

cProfile is a separate diagnostic, not the source of these reported timings.

Full-model trace confirmation

MiniMax-M3-MXFP4, TP4, gfx1250 (256 CU/device), EAGLE3 with 3 speculative
tokens, FP8 KV, ptpc_fp8 non-MoE linears. Same ATOM checkout with the SwiGLU
FP32 fix in both arms. Exact 2517-token disjoint prompts within each service;
identical seeds/input hashes across base and cache arms. No fake acceptance
rate. Warmups excluded.

Three profiled batches in one service start per arm, all four ranks.
Each selected annotation is prefill[bs=1 tok=2517 ctx=2517 nctx=3.2M].
Every rank/recording has 58 BF16 GEMM host calls and 120 start-sync calls.

Metric Base Layout cache
Host GEMM event median 137.055 us 76.057 us
Sum of 58 host GEMM event durations per rank/prefill 8.018 ms 4.487 ms
Profiled GPU prefill annotation duration 89.050 ms 83.933 ms
Unprofiled TTFT, median of 30 matched requests 92.65 ms 89.15 ms

Trace aggregates are the median of three batch summaries, each a median
across four ranks. The host event duration reduction is approximately
44.5%. These are host-event durations, not an exclusive CPU/critical-path
decomposition, and cannot be summed across concurrent ranks as wall savings.

GPU dispatch controls:

  • 57 router GEMMs per rank/recording retain the same
    BLOCK_M128 / BLOCK_N128 / BLOCK_K64 / NUM_BUFFERS6 / TN configuration:
    median GPU duration 23.334 -> 23.054 us (broadly unchanged).
  • The other GEMM configuration retains its one call per rank/recording:
    37.495 -> 37.495 us.
  • No change to GEMM count, activation/bias flags or synchronization kernels.

Return-to-base control: restarting the unpatched service reproduced
host GEMM medians of 136.008 / 134.377 / 134.797 us and per-step sums of
8.053 / 7.892 / 7.885 ms. Median TTFT over its same 30 prompts was 91.95 ms.
This supports a localized host overhead reduction rather than kernel tuning.

Limits on request-level claims

The first base/cache pair shows 3.78% lower observed median TTFT for this
single-request, 2517-token, one-output-token workload. Batch 0 was slightly
slower with caching; later batches were faster. The return baseline is a
useful control, but three batches are not three independent service-start
replicates and rank traces are not independent timing samples.

This is not a general throughput claim or a prediction for other concurrency,
context lengths, decode graph replay, models or machines. CUDA graph replay
does not rerun this Python helper. No GSM8K/model-quality result is claimed.
All 30 paired one-token response hashes matched, a narrow output check only.

Validation

  • 36 isolated FP16/BF16 shape/layout/bias cases passed against FP32 reference,
    cached/uncached bit-exact comparisons and graph replay.
  • The added regression selection: 16 passed on each of physical GPUs
    0 and 1 (separate runs) on the release checkout.
  • Tests cover every cache-key component, bounded eviction, real layout
    equality/hash values, concurrent misses, all four layout modes, both Gluon
    kernel types, FP16/BF16, preallocated outputs, graph replay after changing
    inputs, nested metadata mutation checks and tensor weakrefs after teardown.
  • Fullgraph dynamic torch.compile correctness is exercised on the public
    GEMM API with cache misses/hits and different M.
  • Black (--target-version py312), Ruff and git diff --check passed.
  • No gfx950 runtime testing is claimed; its non-Gluon path is not changed.

Provenance / reproducibility

Full-model A/B used aiter bbef5a6f2d3733b293c80d2cee6a8d464e88bc01
plus only the candidate wrapper change. ATOM is pinned main+#2710 with the
SwiGLU fix identical in both arms. Image:
rocm/fw-bringup-mlperf:gfx1250-atom-20261023, isolated FlyDSL 0.4.0 overlay.

Release base: 48295fab6e1d06d4bb4aa76418075c68bede0860.
The modified wrapper and test file were unchanged between the experiment
base and release base; the production wrapper SHA256 is identical in both
candidate checkouts. The entire newer-main model stack was not separately
benchmarked.

Excluded run: an initial candidate-model attempt loaded base aiter in
spawned workers because AITER_META_DIR inserted /code/aiter ahead of the
candidate path. That recording is marked invalid and excluded. The corrected
configuration sets both PYTHONPATH and AITER_META_DIR to the candidate;
an explicit parent/spawn-child probe verified matching module paths and the
cache helper before the corrected full-model recording. Match both settings
when reproducing; parent-only imports do not prove spawned worker identity.

HIP_VISIBLE_DEVICES=0 python3 -m pytest -q       op_tests/triton_tests/gemm/basic/test_gemm_a16w16.py       -k 'layout_cache or cached_layout'

python3 -m black --check --target-version py312       aiter/ops/triton/gemm/basic/gemm_a16w16.py       op_tests/triton_tests/gemm/basic/test_gemm_a16w16.py
python3 -m ruff check --no-cache       aiter/ops/triton/gemm/basic/gemm_a16w16.py       op_tests/triton_tests/gemm/basic/test_gemm_a16w16.py

Raw traces, matched-input manifests, host samples, excluded-run diagnostics,
return-baseline results and independent gpt-6-astra review reports remain
outside the repository. No benchmark reports are added under docs.

Validated release commit: 4aace7695a6da9c7f13c562d9301e9ba11f97bbe.

@xytpai
xytpai requested a review from a team October 28, 2026 09:39
@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 7090 --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.

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 tests can miss first-use mutations because they snapshot state after the first cached launch, and the selected dimensions exercise only bandwidth-bound cache reuse, leaving compute-bound reuse untested.

2 open issues
What changed in this PR

This PR reduces host overhead in gfx1250 non-persistent Gluon GEMM by caching reusable layout metadata. Public APIs, GPU kernels, and other dispatch paths remain unchanged.

Changes:

  • Add a bounded, 128-entry cache keyed by six scalar layout inputs.
  • Use cached metadata in the non-persistent Gluon wrapper.
  • Add regression tests for cache behavior, numerical results, graph replay, compilation, and metadata lifetime.
File Description
op_tests/​triton_tests/​gemm/​basic/​test_gemm_a16w16.py Add cache and GEMM integration regression tests.
aiter/​ops/​triton/​gemm/​basic/​gemm_a16w16.py Cache layout metadata for non-persistent gfx1250 Gluon GEMM.

Review effort: Balanced

# avoids spending GPU memory on an unrelated large-matrix test.
for kernel_type, rows in (("bandwidth_bound", 37), ("compute_bound", 129)):
x, w, _, _, _ = generate_gemm_a16w16_inputs(
rows, 128, 512, dtype=dtype, layout=layout, output=False
Comment on lines +424 to +425
snapshot = [dataclasses.asdict(v) for v in layouts]
hashes = [hash(v) for v in layouts]
@Boss2002n

Copy link
Copy Markdown
Contributor

check #6480 and #6500 which cache a private layout builder in the Gluon kernel module; here the wrappers keep the per-call cost.
Pls cache the builder in _gluon_kernels/gfx1250/gemm/basic/gemm_a16w16.py, as gemm_mxfp4.py does.

and secondly can we remote the additional UTs, we are trying to keep our CI run time minimal.

@Boss2002n Boss2002n assigned xytpai and unassigned vgokhale Oct 31, 2026
lirui927 pushed a commit that referenced this pull request Nov 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

No activity for 15 days, so this is now labelled stale. A push or a comment clears it; keep-open exempts it. Nothing is closed automatically.

@github-actions github-actions Bot added the stale The PR hasn't been updated in 2 weeks label Nov 16, 2026

@Boss2002n Boss2002n 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.

Must fix before merge

  1. Merge conflicts with main (wrapper, test): #7289 changed the same lines. In the wrapper it added import os and the create_store_layout import, and in the test file it added new tests at the end. The PR cannot merge as it is. Fix: rebase on main, and keep main's import os and create_store_layout import.

Nice to fix

  • Move the cached layout builder into _gluon_kernels/gfx1250/gemm/basic/gemm_a16w16.py as a private functools.cache function, as gemm_mxfp4.py does, and call it from the wrapper (wrapper). Then the batched and grouped wrappers can reuse it later.
  • Delete the five cache tests (test). They check cache internals, not GEMM results, and the existing Gluon tests already cover the cached path. This also removes the false "both kernel variants" comment: with N=128, K=512, both M values run bandwidth_bound.
  • Answer the open review comments.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale The PR hasn't been updated in 2 weeks Triton/Gluon

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants