Skip to content

[ROCm] Add opt-in CK SDPA build for gfx11 (RDNA3, RDNA3.5) - #203095

Closed
mgehre-amd wants to merge 2 commits into
pytorch:mainfrom
ROCm:matthias.ck-sdpa-gfx1151-upstream
Closed

mgehre-amd wants to merge 2 commits into
pytorch:mainfrom
ROCm:matthias.ck-sdpa-gfx1151-upstream

Conversation

@mgehre-amd

@mgehre-amd mgehre-amd commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Linked issue or supporting maintainer

Fixes #203094

BC-breaking?

No

Summary (human written only)

Add gfx1100, gfx1101 and gfx1102 (RDNA3) and gfx1150 and gfx1151 (RDNA3.5) to the CK SDPA architectures behind a new USE_ROCM_CK_SDPA_GFX11 option.
CK SDPA has shown improved performance over aotriton in some cases, and we want to allow enabling it in those cases via torch.backends.cuda.preferred_rocm_fa_library('ck').

This mimics how gfx12 CK SDPA was integrated.

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

Add gfx1150 and gfx1151 (RDNA3.5) to the CK SDPA architectures behind a
new USE_ROCM_CK_SDPA_GFX11 option, the gfx11 counterpart of
USE_ROCM_CK_SDPA_GFX12.

Changes:
- USE_ROCM_CK_SDPA_GFX11 is OFF by default for the same reason as the
  gfx12 option: both arches are already in ROCm wheel arch lists, and
  turning it on adds CK codegen and compile time to those builds.
- The SDPA runtime default is unchanged: AOTriton stays the preferred
  backend; CK is used only via preferred_rocm_fa_library("ck") or
  TORCH_ROCM_FA_PREFER_CK=1.
- Both arches map to the CK Tile FMHA "gfx115" codegen target; ck_tile
  defines __gfx115__ for gfx1150..gfx1153. The pinned composable_kernel
  already emits fwd, fwd_splitkv, fwd_appendkv and bwd instances for it
  with PyTorch's receipt-4 filters.
- kentry_pt must list the arches, otherwise the instances compile to the
  CUDA_KERNEL_ASSERT stub.
- Context::ckSDPASupported() reads the generated AT_ROCM_CK_SDPA_ARCHS,
  so no runtime change is needed.
@pytorch-bot pytorch-bot Bot added the module: rocm AMD GPU support for Pytorch label Nov 2, 2026
@pytorch-bot

pytorch-bot Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

PR Status: Approved 🚀

Please fix all CI failures and trigger merge by commenting "@pytorchbot merge".

🔗 Helpful Links

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

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

❌ 2 New Failures, 1 Cancelled Job, 2 Unrelated Failures

As of commit a6d49a7 with merge base f6585f7 (image):

NEW FAILURES - The following jobs have failed:

  • trunk / linux-noble-rocm-py3.11-mi350 / test (default, 1, 8, amd-dpx-linux.rocm.gpu.gfx950.1) (gh)
    test/profiler/test_profiler.py::TestMetadataJsonFormatCUDA::test_kernel_metadata_field_types

    AI verdict: AI verdict: probably not related

    The suspect commit only adds gfx1100/1101/1102 to an opt-in CK SDPA build path that is OFF by default and irrelevant to gfx950 (MI350). The failure is a KeyError: 'grid' in ROCm profiler kernel metadata, from a test that was added after the PR's merge base. Trunk has newer ROCm grid/block handling, and that test passes on trunk mi350 runs, so the failure comes from the PR branch's stale profiler code and test state.

    Full reasoning on HUD →

  • trunk / win-vs2022-cpu-py3 / test (default, 11, 12, windows.4xlarge.nonephemeral) (gh)
    AssertionError: Torch not compiled with CUDA enabled

    AI verdict: AI verdict: probably not related

    The job failed because the test_nestedtensor process exited with code 2 ('Unsupported signal: 2') even though all 1387 of its tests passed. The 'Torch not compiled with CUDA' capture is noise from a passing test. The suspect only changes ROCm CK SDPA CMake options, comments and a HIP preprocessor guard, none of which take effect in a Windows CPU build.

    Full reasoning on HUD →

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

CANCELLED JOB - The following job was cancelled. Please retry:

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

@linux-foundation-easycla

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

Copy link
Copy Markdown

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

  • ✅ login: mgehre-amd / name: Matthias Gehre (4a53b78)

@github-actions github-actions Bot added bot-triaged This is a label only to be used by the auto triage bot missing actionable issue A PR without a linked actionable issue or maintainer sponsor triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module labels Nov 2, 2026
@pytorch-bot pytorch-bot Bot added open source and removed triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module bot-triaged This is a label only to be used by the auto triage bot open source missing actionable issue A PR without a linked actionable issue or maintainer sponsor labels Nov 5, 2026
@github-actions
github-actions Bot requested a review from jeffdaily November 5, 2026 16:28
@github-actions github-actions Bot added bot-triaged This is a label only to be used by the auto triage bot triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module labels Nov 5, 2026
CK's FMHA codegen has separate gfx11 (RDNA3) and gfx115 (RDNA3.5) forward
targets, so map gfx110x to the gfx11 family and add the gfx110x macros to the
kernel entry guard.

Authored with Claude.
@jeffdaily jeffdaily changed the title [ROCm] Add opt-in CK SDPA build for gfx1150/gfx1151 [ROCm] Add opt-in CK SDPA build for gfx11 (RDNA3, RDNA3.5) Nov 9, 2026
@jeffdaily

Copy link
Copy Markdown
Collaborator

I pushed a maintainer commit, a6d49a7, that extends USE_ROCM_CK_SDPA_GFX11 to RDNA3 (gfx1100/gfx1101/gfx1102), and updated the title and summary to match. The option is named for gfx11, and CK's FMHA codegen already treats gfx110x and gfx115x as one family, so there was no reason to leave RDNA3 out.

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

  • CK's fwd codegen has separate gfx11 (gfx110x) and gfx115 targets; bwd, splitkv and appendkv emit only gfx11 instances, which already serve gfx1150/gfx1151. So the gfx115 path in this PR already depends on CK's gfx11 code.
  • The commit maps ^gfx11 (after ^gfx115) to the gfx11 codegen target and adds __gfx1100__/__gfx1101__/__gfx1102__ to the kentry_pt guard.
  • gfx1100 (W7800, Linux): built with PYTORCH_ROCM_ARCH=gfx1100. The profiler confirms that CK fwd and bwd run as ck_tile gfx11_t kernels. test_transformers CK tests: 1360 passed, 0 failed. The skips are only head_dim > 128 and causal with Sq != Sk. CK forward takes about 0.55x AOTriton's time (27 of 28 shapes faster). Forward+backward is 1.76x slower at head_dim 64 and 1.16x at head_dim 128. gfx1101/gfx1102 are untested but use the same gfx11 CK trait.
  • gfx1151 (8060S, Windows): test_transformers CK tests 688 passed, 0 failed. Same speed pattern: forward about 0.59x AOTriton's time, forward+backward 1.62x slower at head_dim 64 and 1.08x at head_dim 128.
  • So on both arches, CK is a win for inference and a loss for training at head_dim 64. bf16 CK error vs fp32 math is 2-4x AOTriton's but within test tolerance. Note that common_cuda.py lists gfx1150/gfx1151 as experimental for flash attention, so these tests skip unless TORCH_ROCM_AOTRITON_ENABLE_EXPERIMENTAL=1 is set.

@pytorch-bot

This comment was marked as resolved.

@jeffdaily jeffdaily added ciflow/rocm-rx7900 Trigger "default" config CI on ROCm RX7900 Radeon (Navi31/gfx1100) GPUs ciflow/trunk Trigger trunk jobs on your pull request and removed ciflow/rocm labels Nov 9, 2026
@jeffdaily

Copy link
Copy Markdown
Collaborator

@pytorchbot merge -i

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

mgehre-amd added a commit to ROCm/TheRock that referenced this pull request Nov 18, 2026
## Motivation

PyTorch added the `USE_ROCM_CK_SDPA_GFX11` CMake option
(pytorch/pytorch#203095, OFF by default). It builds the Composable
Kernel SDPA backend for gfx1100/gfx1101/gfx1102/gfx1150/gfx1151. TheRock
does not set the option today, so TheRock wheels for these targets have
no CK SDPA kernels and
`torch.backends.cuda.preferred_rocm_fa_library('ck')` cannot be used on
them.

## Technical Details

`build_prod_wheels.py` sets `USE_ROCM_CK_SDPA_GFX11=ON` only when all of
the following hold:

- `PYTORCH_ROCM_ARCH` contains a gfx11 target. Builds for other targets
keep their configuration. (PyTorch also intersects the option's arch
list with `PYTORCH_ROCM_ARCH`, so in a multi-arch build, CK device code
is generated only for gfx1100/1101/1102/1150/1151.)
- The PyTorch version is >= 2.16, which includes nightly (`2.16.0a0`).
Older release branches do not have the option (`release/2.15` has only
`USE_ROCM_CK_SDPA_GFX12`).
- The build is on Linux with flash attention enabled. PyTorch only
builds CK SDPA in that configuration.
- `USE_ROCM_CK_SDPA_GFX11` is not already set in the environment. An
explicit value, for example `OFF`, takes precedence.

AOTriton stays the default SDPA backend at runtime. CK is used only on
request.

## Test Plan

- New unit test
`external-builds/pytorch/tests/build_prod_wheels_ck_sdpa_test.py`.
- Ran two dev builds of `multi_arch_release_linux_pytorch_wheels.yml` at
the same time with identical inputs: the full production family set,
py3.12, torch `nightly`, ROCm `10.3.0a20261110`, and sccache.
- Baseline (`main`):
https://github.com/ROCm/TheRock/actions/runs/43003975744
- This PR: https://github.com/ROCm/TheRock/actions/runs/43003980163.
This run built an earlier revision that detected the option in
`CMakeLists.txt` instead of checking the version. For the `nightly` ref,
that revision sets the same flag.

## Test Result

Both runs built the same torch (`2.16.0a0+git09b29f3a`). The CMake
summary shows `USE_ROCM_CK_SDPA_GFX11: ON` for this PR and `OFF` for the
baseline.

**Build time** ("Build PyTorch wheels" step, one fat build for all
families):

| | Baseline | This PR | Delta |
|---|---|---|---|
| Step duration | 3:40:06 | 3:47:39 | +7:33 (+3.4%) |
| sccache compile requests | 2205 | 3125 | +920 |
| sccache HIP misses | 1455 | 2080 | +625 |

The HIP cache was cold in both runs (new ROCm version), so the figures
reflect full compiles. This is one sample per side.

**Wheel size** (`ls -lh` after the kpack split, 1 MB resolution):

| Wheel | Baseline | This PR |
|---|---|---|
| `amd_torch_device_gfx1100` | 43M | 50M |
| `amd_torch_device_gfx1101` | 42M | 50M |
| `amd_torch_device_gfx1102` | 43M | 50M |
| `amd_torch_device_gfx1150` | 42M | 49M |
| `amd_torch_device_gfx1151` | 42M | 49M |
| `torch` (host) | 222M | 225M |

All other wheels have the same size in both runs: `amd_torch_device_*`
for gfx1103, gfx1152, gfx1153, gfx110x, gfx115x, gfx12*, gfx10*, gfx9*,
gfx942, gfx950 and gfx1250, plus all torchvision, torchaudio, triton and
apex wheels.

## Submission Checklist

- [x] Look over the contributing guidelines at
https://github.com/ROCm/TheRock/blob/main/CONTRIBUTING.md.

JIRA ID: AIESW-50855
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot-triaged This is a label only to be used by the auto triage bot ciflow/rocm-rx7900 Trigger "default" config CI on ROCm RX7900 Radeon (Navi31/gfx1100) GPUs ciflow/trunk Trigger trunk jobs on your pull request Merged module: rocm AMD GPU support for Pytorch open source release notes: rocm mandatorylabel 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.

[ROCM] Support CK SDPA flash attention on gfx1150 & gfx1151

4 participants