Skip to content

[ROCm][Inductor] Support CK-Tile universal GEMM API change in ROCm 7.14 - #189646

Closed
jagadish-amd wants to merge 9 commits into
pytorch:mainfrom
jagadish-amd:ck-tile_universal_gemm
Closed

jagadish-amd wants to merge 9 commits into
pytorch:mainfrom
jagadish-amd:ck-tile_universal_gemm

Conversation

@jagadish-amd

@jagadish-amd jagadish-amd commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

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

@pytorch-bot

pytorch-bot Bot commented Jul 12, 2026 •

Copy link
Copy Markdown

🔗 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 Failures

As of commit ff4564b with merge base e915d5f (image):

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.

@pytorch-bot pytorch-bot Bot added ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests module: inductor module: rocm AMD GPU support for Pytorch labels Jul 12, 2026
@pytorch-bot

pytorch-bot Bot commented Jul 12, 2026 •

Copy link
Copy Markdown

Workflows were awaiting approval. CI has now been triggered for the ciflow labels on this PR.

@pytorch-bot

pytorch-bot Bot commented Jul 12, 2026

Copy link
Copy Markdown

The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:

  • ciflow/inductor
  • ciflow/torchtitan

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.

@jagadish-amd

Copy link
Copy Markdown
Contributor Author

@pytorchbot label "topic: not user facing"

@pytorch-bot pytorch-bot Bot added the topic: not user facing topic category label Jul 12, 2026
@jithunnair-amd jithunnair-amd added ciflow/rocm-nightly Trigger "default" config CI on a nightly build of ROCm from theRock on MI300 ciflow/rocm-mi355 Trigger "default" config CI on ROCm MI355 runners ciflow/rocm-mi300 Trigger "default" config CI on ROCm MI300 labels Jul 13, 2026
@pytorch-bot

pytorch-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown

Warning: Unknown label ciflow/rocm-mi355.
Currently recognized labels are

  • ciflow/b200
  • ciflow/b200-distributed
  • ciflow/b200-symm-mem
  • ciflow/binaries
  • ciflow/binaries_libtorch
  • ciflow/binaries_wheel
  • ciflow/docker
  • ciflow/dtensor
  • ciflow/dynamo
  • ciflow/h100
  • ciflow/h100-cutlass-backend
  • ciflow/h100-distributed
  • ciflow/h100-symm-mem
  • ciflow/inductor
  • ciflow/inductor-cu126
  • ciflow/inductor-micro-benchmark
  • ciflow/inductor-micro-benchmark-cpu-x86
  • ciflow/inductor-pallas
  • ciflow/inductor-perf-compare
  • ciflow/inductor-perf-test-nightly-rocm-mi300
  • ciflow/inductor-perf-test-nightly-rocm-mi350
  • ciflow/inductor-perf-test-nightly-x86-zen
  • ciflow/inductor-perf-test-nightly-xpu
  • ciflow/inductor-periodic
  • ciflow/inductor-rocm-mi200
  • ciflow/inductor-rocm-mi300
  • ciflow/mps
  • ciflow/nightly
  • ciflow/op-benchmark
  • ciflow/periodic
  • ciflow/periodic-rocm-mi200
  • ciflow/periodic-rocm-mi300
  • ciflow/pull
  • ciflow/riscv64
  • ciflow/rocm-mi200
  • ciflow/rocm-mi300
  • ciflow/rocm-navi31
  • ciflow/rocm-nightly
  • ciflow/s390
  • ciflow/slow
  • ciflow/slow-rocm-mi200
  • ciflow/torchtitan
  • ciflow/triton_binaries
  • ciflow/trunk
  • ciflow/tsan
  • ciflow/unstable
  • ciflow/vllm
  • ciflow/win-arm64
  • ciflow/xpu

Please add the new label to .github/pytorch-probot.yml

@jagadish-amd
jagadish-amd marked this pull request as ready for review July 13, 2026 17:08

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

LGTM assuming you were able to test in a 7.14 environment (not sure we have that in CI).

@jagadish-amd

Copy link
Copy Markdown
Contributor Author

LGTM assuming you were able to test in a 7.14 environment (not sure we have that in CI).

yes, also adding nightly label.

@jithunnair-amd jithunnair-amd added the ciflow/trunk Trigger trunk jobs on your pull request label Jul 14, 2026
@albanD albanD added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Jul 14, 2026
@albanD
albanD requested a review from jeffdaily July 14, 2026 14:23
@jithunnair-amd jithunnair-amd added ciflow/periodic-rocm-mi300 Trigger "distributed" config CI on ROCm MI300/MI325 ciflow/inductor-rocm-mi300 Trigger "inductor" config CI on ROCm MI300/MI325 ciflow/rocm-mi200 Trigger "default" config CI on ROCm MI200 ciflow/periodic-rocm-mi200 Trigger "distributed" config CI on ROCm MI200 ciflow/inductor-rocm-mi200 Trigger "inductor" config CI on ROCm MI200 keep-going Don't stop on first failure, keep running tests until the end labels Jul 18, 2026

@jeffdaily jeffdaily left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 carries HasHotLoop_, so a wider window would report v1 on a v2 header.
  • The ELayout change 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.hip fallback. CK, like ordinary C++, writes the template parameter list above the struct name, so the parameters belonging to UniversalGemmPipelineProblem sit behind the anchor, not ahead of it. _header_has_v2_universal_gemm_pipeline searches 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) None
third_party/composable_kernel 10604 10102 (-502) 15287 (+4683) None
third_party/flash-attention/csrc/... 9818 9374 (-444) 13915 (+4097) None
third_party/fbgemm/external/... 7339 6944 (-395) none None

Every forward hit exceeds _HEADER_SCHEDULER_MAX_DISTANCE = 4000, so _ck_tile_universal_gemm_v2_api returns None and 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/include and returns False via 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.hpp is FlatmmPipelineProblem (line 322), whose parameter list is ..., GemmPipelineScheduler Scheduler_, bool HasHotLoop_, TailNumber TailNum_, ..., structurally identical to the legacy UniversalGemmPipelineProblem. So a larger _HEADER_SCHEDULER_MAX_DISTANCE would 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 preceding template<. A bounded backward scan (900 chars) gives the correct answer on all four copies, including distinguishing the v1 /opt/rocm header from the v2 third_party/composable_kernel one.

_ck_tile_rocm_include_dir lines 39-47 are unreachable, and the whole helper duplicates existing code. cpp_extension.ROCM_HOME is _find_rocm_home(), which already consults ROCM_HOME, then ROCM_PATH, then _rocm_sdk_core, then hipcc on PATH, then /opt/rocm. If line 37 sees a falsy value, the manual env re-check on lines 39-41 cannot succeed, and _join_rocm_home reads that same module global and raises OSError. Separately, torch/_inductor/codegen/rocm/compile_command.py:12-47 (_rocm_include_paths) already implements the canonical config.rocm.rocm_home or cpp_extension._join_rocm_home("include") precedence and is what actually builds the -I line.

use_v2_api is computed independently in emit_ck_instance (line 770) and render (line 850), with consistency resting on functools.cache. render already calls emit_ck_instance; compute the flag once in render and pass it down, so the instance definition and the launch site cannot disagree.

Code Quality

The ELayout fix 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; where CLayout is a type alias is a hard compile error (error: expected primary-expression before ';' token), and cshuffle_epilogue.hpp:39 declares ELayout_ as a typename anyway. gen_ops() emits for epilogue in ["Default", "CShuffle"] across all three pipeline families, and filter_op rejects 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 via log.exception on a by-default-silenced inductor logger, marked failed, and pruned at select_algorithm.py:4473; create_no_valid_choices fires only if every choice fails, which never happens because the Default instances compile.

Testing

test_header_probe_legacy_api and test_header_probe_v2_api assert against a header layout that cannot exist. Both synthetic bodies place template<...> inside struct 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 None in practice, the torch.version.hip >= (7, 14) fallback is the only live decision path, and nothing exercises it, nor the unreadable-header path, nor the ambiguous-None path.

Nothing verifies the emitted v2 C++ compiles. test_emit_v2_simplified_instance only checks substring presence. The whole risk of this PR is whether the simplified UniversalGemmPipelineProblem plus non-templated GemmKernel instantiation 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 moment emit_ck_instance touches instance state; tempfile and unittest.mock.patch are imported inside test bodies while test_ck_backend.py imports os/unittest at module level; and the new class does not reuse TestCKBackend.setUp's try_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.py has no explicit --include anywhere in .ci/pytorch/test.sh; it only rides the generic inductor sweep, and the sole nightly-image inductor shards on this PR are marked unstable and are already red against known issue #181648. The v2 path currently rests entirely on a local run.

@jagadish-amd

jagadish-amd commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor Author

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 carries HasHotLoop_, so a wider window would report v1 on a v2 header.
  • The ELayout change 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.hip fallback. CK, like ordinary C++, writes the template parameter list above the struct name, so the parameters belonging to UniversalGemmPipelineProblem sit behind the anchor, not ahead of it. _header_has_v2_universal_gemm_pipeline searches 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)
None

third_party/composable_kernel
10604
10102 (-502)
15287 (+4683)
None

third_party/flash-attention/csrc/...
9818
9374 (-444)
13915 (+4097)
None

third_party/fbgemm/external/...
7339
6944 (-395)
none
None

Every forward hit exceeds _HEADER_SCHEDULER_MAX_DISTANCE = 4000, so _ck_tile_universal_gemm_v2_api returns None and 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/include and returns False via 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.hpp is FlatmmPipelineProblem (line 322), whose parameter list is ..., GemmPipelineScheduler Scheduler_, bool HasHotLoop_, TailNumber TailNum_, ..., structurally identical to the legacy UniversalGemmPipelineProblem. So a larger _HEADER_SCHEDULER_MAX_DISTANCE would 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 preceding template<. A bounded backward scan (900 chars) gives the correct answer on all four copies, including distinguishing the v1 /opt/rocm header from the v2 third_party/composable_kernel one.
_ck_tile_rocm_include_dir lines 39-47 are unreachable, and the whole helper duplicates existing code. cpp_extension.ROCM_HOME is _find_rocm_home(), which already consults ROCM_HOME, then ROCM_PATH, then _rocm_sdk_core, then hipcc on PATH, then /opt/rocm. If line 37 sees a falsy value, the manual env re-check on lines 39-41 cannot succeed, and _join_rocm_home reads that same module global and raises OSError. Separately, torch/_inductor/codegen/rocm/compile_command.py:12-47 (_rocm_include_paths) already implements the canonical config.rocm.rocm_home or cpp_extension._join_rocm_home("include") precedence and is what actually builds the -I line.
use_v2_api is computed independently in emit_ck_instance (line 770) and render (line 850), with consistency resting on functools.cache. render already calls emit_ck_instance; compute the flag once in render and pass it down, so the instance definition and the launch site cannot disagree.

Code Quality

The ELayout fix 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; where CLayout is a type alias is a hard compile error (error: expected primary-expression before ';' token), and cshuffle_epilogue.hpp:39 declares ELayout_ as a typename anyway. gen_ops() emits for epilogue in ["Default", "CShuffle"] across all three pipeline families, and filter_op rejects 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 via log.exception on a by-default-silenced inductor logger, marked failed, and pruned at select_algorithm.py:4473; create_no_valid_choices fires only if every choice fails, which never happens because the Default instances compile.

Testing

test_header_probe_legacy_api and test_header_probe_v2_api assert against a header layout that cannot exist. Both synthetic bodies place template<...> inside struct 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 None in practice, the torch.version.hip >= (7, 14) fallback is the only live decision path, and nothing exercises it, nor the unreadable-header path, nor the ambiguous-None path.
Nothing verifies the emitted v2 C++ compiles. test_emit_v2_simplified_instance only checks substring presence. The whole risk of this PR is whether the simplified UniversalGemmPipelineProblem plus non-templated GemmKernel instantiation 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 moment emit_ck_instance touches instance state; tempfile and unittest.mock.patch are imported inside test bodies while test_ck_backend.py imports os/unittest at module level; and the new class does not reuse TestCKBackend.setUp's try_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.py has no explicit --include anywhere in .ci/pytorch/test.sh; it only rides the generic inductor sweep, and the sole nightly-image inductor shards on this PR are marked unstable and are already red against known issue #181648. The v2 path currently rests entirely on a local run.

"falls through to the torch.version.hip comparison every time" --> This is true, verified and its always hitting fallback path.
I have fixed it.

AI analysis after new commit
Header probe: The forward search was wrong for real ck_tile headers (template params sit above struct UniversalGemmPipelineProblem). The probe now scans backward from the struct to the preceding template<> block and compares AElementWise_ vs HasHotLoop_ after Scheduler_. Added test_header_probe_does_not_use_later_flatmm_signature so we don’t misread FlatmmPipelineProblem. Tests now use outer-template fixtures matching ROCm 7.14 headers, plus fallback-path coverage.

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.

@jagadish-amd
jagadish-amd force-pushed the ck-tile_universal_gemm branch from c13f62a to daa02bb Compare July 24, 2026 05:15
Signed-off-by: Jagadish Krishnamoorthy <[email protected]>
Signed-off-by: Jagadish Krishnamoorthy <[email protected]>
…e before UniversalGemmPipelineProblem.

Signed-off-by: Jagadish Krishnamoorthy <[email protected]>
@jagadish-amd
jagadish-amd force-pushed the ck-tile_universal_gemm branch from 1c81768 to 93bf12f Compare August 11, 2026 23:36
@jagadish-amd
jagadish-amd requested a review from a team as a code owner August 12, 2026 20:23
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 jeffdaily left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@jeffdaily

Copy link
Copy Markdown
Collaborator

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your 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

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 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 team Raised by workflow job

@jeffdaily

Copy link
Copy Markdown
Collaborator

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

@jagadish-amd
jagadish-amd deleted the ck-tile_universal_gemm branch August 17, 2026 23:57
pytorchmergebot pushed a commit that referenced this pull request Aug 25, 2026
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]>
orrangetabby17 pushed a commit to orrangetabby17/pytorch that referenced this pull request Sep 2, 2026
…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]>
orrangetabby17 pushed a commit to orrangetabby17/pytorch that referenced this pull request Sep 2, 2026
…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]>
pytorchmergebot pushed a commit that referenced this pull request Sep 25, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/inductor ciflow/inductor-rocm-mi200 Trigger "inductor" config CI on ROCm MI200 ciflow/inductor-rocm-mi300 Trigger "inductor" config CI on ROCm MI300/MI325 ciflow/periodic-rocm-mi200 Trigger "distributed" config CI on ROCm MI200 ciflow/periodic-rocm-mi300 Trigger "distributed" config CI on ROCm MI300/MI325 ciflow/rocm-mi200 Trigger "default" config CI on ROCm MI200 ciflow/rocm-mi300 Trigger "default" config CI on ROCm MI300 ciflow/rocm-mi355 Trigger "default" config CI on ROCm MI355 runners ciflow/rocm-nightly Trigger "default" config CI on a nightly build of ROCm from theRock on MI300 ciflow/torchtitan Run TorchTitan integration tests ciflow/trunk Trigger trunk jobs on your pull request keep-going Don't stop on first failure, keep running tests until the end Merged module: inductor module: rocm AMD GPU support for Pytorch open source topic: not user facing topic category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants