Skip to content

[ROCm][Inductor] Advance CK pin, Generate ck/config.h for the CK wheel and re-enable CI tests - #195658

Closed
andriy-ca wants to merge 4 commits into
pytorch:mainfrom
andriy-ca:gh/andriy-ca/rocm-ck-header-warning
Closed

andriy-ca wants to merge 4 commits into
pytorch:mainfrom
andriy-ca:gh/andriy-ca/rocm-ck-header-warning

Conversation

@andriy-ca

@andriy-ca andriy-ca commented Sep 2, 2026 •

Copy link
Copy Markdown

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"

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 Sep 2, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/195658

Note: Links to docs will display an error until the docs builds have been completed.

✅ You can merge normally! (5 Unrelated Failures)

As of commit 090a323 with merge base 6fac2b6 (image):

NEW FAILURES SUPPRESSED BY AI (non-blocking) - The following job failed, but the AI CI Advisor judged the failure not to be evidence against this change:

  • Build almalinux docker images / build-docker (cuda12.6) (gh) (this job did not run on the merge base, so DrCI cannot tell whether the failure is pre-existing)

    AI verdict: AI verdict: infra issue

    The Docker build failed because the remote BuildKit instance was unreachable ("context deadline exceeded" after 40 retries). The commit only modifies ROCm CK GPU target configuration and has no connection to CUDA Docker image builds.

    Full reasoning on HUD →

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:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot pytorch-bot Bot added ciflow/docker ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests module: inductor module: rocm AMD GPU support for Pytorch release notes: releng release notes category labels Sep 2, 2026
@linux-foundation-easycla

linux-foundation-easycla Bot commented Sep 2, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

@pytorch-bot

pytorch-bot Bot commented Sep 2, 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 Sep 2, 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
  • ciflow/docker

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.

1 similar comment
@pytorch-bot

pytorch-bot Bot commented Sep 2, 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
  • ciflow/docker

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.

@andriy-ca andriy-ca changed the title [ROCm] Warn when CK headers do not resolve, and advance the CK pin [ROCm][Inductor] Warn when CK headers do not resolve, and advance the CK pin Sep 2, 2026
@andriy-ca andriy-ca changed the title [ROCm][Inductor] Warn when CK headers do not resolve, and advance the CK pin [ROCm][Inductor] Advance CK pin and warn when CK headers do not resolve Sep 2, 2026
@andriy-ca

Copy link
Copy Markdown
Author

@pytorchbot label "topic: not user facing"

@pytorch-bot pytorch-bot Bot added the topic: not user facing topic category label Sep 2, 2026
@andriy-ca
andriy-ca marked this pull request as ready for review September 10, 2026 21:22
@andriy-ca
andriy-ca requested review from a team and jeffdaily as code owners September 10, 2026 21:22
@jagadish-amd

Copy link
Copy Markdown
Contributor

LGTM. I tested the PR on a system which doesn't ship ck headers, ck config.h got generated and ck inductor tests passed.
ck inductor tests were skipped in #188593 (@andriy-ca please add this PR as reference in PR summary)

@andriy-ca

Copy link
Copy Markdown
Author

LGTM. I tested the PR on a system which doesn't ship ck headers, ck config.h got generated and ck inductor tests passed. ck inductor tests were skipped in #188593 (@andriy-ca please add this PR as reference in PR summary)

Thanks for testing on a system without the CK headers. Reference added to the summary.

@jeffdaily

Copy link
Copy Markdown
Collaborator

Took a pass over this. Three things I'd like addressed before it lands, plus a note on CI. Findings below were drafted with an AI assistant and reviewed by me:

1. The remedy text contradicts the wheel change in this same PR.
_CK_HEADER_REMEDIES["ck/config.h"] in torch/_inductor/utils.py tells the user the header "is not shipped in the ck4inductor wheel; it comes from a full CK install under $ROCM_HOME/include/ck". But .ci/pytorch/rocm_utils.sh here generates that header and packages it into the wheel. After this lands the usual fix is "install a newer rocm-composable-kernel wheel", which is what the message steers the user away from.

2. The cache key does not match the roots that are actually probed.
_warn_missing_ck_header(header, ck_dir, rocm_home) keys on config.rocm.ck_dir / config.rocm.rocm_home, but never passes them to check_headers(), which resolves its own roots from TORCHINDUCTOR_CK_DIR / ROCM_HOME / ROCM_PATH (ck4inductor/util.py). Two consequences:

  • Setting torch._inductor.config.rocm.ck_dir programmatically (the path _ck_dir() in codegen/rocm/compile_command.py honors) makes the diagnostic search a different root than the compile uses, and the warning then names roots that are not the ones in play. The new _roots() helper patches both env and config, which hides this.
  • config.rocm.ck_dir defaults to None and is populated as a side effect of the first _ck_dir() call, so the key is (header, None, None) before the first compile and (header, "<path>", None) after. The same header under one configuration can warn twice, which is the "warns once" contract the tests assert.

Passing ck_dir / rocm_home through to check_headers() fixes both.

3. Nothing tests the gate call sites.
All five new tests call _warn_missing_ck_headers(...) directly, so dropping the call from use_ck_gemm_template / use_ck_tile_gemm_template / use_ck_conv_template, or a change where the enabled = ...; if enabled: ...; return enabled restructure alters the verdict, passes the suite. "Gating is unchanged" is the PR's central safety claim and is the one thing not asserted. Related: test_missing_header_warns_and_names_the_roots asserts assertIn("include", ...), but the format string already contains the literal "in any include root", so that assertion holds even if roots is empty. Assert on the temp dir path instead.

Non-blocking, but worth fixing while the mirror is fresh: generate_ck_config_h.cmake says it mirrors CK's CMakeLists.txt, and for three variables it does not. Regenerating at the pinned commit emits CK_ENABLE_DL_KERNELS ON (CK sets it only for gfx101|gfx103|gfx10-1|gfx10-3), CK_ENABLE_DPP_KERNELS ON (CK defaults DISABLE_DPP_KERNELS=ON), and CK_ENABLE_ALL_DTYPES ON (CK never sets it, and setting it flips the dtype macros from ON to "ON"). No compile impact today since none of the three is consumed by CK headers, but the drift check only catches a new placeholder, never a wrong value. Also generate_ck_config_h.cmake says the header's #if/#else "prefers OCP" when both FP8 flavors are set. It does not: both are emitted as #define ... ON, and amd_ck_fp8.hpp tests them with #if, where ON evaluates to 0, so both branches are false.

On CI: ciflow/inductor, ciflow/torchtitan and ciflow/docker are still awaiting approval, so none of this has run. A CK pin bump plus a wheel-build change plus seven re-enabled inductor tests needs mi200 and navi31 green too, not just the local gfx942 verification in the test plan.

Findings in the quoted block above were drafted with an AI assistant.

The pinned commit predates the gfx1250 work: it has no WMMA instance
enumerators, so the WMMA backends find nothing and their tests skip rather
than run. It also does not ship the CK-Tile headers in the wheel, which
ROCm no longer installs system-wide.

The new pin adds WMMA enumeration for universal GEMM, batched GEMM and
grouped convolution, ships the CK-Tile headers and the batched WMMA
instance sources, and adds a header-resolution diagnostic. Instance
enumeration is also now deterministic and duplicate-free, so the same
wheel offers the same candidates on every machine.
Seven subtests were skipped on ROCm 7.14 and above because the classic CK
path failed against the pinned Composable Kernel commit. That pin is from
May and predates six months of CK work, while CI now builds against ROCm
10.0 -- so the guard covers every ROCm job rather than the one release it
was written for, and the tests it disables never run anywhere.

The preceding pin bump is what makes them viable again: enumeration is
deterministic and duplicate-free, so a given wheel offers the same
candidates on every machine rather than depending on filesystem order.

Test IDs are unchanged, so prior runs remain comparable.
ROCm 7.14 stopped installing the CK headers system-wide, so the inductor CK
backends now compile against what the ck4inductor wheel ships. One header is
missing from that set: ck/config.h is generated by CK's build from
include/ck/config.h.in, so it is in neither the wheel nor $ROCM_HOME. Without
it every CK choice fails to compile and is silently discarded, and the user
sees an autotune with no CK candidates.

Generate it during the wheel build and package it with the rest of include/ck.

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 new helper sets them and runs the same
configure_file in cmake 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 a variable 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.

Verified against the header CK's own CMake produces: the output for
GPU_TARGETS=gfx1100 is byte-identical to /opt/rocm/include/ck/config.h from a
ROCm 7.15 install, and every CK_USE_* macro matches the gfx942, gfx950 and
gfx1250 headers shipped in their respective ROCm images.
@andriy-ca
andriy-ca force-pushed the gh/andriy-ca/rocm-ck-header-warning branch from 94c7f6e to 097c274 Compare September 12, 2026 03:14
@andriy-ca

Copy link
Copy Markdown
Author

Thanks — all four findings reproduced, and three turned out to share a root cause.

Reply below was drafted by an AI agent and edited by me:

Findings 1–3: the diagnostic is withdrawn rather than fixed.

Working out how to fix finding 2 showed that the code it lives in no longer has a justification:

  1. After the ck/config.h generation in this PR, all three headers it checks now ship in the wheel — ck/ck.hpp and ck_tile/core.hpp already did, and config.h now does.
  2. It can only run after use_ck_template() has confirmed ck4inductor imports, and that path already warns on a missing package. So it warned that a header might be missing from a package just proven installed.
  3. The remaining justification would be a TORCHINDUCTOR_CK_DIR override pointing at a CK checkout. But [ROCm][Inductor][CK backend] Install rocm-composable-kernel python package on ROCm Linux CI docker images #162288 retired that workflow — "the path is inferred by trying to import ck4inductor" — and use_ck_template() unconditionally overwrites config.rocm.ck_dir with the imported package's path, so the override never reaches the compiler.

torch/_inductor/utils.py is now byte-identical to main and no longer appears in the diff. That is also finding 3's answer: rather than adding a test asserting the gates are unchanged, the three gate functions are provably untouched.

Finding 4: fixed, and the problem was larger than reported.

All three drift claims confirmed against /opt/rocm/include/ck/config.h taken from real ROCm images. While fixing them I found the generator raised FATAL_ERROR for every target list except the exact one we pass — the arch blocks only assigned in the true branch, so the drift check could not distinguish "OFF for this arch" from "the script forgot it".

Your FP8 correction is right: ON is an undefined identifier in #if, so neither arm is taken. There is no #define ON anywhere in CK. The mechanism is that CK pairs each FP8 macro with add_definitions(-DCK_USE_OCP_FP8), an empty definition, and that is what #if actually sees in a real build — we emit the header but not the -D flags. The comment now records this and notes the fix would belong in compile_command.py if the fp8 path is ever enabled, rather than changing a value here and diverging from the header ROCm ships.

@jithunnair-amd jithunnair-amd added ciflow/trunk Trigger trunk jobs on your pull request ciflow/rocm-mi300 Trigger "default" config CI on ROCm MI300 ciflow/rocm-mi200 Trigger "default" config CI on ROCm MI200 labels Sep 12, 2026
@jithunnair-amd jithunnair-amd added the ciflow/rocm-navi31 Trigger "default" config CI on ROCm Navi31 label Sep 12, 2026
@jeffdaily

Copy link
Copy Markdown
Collaborator

Re-reviewed the reworked version. The four earlier findings are resolved: I re-derived config.h from config.h.in at the pinned commit and diffed the script's rules against CK's CMakeLists.txt (92-136, 258-268, 446-526), and for this target list there is no value mismatch left. I also confirmed the re-enabled tests genuinely run rather than skip: gfx90a 64 passed, gfx942 64 passed, gfx950 66 passed, 8 pre-existing scaled_mm skips in each. navi31 has inductor/test_ck_backend in ROCM_BLOCKLIST, so its red is unrelated.

Two things left before this lands, both small. Findings below were drafted with an AI assistant and reviewed by me:

1. The title no longer describes the PR.
"Advance CK pin and warn when CK headers do not resolve" still advertises the withdrawn diagnostic, but the diff is four files and none is torch/_inductor/utils.py. The title becomes the squashed commit subject, so this lands mis-describing itself.

2. The hardcoded arch list does not cover the arches that consume the wheel.
rocm_utils.sh generates one header for gfx942;gfx950;gfx1250. The ROCm CI images are built for gfx90a;gfx942;gfx950;gfx1100 (.ci/docker/build.sh:211, plus gfx1033 appended at .ci/pytorch/build.sh:16), and the manywheel list is 14 arches (.ci/docker/manywheel/build.sh:80). So gfx1250 is the one arch named that is in no CI test image, while gfx90a, the arch that actually ran the tests above, is not named.

It is correct today only by substring overlap: gfx90a gets CK_USE_XDL because gfx942 matches gfx9 and CK_USE_FNUZ_FP8 because gfx942 matches gfx94; gfx1100 gets CK_USE_WMMA/CK_USE_WMMA_FP8 only because gfx1250 matches the gfx12 regex. Drop gfx1250 in a later edit and gfx1100 silently loses WMMA.

PYTORCH_ROCM_ARCH is exported and already ;-separated at both call sites, so -D "CK_GPU_TARGETS=${PYTORCH_ROCM_ARCH}" is a drop-in. If you would rather keep a fixed list so the header does not vary with the build host, make it the union of what the wheel ships for and say in the comment why each arch is in it. Either way the list is currently written out three times (comment, echo, -D); a local would keep the log honest.

Two description fixes while you are in there: "the install_rocm.sh patch added in #189646" is the wrong file, #189646 patched rocm_utils.sh, the same file this PR edits; and the ROCm CD path has not called build_rocm_ck_wheel since #182696 (.ci/manywheel/build.sh routes GPU_ARCH_TYPE=rocm to the Python pipeline, which has no CK step), so this fix reaches CI but not the wheel a user installs. That is pre-existing and not yours to fix here, but the motivation section currently reads as a user-facing fix.

Findings in the quoted block above were drafted with an AI assistant.

@andriy-ca andriy-ca changed the title [ROCm][Inductor] Advance CK pin and warn when CK headers do not resolve [ROCm][Inductor] Advance CK pin, Generate ck/config.h for the CK wheel and re-enable its tests Sep 18, 2026
Effect on the generated header: CK_USE_WMMA and CK_USE_WMMA_FP8 become undefined; XDL, GFX94, OCP_FP8, FNUZ_FP8 and NATIVE_MX are unchanged. gfx1250 support is deferred to a follow-up that extends ck_supported_arch and this list together.
@andriy-ca andriy-ca changed the title [ROCm][Inductor] Advance CK pin, Generate ck/config.h for the CK wheel and re-enable its tests [ROCm][Inductor] Advance CK pin, Generate ck/config.h for the CK wheel and re-enable CI tests Sep 19, 2026
@andriy-ca

Copy link
Copy Markdown
Author

Thanks — both fixed. Head is now 090a323

Title

Updated to [ROCm][Inductor] Advance CK pin, Generate ck/config.h for the CK wheel and re-enable CI tests

Arch list

Restricted generation of the ck/config.h header to gfx90a;gfx942;gfx950. Which is the intersection between the ROCm CI images architectures and CK's Inductor supported architectures:

# torch/_inductor/config.py
ck_supported_arch: list[Literal["gfx90a", "gfx942", "gfx950"]] = [...]

use_ck_template() returns False for anything outside that list before a kernel is emitted. gfx1030, gfx1100, gfx1201 and the rest of the manywheel list can never reach CK codegen, so naming them would only union in macros like CK_USE_WMMA and CK_ENABLE_DL_KERNELS for hardware the backend refuses to serve.

${PYTORCH_ROCM_ARCH} has that problem plus one more — it inherits the gfx906 fallback at .ci/pytorch/build.sh:148-151 when the variable is unset, which would silently produce an XDL-only header.

Introduction of gfx1250 definitions is deferred to the follow-up, which extends ck_supported_arch and this list together.

Description

Both fixed:

@ezyang ezyang added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Sep 21, 2026
@jeffdaily

Copy link
Copy Markdown
Collaborator

The docker image build failures are present on other PRs, so not this PR's fault.

@pytorchbot merge -i

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

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

Labels

ciflow/docker ciflow/inductor ciflow/rocm-mi200 Trigger "default" config CI on ROCm MI200 ciflow/rocm-mi300 Trigger "default" config CI on ROCm MI300 ciflow/rocm-navi31 Trigger "default" config CI on ROCm Navi31 ciflow/torchtitan Run TorchTitan integration tests ciflow/trunk Trigger trunk jobs on your pull request Merged module: inductor module: rocm AMD GPU support for Pytorch open source release notes: releng release notes category 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