Skip to content

[ROCm] Consolidate CK GEMM allow-list - #201113

Closed
alugorey wants to merge 3 commits into
pytorch:mainfrom
ROCm:alugorey/ck_gemm_whitelist
Closed

alugorey wants to merge 3 commits into
pytorch:mainfrom
ROCm:alugorey/ck_gemm_whitelist

Conversation

@alugorey

@alugorey alugorey commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The CK GEMM supported-architecture allowlist currently lives hardcoded in three
places: torch_filter_ck_gemm_arches (cmake/public/utils.cmake), the runtime
check at::Context::ckGemmSupported(), and the gemm_internal_ck dispatch in
ck_gemm_{half,bfloat16}.hip. Keeping them in sync is manual, and the
gfx11/gfx12 WMMA path (#143971) can only be re-enabled by editing source in
several spots.

This PR makes the list a single source of truth:

  • A new CMake cache variable TORCH_CK_GEMM_ARCH_LIST (default
    gfx90a;gfx942;gfx950) drives the ck_gemm build arch filter and is surfaced
    to C++ through a generated ATen/ROCmCKGEMMConfig.h header, mirroring the
    existing AT_ROCM_CK_SDPA_ARCHS mechanism. It is forwarded from the
    environment via cmake/EnvVarForwarding.cmake.
  • Context.cpp parses the list once through a shared parseArchList helper
    used by both ckSDPASupported() and ckGemmSupported().
  • The .hip dispatch calls at::globalContext().ckGemmSupported() instead of
    re-parsing the list, so the header include, the parser, and the fallback are
    removed from both .hip files.

A WMMA arch can now be opted back in at both build and run time without patching
source, e.g. TORCH_CK_GEMM_ARCH_LIST="gfx90a;gfx942;gfx950;gfx1200".

BC-breaking

No. Default behavior is unchanged -- the default list is the same three archs
that were previously hardcoded.

Supporting maintainer

@jeffdaily (requested this refactor in review).

Test plan

CMake wiring, standalone project including cmake/public/utils.cmake:

  • default: torch_filter_ck_gemm_arches filters
    gfx942;gfx1250-strict;gfx950;gfx1200 to gfx942;gfx950; generated header
    #define TORCH_CK_GEMM_ARCH_LIST "gfx90a,gfx942,gfx950".
  • override TORCH_CK_GEMM_ARCH_LIST="gfx90a;gfx942;gfx950;gfx1200": filter keeps
    gfx942;gfx950;gfx1200; header "gfx90a,gfx942,gfx950,gfx1200".

Full build:

PYTORCH_ROCM_ARCH="gfx90a gfx942 gfx950" pip install -e . --no-build-isolation -v

rc=0, 0 failed. ck_gemm_half.hip.o offload bundle = gfx90a,gfx942,gfx950;
libtorch_hip.so links (the ck_gemm -> Context::ckGemmSupported() cross-TU
call resolves).

cc @jeffdaily @sunway513 @jithunnair-amd @pruthvistony @ROCmSupport @jataylo @hongxiayang @naromero77amd @pragupta @jerrymannil @xinyazhang

@pytorch-bot

pytorch-bot Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ No Failures

As of commit 7c4b1e4 with merge base 6e33a88 (image):
💚 Looks good so far! There are no failures yet. 💚

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

@jeffdaily jeffdaily added ciflow/binaries_wheel Trigger binary build and upload jobs for wheel on the PR ciflow/trunk Trigger trunk jobs on your pull request labels Oct 17, 2026
@jeffdaily

Copy link
Copy Markdown
Collaborator

My agent came up with this analysis, but I've read and approved it.

Moving to an allowlist looks right, but this hardcodes the same arch list in three places (torch_filter_ck_gemm_arches, Context::ckGemmSupported(), and the ck_gemm_{half,bfloat16}.hip dispatch) and makes the gfx11/gfx12 WMMA path from #143971 unreachable both at build and run time; re-enabling it means editing source in two places. Could the allowlist be a single CMake cache variable (e.g. TORCH_CK_GEMM_ARCH_LIST, default gfx90a;gfx942;gfx950) that torch_filter_ck_gemm_arches uses and that is passed as a compile definition to Context.cpp and the .hip files? That removes the keep-in-sync comments and lets someone opt a WMMA arch back in with -DTORCH_CK_GEMM_ARCH_LIST=... without patching.

Please also fill in the PR template (supporting maintainer or linked issue, BC-breaking, and a short human-written summary) before marking this ready for review.

@pytorch-bot

pytorch-bot Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

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

Addresses review feedback: the CK GEMM architecture allowlist was hardcoded
in three places (torch_filter_ck_gemm_arches, Context::ckGemmSupported, and
the ck_gemm_{half,bfloat16}.hip dispatch), and the gfx11/gfx12 WMMA path
could only be re-enabled by editing source in multiple spots.

Introduce a single CMake cache variable TORCH_CK_GEMM_ARCH_LIST (default
gfx90a;gfx942;gfx950). torch_filter_ck_gemm_arches reads it to select the
ck_gemm build architectures, and it is surfaced to C++ through a generated
ATen/ROCmCKGEMMConfig.h header (mirroring the existing AT_ROCM_CK_SDPA_ARCHS
mechanism) that Context.cpp and the .hip dispatch parse. The per-site
hardcoded lists and keep-in-sync comments are removed.

Default behavior is unchanged. A WMMA arch can now be opted back in at both
build and run time without patching source, e.g.
-DTORCH_CK_GEMM_ARCH_LIST="gfx90a;gfx942;gfx950;gfx1200".

Test Plan:
Verified the CMake wiring with a standalone project that includes
cmake/public/utils.cmake and configure_file()s the new header:

```
# default allowlist
PYTORCH_ROCM_ARCH="gfx942;gfx1250-strict;gfx950;gfx1200"
torch_filter_ck_gemm_arches -> gfx942;gfx950
ROCmCKGEMMConfig.h -> #define TORCH_CK_GEMM_ARCH_LIST "gfx90a,gfx942,gfx950"

# override pulls the gfx1200 WMMA arch into build and runtime
cmake -DTORCH_CK_GEMM_ARCH_LIST="gfx90a;gfx942;gfx950;gfx1200"
torch_filter_ck_gemm_arches -> gfx942;gfx950;gfx1200
ROCmCKGEMMConfig.h -> #define TORCH_CK_GEMM_ARCH_LIST "gfx90a,gfx942,gfx950,gfx1200"
```

Full compile+link verification on gfx90a, gfx942, gfx950 (single and
combined) is being run separately.

Authored with assistance from an AI coding agent (Claude).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@alugorey
alugorey force-pushed the alugorey/ck_gemm_whitelist branch from 0a856a6 to 4e1be93 Compare October 22, 2026 00:23
@alugorey alugorey changed the title Implement whitelist for CK GEMMs instead of blacklist [ROCm] Consolidate CK GEMM allow-list Oct 22, 2026
@pytorch-bot pytorch-bot Bot added the module: rocm AMD GPU support for Pytorch label Oct 22, 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.

My agent came up with this analysis, but I've read and approved it.

Thanks for moving the list to TORCH_CK_GEMM_ARCH_LIST. Three things before this is ready:

  1. The comma-list parser is now copied four times (Context.cpp for CK SDPA and CK GEMM, and both ck_gemm_{half,bfloat16}.hip), and the fallback default three times. In the .hip dispatch, the else if can call at::globalContext().ckGemmSupported() instead, which removes the header include, the parser and the fallback from both files. In Context.cpp, please share one parse helper between ckSDPASupported() and ckGemmSupported().
  2. TORCH_CK_GEMM_ARCH_LIST is not forwarded from the environment, so a pip install build cannot set it without -C cmake.define=.... Please add it to the passthrough list in cmake/EnvVarForwarding.cmake next to TORCH_CUDA_ARCH_LIST, and to the reference list at the top of that file.
  3. Please add a test plan to the description showing the default build and a TORCH_CK_GEMM_ARCH_LIST override, then mark the PR ready so CI runs.

Addresses review feedback on the TORCH_CK_GEMM_ARCH_LIST change:

- Consolidate the comma-separated arch-list parser into a single
  parseArchList helper in Context.cpp, shared by ckSDPASupported() and
  ckGemmSupported(). The ck_gemm_{half,bfloat16}.hip dispatch now calls
  at::globalContext().ckGemmSupported() instead of re-parsing the list, so
  the generated-header include, the parser, and the fallback define are
  removed from both .hip files (the parser lived in four places and the
  fallback in three).
- Forward TORCH_CK_GEMM_ARCH_LIST from the environment by adding it to
  cmake/EnvVarForwarding.cmake (the reference list and _ENV_PASSTHROUGH), so
  a pip install / setup.py build can set it without -C cmake.define=...

Test Plan:
Full compile+link build with PYTORCH_ROCM_ARCH="gfx90a gfx942 gfx950":

```
pip install -e . --no-build-isolation -v   # rc=0, 4911 ninja steps, 0 failed
```

ck_gemm compiles for all three archs (ck_gemm_half.hip.o offload bundle =
gfx90a,gfx942,gfx950) and libtorch_hip.so links, confirming the new
ck_gemm -> at::Context::ckGemmSupported() cross-TU call resolves.

Authored with assistance from an AI coding agent (Claude).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@alugorey
alugorey marked this pull request as ready for review October 26, 2026 17:10
@alugorey

Copy link
Copy Markdown
Contributor Author

My agent came up with this analysis, but I've read and approved it.

Thanks for moving the list to TORCH_CK_GEMM_ARCH_LIST. Three things before this is ready:

  1. The comma-list parser is now copied four times (Context.cpp for CK SDPA and CK GEMM, and both ck_gemm_{half,bfloat16}.hip), and the fallback default three times. In the .hip dispatch, the else if can call at::globalContext().ckGemmSupported() instead, which removes the header include, the parser and the fallback from both files. In Context.cpp, please share one parse helper between ckSDPASupported() and ckGemmSupported().
  2. TORCH_CK_GEMM_ARCH_LIST is not forwarded from the environment, so a pip install build cannot set it without -C cmake.define=.... Please add it to the passthrough list in cmake/EnvVarForwarding.cmake next to TORCH_CUDA_ARCH_LIST, and to the reference list at the top of that file.
  3. Please add a test plan to the description showing the default build and a TORCH_CK_GEMM_ARCH_LIST override, then mark the PR ready so CI runs.

@jeffdaily ready for next round of review

The ck_gemm_{half,bfloat16}.hip dispatch now calls ckGemmSupported() on every CK GEMM, and it walked every visible device and re-parsed the arch list each time. Compute it once; the device set does not change within a process.

Authored with Claude.

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

My agent came up with this analysis, but I've read and approved it.

All three points from the last round are addressed at bfc3aea: one parseArchList helper in Context.cpp, the .hip dispatch calls ckGemmSupported() with no header, parser or fallback of its own, TORCH_CK_GEMM_ARCH_LIST is in the EnvVarForwarding.cmake passthrough and reference lists, and the description has a test plan.

@jeffdaily

Copy link
Copy Markdown
Collaborator

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: This PR needs a release notes: label
If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

Details for Dev Infra team

Raised by workflow job

@jeffdaily jeffdaily added the release notes: rocm mandatorylabel label Oct 26, 2026
@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

jeffdaily added a commit to ROCm/pytorch that referenced this pull request Oct 27, 2026
Resolve the conflict with pytorch#201113 in gemm_internal_ck<BFloat16> and gemm_internal_ck<Half>: keep main's ckGemmSupported() check and this branch's bool return from the gfx9 dispatch.

Authored with Claude.
pragupta pushed a commit to ROCm/pytorch that referenced this pull request Nov 9, 2026
…llow-list (#3979)

Backport of the CK GEMM single-source allow-list to release/2.13.
Replaces the gfx1250 blacklist (list(REMOVE_ITEM ... gfx1250
gfx1250-strict)) with a single CMake cache variable
TORCH_CK_GEMM_ARCH_LIST (default gfx90a;gfx942;gfx950) that drives the
ck_gemm build arch filter (torch_filter_ck_gemm_arches) and is surfaced
to C++ via a generated ATen/ROCmCKGEMMConfig.h header.

release/2.13 predates the CK SDPA/GEMM gating split (upstream pytorch#187267)
and had no ckGemmSupported() -- only a combined ckSupported(). This adds
Context::ckGemmSupported() (parsing TORCH_CK_GEMM_ARCH_LIST via a shared
parseArchList helper) and routes the CK blas-backend gate through it,
leaving the CK SDPA / flash-attention gates on ckSupported(). The
ck_gemm_{half,bfloat16}.hip dispatch calls
at::globalContext().ckGemmSupported() instead of an isGPUArch({"gfx9"})
prefix check. TORCH_CK_GEMM_ARCH_LIST is forwarded from the environment
via cmake/EnvVarForwarding.cmake.

Squashed backport of upstream pytorch/pytorch pytorch#200307 (base allow-list)
and pytorch#201113 (TORCH_CK_GEMM_ARCH_LIST consolidation).

Once these are merged need to revert
ROCm/TheRock#9414

Co-authored-by: Claude Opus 4.8 <[email protected]>
pragupta pushed a commit to ROCm/pytorch that referenced this pull request Nov 9, 2026
…llow-list (#3980)

Backport of the CK GEMM single-source allow-list to release/2.14.
Replaces the gfx1250 blacklist (list(REMOVE_ITEM ... gfx1250
gfx1250-strict)) with a single CMake cache variable
TORCH_CK_GEMM_ARCH_LIST (default gfx90a;gfx942;gfx950) that drives the
ck_gemm build arch filter (torch_filter_ck_gemm_arches) and is surfaced
to C++ via a generated ATen/ROCmCKGEMMConfig.h header.
Context::ckGemmSupported() parses that list (shared parseArchList
helper) and the ck_gemm_{half,bfloat16}.hip dispatch calls
at::globalContext().ckGemmSupported() instead of an isGPUArch({"gfx9"})
prefix check. TORCH_CK_GEMM_ARCH_LIST is forwarded from the environment
via cmake/EnvVarForwarding.cmake.

Squashed backport of upstream pytorch/pytorch pytorch#200307 (base allow-list)
and pytorch#201113 (TORCH_CK_GEMM_ARCH_LIST consolidation).

Once these are merged need to revert
ROCm/TheRock#9414

Co-authored-by: Claude Opus 4.8 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/binaries_wheel Trigger binary build and upload jobs for wheel on the PR ciflow/trunk Trigger trunk jobs on your pull request Merged module: rocm AMD GPU support for Pytorch open source release notes: rocm mandatorylabel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants