Skip to content

[release/2.14] Consolidate CK GEMM allow-list - #3945

Draft
ethanwee1 wants to merge 1 commit into
release/2.14from
ethanwee1-backport-ck-gemm-2.14
Draft

ethanwee1 wants to merge 1 commit into
release/2.14from
ethanwee1-backport-ck-gemm-2.14

Conversation

@ethanwee1

@ethanwee1 ethanwee1 commented Nov 4, 2026 •

Copy link
Copy Markdown

Related: ROCm/TheRock#9413

Backport of pytorch/pytorch@5182982d.

Problem

The release branch builds CK GEMM for every requested architecture except gfx1250. Adding gfx1170/gfx1171 therefore compiles unsupported CK kernels and breaks TheRock wheel builds.

Changes

  • Make TORCH_CK_GEMM_ARCH_LIST the build-time and runtime source of truth.
  • Filter CK GEMM compilation to the default supported architectures.
  • Disable CK GEMM when no requested architecture is supported.
  • Keep runtime dispatch aligned with the generated allow-list.

Tracked in AIPYTORCH-1538.

Validation

  • Verified the filter maps gfx942;gfx1170;gfx1250-strict;gfx950 to gfx942;gfx950.
  • CMake script validation and git diff --check passed.
  • The mixed gfx94X-dcgpu + gfx117X-all validation build compiled PyTorch successfully.
  • Wheel splitting then hit the known missing gfx117 bundle fixed by ROCm/rocm-systems#13969, so standard tests could not start.

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 (pytorch#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"`.

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

@jeffdaily (requested this refactor in review).

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

Pull Request resolved: pytorch#201113
Approved by: https://github.com/jeffdaily

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: Jeff Daily <jeff.daily@amd.com>
(cherry picked from commit 5182982)
(cherry picked from commit a117134)

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants