Repository navigation
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
PR title tags & labels: |
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 Request changes on the lookup ladder before merge (P1 vs SILOTIGER-971): The last rung returns the shape's lowest baked Also P2:
P3 worth a look: per-device CU cache in Series (with #5182 / #5340 / #5342)
Not in these PRs: 128-CU retune (SILOTIGER-972), launch heuristics (977), collectives (SILOTIGER-974). |
fff9185 to
917c1f4
Compare
a44faa5 to
c1736a3
Compare
- 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.
2165534 to
0b359e0
Compare
|
Advisory review (static + hand-run; not a merge gate). Validation/Perf ran no GPU stage — reasons are on their lines below. Findings tagged 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):
|
|
#4961 made most of this obsolete |
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_gemmcatches 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 asgfx:cu_numpairs, as inAITER_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.curesolved every gfx1250 shape throughopus_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.cowinners did dispatch, through the separate.colookup 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 legacycu_num=0row, 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_fallbackgating keeps a count-less.corow from shadowing an exact-CU split-K winner, which is the ruleopus_gemm.cudepends 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_BYTESis 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
.coshapes become CU-conditional. No CI job exercises gfx1250 (GPU_ARCH_LISTinaiter-test.yamlisgfx942;gfx950). The A/B is cheap for the split-K half, since the old path is today's heuristic. The.cohalf is the exposure: that lookup was shape-only and always hit, it now goes through the CU-aware search, and every.corow is stamped 256, so on silicon reporting any other count those 147 shapes fall to the heuristic instead.aiter/tuned_gemm.pyis the one non-opus file here, and it is the live serving route.tuned_gemm.opus_gemmcalled the id dispatcher unguarded, so an unbaked id escaped and killed the rank. The dispatcher now raisesunbaked_kernel_error, registered through pybind asUnbakedKernelError;try_opus_gemm_a16w16_tunecatches it by type, returns False, andtuned_gemmfalls back totorch_gemm, which is what the same function already does when opus is unavailable. A split-K workspace OOM is aRuntimeErrortoo 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.pyandop_tests/opus/test_opus_basicall 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 NaNcu_num. The C++ cases cover exact-CU selection and the fallback ladder, including the miss that ends it, andtest_opus_serving_fallback.pycovers each serving-degradation path.ruffandblackare clean.