Repository navigation
[ROCm][Inductor] Support CK-Tile universal GEMM API change in ROCm 7.14 - #189646
jagadish-amd wants to merge 9 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/189646
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New Failure, 14 Unrelated FailuresAs of commit ff4564b with merge base e915d5f ( NEW FAILURE - The following job has failed:
FLAKY - The following jobs failed but were likely due to flakiness present on trunk:
UNSTABLE - The following jobs are marked as unstable, possibly due to flakiness on trunk:
CRCR (non-blocking) - The following CRCR downstream CI jobs failed but are non-blocking:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
|
|
The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:
Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows. |
|
@pytorchbot label "topic: not user facing" |
|
Warning: Unknown label
Please add the new label to .github/pytorch-probot.yml |
alugorey
left a comment
There was a problem hiding this comment.
LGTM assuming you were able to test in a 7.14 environment (not sure we have that in CI).
yes, also adding nightly label. |
jeffdaily
left a comment
There was a problem hiding this comment.
Requesting changes based on an AI-assisted pass over the detection logic. The finding I want to highlight: the header probe added in the third commit appears never to return a decision on a real ck_tile header, so _ck_tile_universal_gemm_v2_api falls through to the torch.version.hip comparison every time. CK writes the template parameter list above the struct name, but _header_has_v2_universal_gemm_pipeline searches forward from UniversalGemmPipelineProblem, so it can only reach some later struct's parameters. The measurements below were taken against a ROCm 7.2.1 install; @jagadish-amd, worth reproducing on your 7.14 environment before you act on it.
Two points that need a judgement call rather than a mechanical fix:
- Widening the distance constant is not the fix. The next struct forward is
FlatmmPipelineProblem, whose signature still carriesHasHotLoop_, so a wider window would report v1 on a v2 header. - The
ELayoutchange looks like an unrelated fix that deserves its own callout, since it implies every CShuffle-epilogue instance has been failing to compile and getting pruned by autotuning without surfacing.
Claude's full analysis:
Summary
Branches CK-Tile GEMM codegen between the legacy
has_hot_loop/tail_number-templated pipeline problem and the simplified ROCm 7.14+UniversalGemmPipelineProblem, detecting which by text-probing$ROCM_HOME/include/ck_tile/ops/gemm/pipeline/gemm_pipeline_problem.hpp. The header probe does not work on any real ck_tile header, and the tests pass only because they assert against a synthetic header whose layout is not valid C++.Infrastructure
The header probe never returns a decision; every call falls through to the
torch.version.hipfallback. CK, like ordinary C++, writes the template parameter list above the struct name, so the parameters belonging toUniversalGemmPipelineProblemsit behind the anchor, not ahead of it._header_has_v2_universal_gemm_pipelinesearches forward (header_text.find(_SCHEDULER_PARAM, pos)), so it can never reach them. Measured on the installed ROCm 7.2.1 header, which is the one hipcc actually uses for#include "ck_tile/ops/gemm.hpp":
header copy anchor offset correct Scheduler_next forward Scheduler_probe result /opt/rocm/include(7.2.1)9929 9371 (-558) 13962 (+4033) Nonethird_party/composable_kernel10604 10102 (-502) 15287 (+4683) Nonethird_party/flash-attention/csrc/...9818 9374 (-444) 13915 (+4097) Nonethird_party/fbgemm/external/...7339 6944 (-395) none NoneEvery forward hit exceeds
_HEADER_SCHEDULER_MAX_DISTANCE = 4000, so_ck_tile_universal_gemm_v2_apireturnsNoneand falls back to the version compare in all four cases. Confirmed end-to-end by loading the module directly: on a ROCm 7.2 box it resolves the include dir to/opt/rocm/includeand returnsFalsevia the fallback, not via the header. The PR therefore ships exactly the "rely on hip version" behavior the third commit set out to replace, plus about 60 lines of inert probe code.Widening the window would make the probe confidently wrong rather than fixing it. The next struct forward in
/opt/rocm/include/.../gemm_pipeline_problem.hppisFlatmmPipelineProblem(line 322), whose parameter list is..., GemmPipelineScheduler Scheduler_, bool HasHotLoop_, TailNumber TailNum_, ..., structurally identical to the legacyUniversalGemmPipelineProblem. So a larger_HEADER_SCHEDULER_MAX_DISTANCEwould read Flatmm's parameters and report v1 on a genuine v2 header: the precise failure this PR exists to prevent, now silent. The fix is directional, not a tuning of the constants: scan backwards from the struct name to the precedingtemplate<. A bounded backward scan (900 chars) gives the correct answer on all four copies, including distinguishing the v1/opt/rocmheader from the v2third_party/composable_kernelone.
_ck_tile_rocm_include_dirlines 39-47 are unreachable, and the whole helper duplicates existing code.cpp_extension.ROCM_HOMEis_find_rocm_home(), which already consultsROCM_HOME, thenROCM_PATH, then_rocm_sdk_core, thenhipcconPATH, then/opt/rocm. If line 37 sees a falsy value, the manual env re-check on lines 39-41 cannot succeed, and_join_rocm_homereads that same module global and raisesOSError. Separately,torch/_inductor/codegen/rocm/compile_command.py:12-47(_rocm_include_paths) already implements the canonicalconfig.rocm.rocm_home or cpp_extension._join_rocm_home("include")precedence and is what actually builds the-Iline.
use_v2_apiis computed independently inemit_ck_instance(line 770) andrender(line 850), with consistency resting onfunctools.cache.renderalready callsemit_ck_instance; compute the flag once inrenderand pass it down, so the instance definition and the launch site cannot disagree.Code Quality
The
ELayoutfix is an unrelated bug fix, unmentioned in the title, and it exposes that the entire CShuffle epilogue path has been dead.constexpr auto ELayout = CLayout;whereCLayoutis a type alias is a hard compile error (error: expected primary-expression before ';' token), andcshuffle_epilogue.hpp:39declaresELayout_as atypenameanyway.gen_ops()emitsfor epilogue in ["Default", "CShuffle"]across all three pipeline families, andfilter_oprejects CShuffle only on an unrelated N-alignment check, so roughly half the autotune candidate space has been failing to compile. Those failures are caught in the precompile future, logged vialog.exceptionon a by-default-silenced inductor logger, marked failed, and pruned atselect_algorithm.py:4473;create_no_valid_choicesfires only if every choice fails, which never happens because the Default instances compile.Testing
test_header_probe_legacy_apiandtest_header_probe_v2_apiassert against a header layout that cannot exist. Both synthetic bodies placetemplate<...>insidestruct UniversalGemmPipelineProblem { ... }. That is not valid C++ and does not match any real ck_tile header. The tests pass precisely because they were written to match the probe's incorrect assumption rather than the real header, so they validate the bug instead of catching it. Point them at a fixture copied from a real header (both a v1 and a v2 shape), or at the installed header when present.No test covers the code path that actually runs. Since the probe always returns
Nonein practice, thetorch.version.hip >= (7, 14)fallback is the only live decision path, and nothing exercises it, nor the unreadable-header path, nor the ambiguous-Nonepath.Nothing verifies the emitted v2 C++ compiles.
test_emit_v2_simplified_instanceonly checks substring presence. The whole risk of this PR is whether the simplifiedUniversalGemmPipelineProblemplus non-templatedGemmKernelinstantiation is well-formed, and no test or CI job establishes that.Test hygiene deviates from the file's conventions.
object.__new__(tmpl)bypasses__init__and will break the momentemit_ck_instancetouches instance state;tempfileandunittest.mock.patchare imported inside test bodies whiletest_ck_backend.pyimportsos/unittestat module level; and the new class does not reuseTestCKBackend.setUp'stry_import_ck_lib()skip, so it silently diverges from how every other test in the file gates on CK.Backward Compatibility
tuple(int(v) for v in torch.version.hip.split(".")[:2])matches the established idiom (common_cuda.py:29,cpp_extension.py:355,mm_grouped.py:169). But the fallback compares the HIP runtime version against a threshold describing ck_tile header content, and those are independently versioned. The comment "conventionally aligned with ROCm" is doing a lot of load-bearing work for what is now, in practice, the sole detection mechanism.On CI validation
test_ck_backend.pyhas no explicit--includeanywhere in.ci/pytorch/test.sh; it only rides the generic inductor sweep, and the sole nightly-image inductor shards on this PR are markedunstableand are already red against known issue #181648. The v2 path currently rests entirely on a local run.
"falls through to the AI analysis after new commit Infrastructure: Removed duplicate _ck_tile_rocm_include_dir in favor of shared _rocm_system_include_dir; use_v2_api is computed once in render() and passed into emit_ck_instance and launch rendering; _rocm_system_include_dir is inside the same try/except OSError so missing ROCM_HOME falls back to torch.version.hip instead of raising. Testing: CK-lib skip is scoped to the two emit tests only — header-probe and launch-template tests run without a full SDK. ELayout: Fixed separately (using ELayout = CLayout instead of invalid constexpr auto); called out in the PR description since it was a pre-existing silent failure on the CShuffle epilogue path. Verified locally on ROCm 7.14 and ROCm 7.2: probe returns v2/v1 respectively from /opt/rocm/include/.../gemm_pipeline_problem.hpp without hitting the HIP fallback, and TestCKTileUniversalGemmTemplate passes. |
c13f62a to
daa02bb
Compare
Signed-off-by: Jagadish Krishnamoorthy <[email protected]>
Signed-off-by: Jagadish Krishnamoorthy <[email protected]>
Signed-off-by: Jagadish Krishnamoorthy <[email protected]>
…e before UniversalGemmPipelineProblem. Signed-off-by: Jagadish Krishnamoorthy <[email protected]>
Signed-off-by: Jagadish Krishnamoorthy <[email protected]>
Signed-off-by: Jagadish Krishnamoorthy <[email protected]>
1c81768 to
93bf12f
Compare
Signed-off-by: Jagadish Krishnamoorthy <[email protected]>
test_offered_instance_compiles hard-fails on ROCm hosts with neither ck4inductor nor system ck_tile headers: filter_op still offers instances via the version fallback, and the compile then fails on the missing include. Skip in that case, the same way test_header_probe_on_installed_header does. Also assert on ck_tile::GemmPipelineProblem< in test_emit_v1_legacy_instance, since bare GemmPipelineProblem also matches UniversalGemmPipelineProblem, which both API variants emit, so the assertion could not detect loss of the legacy alias. Test Plan: Ran the full TestCKTileUniversalGemmTemplate class with these changes overlaid on an installed torch build (ROCm 7.14, gfx90a, no ck4inductor installed): 24 tests, 17 pass, 7 environment skips. ``` python3 test/inductor/test_ck_backend.py TestCKTileUniversalGemmTemplate -v ``` On this host test_offered_instance_compiles failed before this change and skips after it, confirming the guard. Authored with Claude Code.
jeffdaily
left a comment
There was a problem hiding this comment.
Approving. The header probe is the right call (keying the API choice off the headers the kernels actually compile against rather than torch.version.hip), and the new template tests plus the restored CKTILE subtest give this solid regression coverage.
I pushed two small test fixes to the branch: test_offered_instance_compiles now skips instead of hard-failing on hosts without ck_tile headers (my dev box hit this), and the v1 emission assertion now checks for ck_tile::GemmPipelineProblem< so it cannot be satisfied by the UniversalGemmPipelineProblem substring that both API variants emit.
One latent bug to pick up in a follow-up PR: the CKTILE backend currently offers zero autotune choices for float16. ops() names half-precision instances "FP16" but check_dtypes compares against _TORCH_DTYPE_TO_CK[torch.float16] == "F16", so every fp16 instance is silently filtered out; your new tests work around this by hardcoding bfloat16. The fix needs the ops() datatype naming and the ck_dtype_to_size keys in ck_tile_template.py brought into agreement. @jagadish-amd please take that one as the next change.
Review notes and test fixes drafted with Claude Code; reviewed and approved by me.
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Merge failedReason: 1 jobs have failed, first few of them are: trunk / linux-jammy-rocm-py3.10-mi350 / test (default, 6, 8, linux.rocm.gpu.gfx950.1) Details for Dev Infra teamRaised by workflow job |
|
Claude determined none of the CI failures here are caused by this PR, and there was positive evidence in the CI logs that this PR was working and evaluated. @pytorchbot merge -i |
Fix CK-Tile float16 autotune silently dropping all fp16 GEMM kernels. ops() named half-precision instances "FP16" while check_dtypes compared against _TORCH_DTYPE_TO_CK[float16] == "F16", so every fp16 kernel was filtered out before autotuning. Rename catalog labels to "F16" to match the existing C++ alias in globals(). Also decouple the universal GEMM dtype catalog from ck_dtype_to_size. GEMM_DTYPES explicitly declares which dtypes get GEMM instances. ck_dtype_to_size remains for alignment and padding math only. _CK_DTYPE_ALIASES is the single source of truth for C++ using aliases, and globals() renders from it. Tests parametrize fp16 and bf16 across template emit and compile coverage, and assert that ops() implements GEMM_DTYPES, that rendered globals() matches _CK_DTYPE_ALIASES, and that every GEMM dtype has a size-table entry. This is a follow-up to the CK-Tile inductor GEMM fix #189646 Authored with Cursor Grok 4.6. Pull Request resolved: #193902 Approved by: https://github.com/jeffdaily Co-authored-by: Jeff Daily <[email protected]>
…14 (pytorch#189646) ROCm 7.14+ ck_tile headers changed UniversalGemmPipelineProblem: the simplified API no longer passes has_hot_loop / tail_number into the pipeline problem, and the generated kernel type is no longer templated on those values. Inductor still emitted the legacy signature, so CK-Tile GEMM codegen failed to compile against newer ROCm installs. Detect the API at codegen time rather than from torch.version.hip, which is frozen when PyTorch is built and says nothing about the headers these kernels actually compile against. The probe resolves ck_tile/ops/gemm/pipeline/gemm_pipeline_problem.hpp through the same ordered include list the compiler uses (the CK directory, then $ROCM_HOME), anchors on struct UniversalGemmPipelineProblem, scans backward to the preceding template clause, and compares AElementWise_ against HasHotLoop_ after GemmPipelineScheduler Scheduler_. torch.version.hip >= 7.14 remains a fallback for when the header is missing or unrecognized, but every path reaching it now logs a warning naming the reason, and an unparsable version string degrades to the legacy API instead of raising out of choice generation. Emit the legacy TailHandler / templated-kernel path for v1 headers and the simplified UniversalGemmPipelineProblem + non-templated GemmKernel path for v2, sharing one launch template between both paths. CShuffle needed two fixes. ELayout was written as an invalid constexpr assignment instead of a type alias, a pre-existing bug that made every CShuffle instance fail to compile and be silently pruned during autotune. Once they compile, they still cannot be offered against pre-v2 headers, where CShuffleEpilogueProblem takes a memory_operation_enum argument with no default whose value depends on kBatch. Emitting that argument would mean resolving kBatch before the split-K choice is made, so filter_op drops CShuffle unless the v2 probe succeeds instead; that keeps the instances out of autotuning rather than spending a failed compile on each. ck_tile removed the argument one release after it simplified the pipeline problem, so a snapshot taken between the two would be misclassified here. Both shipped ROCm releases fall on one side or the other, so this is accepted rather than adding a second probe. Review in the order the codegen runs: the include-path plumbing in compile_command.py and the header probe, then the v1/v2 emission split, then the CShuffle gate, then the tests. Patch ck4inductor's pyproject.toml at wheel-build time to package the ck_tile headers, which ROCm no longer installs system-wide. The patch is a no-op once the fix lands upstream in composable_kernel. Unskip CK Tile inductor tests which were skipped as part of pytorch#188593 Test Plan: PYTORCH_TEST_WITH_ROCM=1 python3 test/inductor/test_ck_backend.py -k standalone_cktile -v PYTORCH_TEST_WITH_ROCM=1 python3 test/inductor/test_ck_backend.py TestCKTileUniversalGemmTemplate -v Authored with Opus 5. Pull Request resolved: pytorch#189646 Approved by: https://github.com/jeffdaily Co-authored-by: Jeff Daily <[email protected]>
…193902) Fix CK-Tile float16 autotune silently dropping all fp16 GEMM kernels. ops() named half-precision instances "FP16" while check_dtypes compared against _TORCH_DTYPE_TO_CK[float16] == "F16", so every fp16 kernel was filtered out before autotuning. Rename catalog labels to "F16" to match the existing C++ alias in globals(). Also decouple the universal GEMM dtype catalog from ck_dtype_to_size. GEMM_DTYPES explicitly declares which dtypes get GEMM instances. ck_dtype_to_size remains for alignment and padding math only. _CK_DTYPE_ALIASES is the single source of truth for C++ using aliases, and globals() renders from it. Tests parametrize fp16 and bf16 across template emit and compile coverage, and assert that ops() implements GEMM_DTYPES, that rendered globals() matches _CK_DTYPE_ALIASES, and that every GEMM dtype has a size-table entry. This is a follow-up to the CK-Tile inductor GEMM fix pytorch#189646 Authored with Cursor Grok 4.6. Pull Request resolved: pytorch#193902 Approved by: https://github.com/jeffdaily Co-authored-by: Jeff Daily <[email protected]>
…el and re-enable CI tests (#195658) Advances the `rocm-composable-kernel` pin and generates the one CK header the wheel does not ship. Restores CK autotuning in CI disabled due to stale pin. ## Motivation ROCm 7.14 stopped installing the CK headers system-wide, so the inductor CK backends now compile against what the `ck4inductor` wheel ships. Every header they `#include` is checked into CK except one: `ck/config.h` is generated by CK's build from `include/ck/config.h.in`, so it exists in neither ROCm nor the wheel's source tree. Without it every CK choice fails to compile and is silently discarded, so the CK backends contribute no autotune candidates at all rather than reporting a missing header. Scope: this restores CK autotuning in CI. The ROCm CD path has routed through the Python build pipeline since #182696 and has no CK step. ## Changes **Generate `ck/config.h`** (`.ci/pytorch/rocm_utils.sh`, `.ci/pytorch/generate_ck_config_h.cmake`) `build_rocm_ck_wheel()` now generates the header for `gfx90a;gfx942;gfx950` and packages it with the rest of `include/ck`. This replaces the `ck_tile` `pyproject.toml` patch, which the new pin makes a no-op. CK's own CMake cannot produce it in the wheel-build container: `CMakeLists.txt` calls `find_package(ROCM)`, `find_package(hip REQUIRED)` and `enable_language(HIP)`, and the image has `hipcc` but no ROCm CMake packages. `config.h.in` substitutes only plain variables, so the helper sets them and runs the same `configure_file` in `cmake -P` script mode. The helper mirrors CK's arch rules rather than referencing them, so it assigns every variable unconditionally — `"ON"` or empty — instead of only in the true branch. Leaving one undefined would be indistinguishable from a deliberate OFF, which both defeats the drift check and makes the script reject any target list that does not happen to enable everything. > **Note for CI:** this step shells out to `cmake -P`, so the wheel-build image must > provide `cmake`. **Pin bump** `4266f867` → `e2daf442` The outgoing pin is from February. The new one packages the `ck_tile` headers in `pyproject.toml`, which makes the patch #189646 added to `rocm_utils.sh` a no-op. It also makes instance enumeration deterministic and duplicate-free, so a given wheel offers the same candidates on every machine instead of depending on filesystem order. This pin is also a prerequisite for follow-up PRs adding gfx1250 WMMA support. **Re-enable version-skipped tests** (`test/inductor/test_ck_backend.py`) Removes seven `skipIfRocmVersionAtLeast([7, 14])` decorators, added in #188593 (and one in #188429) for known 7.14 failures. The predicate is `>=`, so on ROCm 10.x it evaluates true and these subtests are skipped on every current ROCm CI job rather than only on the 7.14 release they were written for. ## Test plan Verified on hardware with both wheels built from this branch — the CK wheel by the real `build_rocm_ck_wheel()`, so the code under test is what produced the artifact. | Arch | Collected | Result | |---|---|---| | gfx942 (MI300X) | 84 | 76 passed, 8 skipped | | gfx942 (MI325X) | 84 | 76 passed, 8 skipped | The 8 skips are the `scaled_mm` cells, skipped upstream for unrelated reasons. @pytorchbot label "topic: not user facing" Pull Request resolved: #195658 Approved by: https://github.com/jeffdaily
ROCm 7.14+ ck_tile headers changed UniversalGemmPipelineProblem: the simplified API no longer passes has_hot_loop / tail_number into the pipeline problem, and the generated kernel type is no longer templated on those values.
Inductor still emitted the legacy signature, so CK-Tile GEMM codegen failed to compile against newer ROCm installs.
Detect the API at codegen time rather than from torch.version.hip, which is frozen when PyTorch is built and says nothing about the headers these kernels actually compile against. The probe resolves ck_tile/ops/gemm/pipeline/gemm_pipeline_problem.hpp through the same ordered include list the compiler uses (the CK directory, then $ROCM_HOME), anchors on struct UniversalGemmPipelineProblem, scans backward to the preceding template clause, and compares AElementWise_ against HasHotLoop_ after GemmPipelineScheduler Scheduler_. torch.version.hip >= 7.14 remains a fallback for when the header is missing or unrecognized, but every path reaching it now logs a warning naming the reason, and an unparsable version string degrades to the legacy API instead of raising out of choice generation.
Emit the legacy TailHandler / templated-kernel path for v1 headers and the simplified UniversalGemmPipelineProblem + non-templated GemmKernel path for v2, sharing one launch template between both paths.
CShuffle needed two fixes. ELayout was written as an invalid constexpr assignment instead of a type alias, a pre-existing bug that made every CShuffle instance fail to compile and be silently pruned during autotune. Once they compile, they still cannot be offered against pre-v2 headers, where CShuffleEpilogueProblem takes a memory_operation_enum argument with no default whose value depends on kBatch. Emitting that argument would mean resolving kBatch before the split-K choice is made, so filter_op drops CShuffle unless the v2 probe succeeds instead; that keeps the instances out of autotuning rather than spending a failed compile on each. ck_tile removed the argument one release after it simplified the pipeline problem, so a snapshot taken between the two would be misclassified here. Both shipped ROCm releases fall on one side or the other, so this is accepted rather than adding a second probe.
Review in the order the codegen runs: the include-path plumbing in compile_command.py and the header probe, then the v1/v2 emission split, then the CShuffle gate, then the tests.
Patch ck4inductor's pyproject.toml at wheel-build time to package the ck_tile headers, which ROCm no longer installs system-wide. The patch is a no-op once the fix lands upstream in composable_kernel.
Unskip CK Tile inductor tests which were skipped as part of #188593
Test Plan:
PYTORCH_TEST_WITH_ROCM=1 python3 test/inductor/test_ck_backend.py -k standalone_cktile -v
PYTORCH_TEST_WITH_ROCM=1 python3 test/inductor/test_ck_backend.py TestCKTileUniversalGemmTemplate -v
Authored with Opus 5.
cc @jeffdaily @sunway513 @jithunnair-amd @pruthvistony @ROCmSupport @jataylo @hongxiayang @naromero77amd @pragupta @jerrymannil @xinyazhang @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben