Skip to content

[HIP] [OPUS] [JIT] [Bugfix] Stop an unbaked tuned kernel id from killing the rank, and key the lookup on CU count - #5341

Closed
RElbers wants to merge 6 commits into
cu-aware-targets/gpu-target-resolutionfrom
cu-aware-targets/opus
Closed

RElbers wants to merge 6 commits into
cu-aware-targets/gpu-target-resolutionfrom
cu-aware-targets/opus

Conversation

@RElbers

@RElbers RElbers commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Stops a tuned row naming a kernel id this build does not contain from killing the rank. The id dispatcher now raises a distinct type, tuned_gemm catches it and falls back to torch, and the shape is remembered so a serving loop pays for the miss once. That is a prerequisite for loading a 128-CU CSV in serving at all (#4735 bug 2). Keys the opus a16w16 GEMM lookup on CU count, and starts dispatching gfx1250's tuned split-K kernels, which the build already contained but nothing ever selected.

Stacked on #5340, which introduces AITER_GPU_TARGETS: build targets written as gfx:cu_num pairs, as in AITER_GPU_TARGETS="gfx950:128;gfx950:256", and the build and runtime target resolution behind them. The opus codegen here resolves its rows and its compile set through those targets, which is what lets one build carry a tuned winner per SKU.

Motivation

The lookup key had no CU count. Tuned rows are keyed (gfx, cu_num, ...), but the generated C++ tables were keyed (M, N, K) per arch. A shape tuned on two SKUs of one arch kept whichever row was read last, and the other SKU silently fell back to its heuristic. One build could never hold both. No checked-in CSV carries two CU counts for one arch today, so this is a fix ahead of the need.

gfx1250's split-K winners were unreachable. opus_gemm.cu resolved every gfx1250 shape through opus_dispatch_a16w16_gfx1250<fp32_t>, and rows bucket into tables by output dtype. Every checked-in gfx1250 opus row is bf16-output, so the fp32 table it consulted was empty and the 150 baked split-K winners never dispatched through it. The 147 .co winners did dispatch, through the separate .co lookup ahead of it.

A tuned row naming a kernel id the build lacks killed the rank. The CSV ships every target's winners; a build bakes only its own, so the two disagree whenever a package is used on a target it was not built for.

Changes

One shared key type and search (csrc/opus_gemm/include/opus_gemm_lookup_entry.cuh) replaces three per-arch comparator copies. The ladder is exact CU, then a legacy cu_num=0 row, then a miss so the caller reaches its heuristic, which is what the Python lookup already does when no row matches the live count. allow_fallback gating keeps a count-less .co row from shadowing an exact-CU split-K winner, which is the rule opus_gemm.cu depends on.

Codegen filters the emitted rows and the compile set through one target resolution, so the kid set and the lookup tables cannot disagree about which arch the build serves. The generated OPUS_GFX1250_WS_PARTIAL_BYTES is static-asserted against the bf16 workspace the host allocates, so a baked kid storing a wider partial fails the build rather than overrunning the buffer.

Scope

  1. gfx1250 split-K shapes move from heuristic to tuned, and the .co shapes become CU-conditional. No CI job exercises gfx1250 (GPU_ARCH_LIST in aiter-test.yaml is gfx942;gfx950). The A/B is cheap for the split-K half, since the old path is today's heuristic. The .co half is the exposure: that lookup was shape-only and always hit, it now goes through the CU-aware search, and every .co row is stamped 256, so on silicon reporting any other count those 147 shapes fall to the heuristic instead.
  2. aiter/tuned_gemm.py is the one non-opus file here, and it is the live serving route. tuned_gemm.opus_gemm called the id dispatcher unguarded, so an unbaked id escaped and killed the rank. The dispatcher now raises unbaked_kernel_error, registered through pybind as UnbakedKernelError; try_opus_gemm_a16w16_tune catches it by type, returns False, and tuned_gemm falls back to torch_gemm, which is what the same function already does when opus is unavailable. A split-K workspace OOM is a RuntimeError too but not that type, so it still propagates. The (id, splitK) is remembered, because the dispatcher writes to stderr before it raises and a serving loop pays for that once.

Testing

op_tests/test_gemm_codegen.py, op_tests/test_opus_serving_fallback.py and op_tests/opus/test_opus_basic all pass, the last building and running on a host with no GPU. One new codegen case, test_opus_bakes_both_skus, covers per-SKU baking, both SKUs keeping their own winner, and mixed-schema CSVs with a NaN cu_num. The C++ cases cover exact-CU selection and the fallback ladder, including the miss that ends it, and test_opus_serving_fallback.py covers each serving-degradation path. ruff and black are clean.

@github-actions

github-actions Bot commented Sep 8, 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 5341 --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.

@samremes

samremes commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Review (opus lookup consumer / non-comm enablement)

This is the opus consumer of #5340 for SILOTIGER-971 / SILOTIGER-976. CU belongs in the lookup key, the shared opus_gemm_lookup_entry type is the right cleanup, and the unbaked-kid guard is real value: four keys in dsv4_bf16_tuned_gemm.csv already resolve to gfx1250 kid 21177 on any 256-CU device, which a gfx950 build does not contain. Keep this draft until #5340 lands.

Request changes on the lookup ladder before merge (P1 vs SILOTIGER-971):

The last rung returns the shape's lowest baked cu_num to any device (opus_lookup_find with allow_fallback=true). On AITER_GPU_TARGETS=gfx950:128;gfx950:256, a 128-CU part with only a 256-CU row for that shape gets the 256-CU winner. SILOTIGER-971 says never select a cu_num=256 row on 128 CU; miss must go to the default/heuristic kernel. Python lookup_tuned already keys on live CU with no fallback, so C++ and Python disagree. The cu_num=0 "legacy" rung is also dead: codegen sorts (M,N,K,cu_num) ascending, so a zero row is it. Outcome to reach: exact CU or cu_num=0 only; otherwise heuristic. If cross-SKU fallback is deliberate, it needs an opt-in and a log that names the substituted count.

Also P2:

  1. SILOTIGER-976 is still open on a gfx1250-only build. The guard matches "tune lookup table". The three dispatch unavailable for this arch AITER_CHECKs do not carry that substring, so a gfx950 kid selected on a gfx1250-only wheel still kills the rank. Root cause: runtime CSV key omits gfx, and gfx950/gfx1250 opus rows share cu_num=256 (the four colliding keys above). Put gfx in _KEY_COLUMNS / _key_from_runtime, and signal "kid not in this build" structurally rather than by message text.

  2. gfx1250 cu_num is unconfirmed. Opus rows and GFX_CU_NUM_MAP say 256; bf16_tuned_gemm.csv triton rows say 96. If the device reports 96, the exact-CU rung misses and gfx1250 "reachability" depends on the P1 rung. Confirm multiProcessorCount and stamp one count.

  3. Split-K workspace guard skips the fuse family (a16w16_clusterlaunch_tdm_splitk_fuse), which is the launcher with no runtime element_size check. Cover every baked gfx1250 kid that consumes that host workspace.

  4. _filter_opus_df_for_targets matches gfx two ways (filter_tune_df exact vs str.lower() on mixed schema). Normalize once.

P3 worth a look: per-device CU cache in opus_get_device_cu_num is now load-bearing; serving tuned_gemm.opus_gemm degrades to torch_gemm while gemm_a16w16_opus still has the opus heuristic; _arch.py swallows AITER_GPU_TARGETS typos as "unsupported device".

Series (with #5182 / #5340 / #5342)

PR Role vs SILOTIGER-971
#5182 Live XCD for swizzle (SILOTIGER-975). Kernel NUM_XCDS=8 remains SILOTIGER-977.
#5340 Build can name gfx950:128;gfx950:256 (SILOTIGER-978 mechanism). Fix active-HIP-device get_gfx() first.
#5341 Opus lookup/miss path (this PR). Last rung fights SILOTIGER-971; miss-path substring fights SILOTIGER-976.
#5342 FlyDSL GEMM AOT filter. Packaging should use the same resolved (gfx, cu_num) as CK, not arch-wide GPU_ARCHS.

Not in these PRs: 128-CU retune (SILOTIGER-972), launch heuristics (977), collectives (SILOTIGER-974).

@RElbers
RElbers force-pushed the cu-aware-targets/opus branch from fff9185 to 917c1f4 Compare September 9, 2026 15:08
@RElbers
RElbers changed the base branch from main to cu-aware-targets/gpu-target-resolution September 9, 2026 19:27
@RElbers
RElbers added this pull request to stack #5449 September 11, 2026 11:13
@RElbers
RElbers marked this pull request as ready for review September 11, 2026 11:13
@RElbers
RElbers requested a review from a team September 11, 2026 11:13
@github-actions github-actions Bot changed the title [Bugfix] Key the opus lookup on CU count, and reach gfx1250's unused tuned rows [HIP] [OPUS] [JIT] [Bugfix] Key the opus lookup on CU count, and reach gfx1250's unused tuned rows Sep 11, 2026
@RElbers RElbers changed the title [HIP] [OPUS] [JIT] [Bugfix] Key the opus lookup on CU count, and reach gfx1250's unused tuned rows [HIP] [OPUS] [JIT] [Bugfix] Stop an unbaked tuned kernel id from killing the rank, and key the lookup on CU count Sep 11, 2026
@RElbers RElbers added the ci:all label Sep 11, 2026
@RElbers
RElbers removed this pull request from stack #5449 September 11, 2026 15:19
@RElbers
RElbers force-pushed the cu-aware-targets/gpu-target-resolution branch from a44faa5 to c1736a3 Compare September 11, 2026 15:50
- Adds cu_num to the generated (M, N, K) lookup key and the tune-dict key, so
  one build holds a distinct winner per CU count of an arch.
- Shares one key type and search across the gfx942, gfx950, and gfx1250 tables
  in a new opus_gemm_lookup_entry.cuh, replacing three comparator copies.
- Resolves a shape to the running device CU count, falling back to a legacy
  count-less row and then to the shape's lowest baked count, so an untuned SKU
  is unchanged.
- Selects the gfx1250 tuned table by runtime output dtype, which is what makes
  its tuned rows reachable at all: every gfx1250 row is bf16-output, so the fp32
  table dispatch used to consult is empty and every shape fell through to the
  pre-compiled table or the heuristic.
- Publishes the widest split-K partial any baked gfx1250 kid stores and asserts
  it against the workspace this dispatch sizes, so a kid with a wider one fails
  the build rather than overrunning the buffer.
- Filters codegen rows and the compile set by (gfx, cu_num) from one target
  resolution, dropping a row that names only an ambiguous CU count, and reports
  a requested target that has no rows.
- Gates the opus arch check on the authoritative target list, adding
  has_named_targets to tell an explicit request from a bare host.
- Falls back to the default kernel when a tuned row names an id this build does
  not contain, at both callers of the id dispatcher: the opus op retries on its
  heuristic, tuned_gemm on torch. The (id, splitK) is remembered so a serving
  loop pays for the miss once, since the dispatcher writes to stderr before it
  raises. A split-K workspace OOM is a RuntimeError too and still escapes.
- Covers per-SKU baking, mixed-schema filtering, every rung of the lookup
  fallback, and each serving degradation path in the tests, including that
  tuned_gemm reaches the dispatcher through the guarded entry point.

A tuned CSV ships every target's winners while a build bakes only its own, so
a row can name a kernel this binary lacks. The live serving route is
tuned_gemm.opus_gemm, which called the id dispatcher unguarded: the raise
escaped and killed the rank. It now degrades to the default kernel, which is
required before a 128-CU CSV can be loaded in serving.

The device CU count reuses the existing one-shot hipGetDeviceProperties probe,
so runtime dispatch adds no query. For the two _ws_ families the template slot
on a table entry is the kid's split-K partial type rather than the output dtype,
so which dtype table an entry lands in does not change how it is instantiated.
- Ends the lookup ladder at the shape's count-less row, so a part with no row
  for its own CU count reaches the heuristic instead of another SKU's winner.
- Adds gfx to the opus runtime key, which two arches sharing a CU count could
  not tell apart, and keeps a row that names no arch reachable through the same
  count-less rung the C++ ladder uses.
- Raises unbaked_kernel_error for a kernel id this build does not contain, so
  the caller that falls back recognises it by type rather than by matching the
  message, and a split-K workspace failure reaching the same caller escapes.
- Takes the split-K workspace partial from the attribute each family actually
  instantiates, which brought the fused single-kernel family into the width the
  host publishes.
- Normalises the gfx column once before filtering, so the exact and mixed
  schema paths stop disagreeing about a row whose arch is spelled in caps.
- Reports an unreadable target variable as such rather than as the device's
  architecture, and at a level someone will see.
- Moves the serving fallback tests to their own file and onto the exception
  type, which the fakes that raised a matching message could not exercise.

The ladder and the Python lookup disagreed: Python returns nothing when no row
matches the live CU count, while C++ substituted the lowest count baked for
that shape. A 128 CU part therefore ran kernels tuned for 256.
- Keys the probe cache on the device ordinal, so a process that switches
  devices stops dispatching with the first one's values.
- Reuses the SynchronizedCache the CK dispatchers already cache these same two
  facts with.

The CU count only began selecting kernels when cu_num entered the lookup key,
which is what made a stale one reach another SKU's tuned winner. The arch has
always had the flaw and picks another SKU's kernels outright.
opus_lookup_find returns an exact CU match, then a count-less row, and
otherwise misses. That third tier went when the ladder stopped substituting
another SKU's winner, but the comment above the function still promised the
shape's first row and the C++ test still asserted it, on a shape whose only row
carries another count. The test therefore dereferenced the null it was handed
rather than failing.
The check sat inside the per-file filter, which _collect_csv_kids calls for
every tuned CSV, so a build printed one "falls back to the heuristic" line per
file that lacked rows for a target. A model CSV tuned for one arch has none
for another by construction, so most of those lines were false: of the shipped
CSVs carrying opus rows, seven lack gfx950 rows and seven cover them, so a
gfx950:256 build printed seven times for a target it bakes.

Moves the report to the combined frame get_tune_dict receives, which spans
every tuned CSV rather than one, and leaves the filter doing only filtering.
This is the shape build_tune_dict uses for the CK modules: one authoritative
frame, one verdict.
- Drops the cases that pinned decisions of this branch rather than behaviour
  aiter requires: the allow_fallback parameter it introduced, the binary
  search bounds and empty table, and the malformed target validation that
  belongs with the build target work.
- Asserts that every request reaches the heuristic when a tuned row names an
  unbaked kernel, rather than asserting the call count, so remembering the
  kid stays an implementation detail.
- Keys the baked lookup on gfx and cu_num, where keying on M and cu_num
  discarded the arch and reproduced the collapse this branch prevents.
- Matches each emitted lookup entry to its own kernel, which four independent
  substring checks could not tell apart from a cross wired one.
- Fails rather than skips when the kernel registry cannot supply the fixture,
  since a skip reports the same green as a passing run.
- Writes the fixture CSVs into the temporary directory the test already
  opens, which removes the bookkeeping it was carrying.

A test is a specification: each one says a future change must preserve it.
The dropped cases specified an internal parameter, the standard library's
contract, and another branch's validation, none of which aiter requires of
this code.
@RElbers
RElbers force-pushed the cu-aware-targets/opus branch from 2165534 to 0b359e0 Compare September 11, 2026 16:42
@zufayu
zufayu requested review from yifehuan and zufayu September 14, 2026 01:44
@zufayu

zufayu commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Advisory review (static + hand-run; not a merge gate). Validation/Perf ran no GPU stage — reasons are on their lines below. Findings tagged [verified] are traced to code/repro.

Makes the opus id-dispatchers raise a dedicated UnbakedKernelError that tuned_gemm catches and answers with a remembered torch fallback, and re-keys the generated opus a16w16 lookup tables on (M, N, K, CU count) so one build can carry a tuned winner per SKU of one arch.

Review (advisory): ⚠️ NEEDS WORK
Validation (deterministic): NOT RUN — auto-validation disabled (REVIEW_AUTO_VALIDATE=0); the added target op_tests/test_opus_serving_fallback.py was run by hand on the full head tree (3 passed), op_tests/opus/test_opus_basic was built and run on this gfx942 host (lookup tests passed), and the pybind exception chain was verified with a minimal TU built against csrc/include/aiter_hip_common.h, but no head-matched report exists
Perf (advisory): NOT RUN — the target ships no benchmark entry point, and the perf-relevant changes are gfx1250-only while this host is gfx942/304 where no checked-in opus row matches (the gfx942 opus rows are all 80-CU), so the tuned path cannot be hand-timed here

⚠️ [verified] The fix covers the a16w16 route only: aiter/ops/gemm_op_a8w8.py (unchanged by this PR) still dispatches libtype=="opus" rows straight into opus_gemm_a8w8_blockscale_bpreshuffle_tune with no catch, while this PR made the gfx942 a8w8 id dispatcher (opus_a8w8_tune_dispatch_gfx942, csrc/opus_gemm/include/gfx942/opus_gemm_arch_gfx942.cuh) raise the new unbaked_kernel_error — so a tuned a8w8 row naming a kid this build lacks still propagates uncaught out of gemm_a8w8_blockscale_bpreshuffle, the same rank-killing escape the PR title says it stops. No checked-in a8w8 CSV carries an opus row today (verified: 0 opus rows in all six a8w8_blockscale_bpreshuffle CSVs), so the exposure is latent until the first a8w8 opus CSV ships. Author must either route the a8w8 opus branch through the same remember-and-fall-back wrapper (falling back to the ck path), or state on the PR that the a8w8 route is deliberately out of scope.
⚠️ [verified] The whole gfx1250 dispatch ladder in csrc/opus_gemm/opus_gemm.cu is rewired (exact-CU .co, then exact-CU split-K, then legacy .co, then heuristic) and the .co lookup becomes CU-conditional, but no CI job builds or runs opus on gfx1250 (.github/workflows/aiter-test.yaml pins GPU_ARCH_LIST to "gfx942;gfx950") and the PR reports no hardware run; the PR body itself discloses that every .co row is stamped cu_num=256, so on gfx1250 silicon reporting any other CU count the 147 .co shapes fall to the heuristic, and the 150 split-K winners that just became reachable have never served a request anywhere. Reviewer should ask for one gfx1250-device run of the tuned shapes, or confirmation that every supported gfx1250 SKU reports 256 CUs, before merge.
⚠️ [verified] No base-vs-head timing exists for a dispatch change whose gfx1250 half is perf-motivated (150 winners moving heuristic to tuned, plus the .co exposure above): the added test target ships no benchmark entry point, auto-validation is disabled, and this gfx942/304 host matches no checked-in opus row, so the change also cannot be hand-timed here. Author must attach a gfx1250 (and ideally a multi-SKU gfx950) before/after timing for the tuned shapes, or mark the perf expectation unverified on the PR.
📝 [verified] test_opus_serving_fallback.py fakes the exception type (_FakeUnbaked stands in for the pybind-registered UnbakedKernelError), so no CI test exercises the real chain — C++ unbaked_kernel_error, pybind translation, Python isinstance catch; a future rename of the module or the exception would pass CI green. The chain was verified out-of-band here with a minimal pybind TU (the registered type isinstance-checks as RuntimeError and as itself; a plain runtime_error does not), but that verification is not in the repo. Reviewer should ask for one GPU test that triggers a real unbaked id through the built module.
📝 [verified] aiter/tuned_gemm.py is a Tier-2 backbone file whose documented failure mode is exactly "silent fallback to slow path", and this PR converts a rank-fatal unbaked id into a one-time-warning torch fallback there; the PR author has no commits to that file (top committers yzhou103, valarLip). Reviewer should ask the de-facto owner to acknowledge the crash-to-fallback semantics change on the PR before merge.

@yifehuan
yifehuan requested a review from demonsan September 17, 2026 08:15
@RElbers

RElbers commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor Author

#4961 made most of this obsolete

@RElbers RElbers closed this Sep 17, 2026
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