Skip to content

[ROCm] Fix CK SDPA flash attention on gfx1200/gfx1201 (RDNA4) - #188114

Closed
poad42 wants to merge 8 commits into
pytorch:mainfrom
poad42:fix/ck-sdpa-gfx12
Closed

poad42 wants to merge 8 commits into
pytorch:mainfrom
poad42:fix/ck-sdpa-gfx12

Conversation

@poad42

@poad42 poad42 commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

The CK Tile FMHA generator already compiles working kernels for gfx12 (--targets=gfx1201 passes through to the kernel template), but two guards prevented them from being used on RDNA4 hardware:

  1. launch_kernel_pt.hpp: kentry_pt kernel entry stubs added in PR [ROCm] CK SDPA - Move arch check to CK patch #144777 ([ROCm] CK SDPA - Move arch check to CK patch) had a hard-coded whitelist of gfx90a/gfx942/gfx950 (updated for gfx950 in PR SDPA support gfx950 #155103). gfx1200/gfx1201 were never added despite the CK Tile FMHA generator supporting them.

  2. Context.cpp: ckSDPASupported() split from ckSupported() in PR [ROCm] Split CK SDPA vs CK GEMM arch gating #187267 ([ROCm] Split CK SDPA vs CK GEMM arch gating) only listed gfx942/gfx950. Added gfx1200/gfx1201.

Tested on gfx1201 (RX 9070): WITHOUT patch the kernel ASSERTs, WITH patch the kernel executes correctly.

Fixes #188113

cc @jeffdaily @sunway513 @jithunnair-amd @pruthvistony @ROCmSupport @jataylo @hongxiayang @naromero77amd @pragupta @jerrymannil @xinyazhang @jgong5 @mingfeima @XiaobingSuper @sanchitintel @ashokei @jingxu10 @aditew01 @mcarilli @ptrblck @leslie-fang-intel

@pytorch-bot

pytorch-bot Bot commented Jun 24, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 2 New Failures, 7 Unrelated Failures

As of commit 468911e with merge base c20fc58 (image):

NEW FAILURES - The following jobs have failed:

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

UNSTABLE - The following job is 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.

@linux-foundation-easycla

linux-foundation-easycla Bot commented Jun 24, 2026 •

Copy link
Copy Markdown

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

  • ✅ login: poad42 / name: Adhitya Mohan (8938241)

@poad42

poad42 commented Jun 24, 2026

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 Jun 24, 2026
@poad42

poad42 commented Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

@pytorchbot label "module: rocm"

@alugorey

Copy link
Copy Markdown
Contributor

@alugorey just checking, should I should change anything from my side?

@poad42 No, thanks for checking. we are probably Okay.

@jeffdaily Can we land this? enables opt-in support for CK SDPA on gfx1200/1201. Does not bump CK so won't cause the usual headache.

ATen/ROCmCKSDPAConfig.h is produced by a CMake configure_file, but Context.cpp is also compiled by builds that do not run CMake: buckbuild.bzl lists it in lean_runtime_with_tensor, and build_variables.bzl carries it in the shared aten source list. Those builds can define USE_ROCM while having no generated header, so an unguarded include fails at preprocessing. ATen/Config.h, included unguarded a few lines above, only works there because it was explicitly wired into Buck via the generate_aten_config genrule; nothing equivalent exists for this new header.

Probe for the header with __has_include, matching the form already used in aten/src/ATen/native/transformers/cuda/sdp_utils.cpp and native/cudnn/MHA.cpp, and fall back to an empty arch list when it is absent. Empty is the correct value for those builds because they never compile CK SDPA, and ckSDPASupported() already short-circuits on an empty list, so the runtime check simply reports unsupported.

Test Plan:

Verified the preprocessor logic in all four build configurations, checking both the resulting macro value and that each configuration compiles:

```
g++ -E -P -DUSE_ROCM -I.            probe.cpp   # -> "gfx942,gfx950"
g++ -E -P -DUSE_ROCM -I/nonexistent probe.cpp   # -> ""
g++ -E -P            -I.            probe.cpp   # -> ""
g++ -E -P            -I/nonexistent probe.cpp   # -> ""
g++ -std=c++17 -fsyntax-only <each of the above> probe.cpp
```

Lint:

```
lintrunner --paths-cmd 'git diff --name-only HEAD' -a
```

Authored with assistance from Claude.
@jeffdaily

Copy link
Copy Markdown
Collaborator

Yes, once CI comes back. I pushed two commits to the branch first.

The one blocker was that ATen/ROCmCKSDPAConfig.h is produced by a CMake configure_file, but Context.cpp is also compiled by builds that never run CMake: buckbuild.bzl lists it in lean_runtime_with_tensor, and build_variables.bzl carries it in the shared aten source list. Those builds can define USE_ROCM without generating the header, so the unguarded include would have failed at preprocessing and bounced at import. ATen/Config.h, included unguarded a few lines above, only works there because it was explicitly wired into Buck through the generate_aten_config genrule; nothing equivalent exists for this new header. OSS CI compiles Context.cpp only through CMake, which is why everything was green.

The fix probes with __has_include, matching the form already used in native/transformers/cuda/sdp_utils.cpp and native/cudnn/MHA.cpp, and falls back to an empty arch list when the header is absent. Empty is the correct value there because those builds never compile CK SDPA, and ckSDPASupported() already short-circuits on an empty list. I checked the preprocessed output and syntax in all four combinations of USE_ROCM present or absent against the header present or absent.

I also merged viable/strict, which pulls in #194794, so this now runs against ROCm 10.0 rather than the image the branch was pinned to. That is 449 commits plus a ROCm major bump, so any new red is worth attributing to the environment before poad42's change.

@poad42 nothing of yours was modified; both commits sit on top of your head.

The rest holds up under review: consolidating the codegen --targets, HIP_ARCHITECTURES and the runtime allowlist into one CMake-resolved list is a real improvement over three lists that could drift, the PARENT_SCOPE ordering is correct, the blob-list filter cannot drop a tracked source, and the aiter FAv3 asm backward path self-disqualifies on gfx12 at runtime so it falls back to the CK tile kernels this PR generates.

Reply drafted with AI assistance.

jeffdaily
jeffdaily previously approved these changes Aug 27, 2026
@jeffdaily jeffdaily changed the title Fix CK SDPA flash attention on gfx1200/gfx1201 (RDNA4) [ROCm] Fix CK SDPA flash attention on gfx1200/gfx1201 (RDNA4) Aug 27, 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

@meta-codesync

meta-codesync Bot commented Aug 29, 2026

Copy link
Copy Markdown

@pytorchbot revert -m="Diff reverted internally" -c="ghfirst"

This Pull Request has been reverted by a revert inside Meta. To re-land this change, please open another pull request, assign the same reviewers, fix the CI failures that caused the revert and make sure that the failing CI runs on the PR by applying the proper ciflow label (e.g., ciflow/trunk).)

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot successfully started a revert job. Check the current status here.
Questions? Feedback? Please reach out to the PyTorch DevX Team

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@poad42 your PR has been successfully reverted.

@pytorchmergebot pytorchmergebot added Reverted ci-no-td Do not run TD on this PR labels Aug 29, 2026
@poad42

poad42 commented Aug 31, 2026

Copy link
Copy Markdown
Contributor Author

@jeffdaily @alugorey did I miss something so it got reverted? I didn't see any CI failures

@jeffdaily

Copy link
Copy Markdown
Collaborator

@poad42 I've requested insight from @jeanschmidt

The header guard added in 5ac98b1 fell back to an empty AT_ROCM_CK_SDPA_ARCHS when ATen/ROCmCKSDPAConfig.h is absent, on the assumption that non-CMake builds never compile CK SDPA. That assumption is wrong for Meta's internal Buck build: it compiles CK SDPA as its only ROCm flash attention backend and replaces AOTriton with a stub that throws at runtime. With the empty fallback, ckSDPASupported() returned false on MI300, getROCmFAPreferredBackend() silently rewrote the CK preference to AOTriton, and mha_fwd dispatched into the stub ("AOTriton is not supported in the internal stack"), which is why the first land of this PR was reverted.

The fix keeps the header authoritative when it exists (all CMake builds, including the new gfx12 opt-in) and changes only the absent-header fallback to "gfx942,gfx950", the exact list ckSDPASupported() hard-coded before this PR. Non-CMake builds therefore get their previous runtime behavior back. The alternative of wiring the generated header into Buck was rejected because it requires an internal-only change we cannot make or test from here; the static fallback matches the status quo those builds have always relied on.

Test Plan:

Compiled the real aten/src/ATen/Context.cpp with the exact torch_cpu compile flags recorded in build/compile_commands.json (which include -DUSE_ROCM) in three include configurations, checking both that -fsyntax-only passes and what string literal reaches the supported_archs initializer:

```
no ROCmCKSDPAConfig.h on the include path (Buck-like)  -> "gfx942,gfx950"  compile OK
-I<dir> with header defining ""    (CMake, CK off)     -> ""               compile OK
-I<dir> with header defining "gfx942"  (CMake, CK on)  -> "gfx942"         compile OK
```

Extracted the supported_archs parsing lambda verbatim from Context.cpp into a standalone program and executed it against representative macro values:

```
g++ -std=c++17 -DAT_ROCM_CK_SDPA_ARCHS='"gfx942,gfx950"' parse_test.cpp -o parse_test && ./parse_test
```

yields [gfx942] [gfx950]; "" yields an empty list, "gfx942,gfx1200,gfx1201" yields all three entries.

Lint:

```
lintrunner --paths-cmd 'git diff --name-only HEAD' -a
```

The only report is a pre-existing misc-use-internal-linkage finding on get_reduction_option, present on main and untouched by this change.

Authored with assistance from Claude.
@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: 2 mandatory check(s) failed. The first few are:

Dig deeper by viewing the failures on hud

Details for Dev Infra team Raised by workflow job

Failing merge rule: Core Maintainers

@jeffdaily

Copy link
Copy Markdown
Collaborator

@pytorchbot merge -i

Infra issue blocking merge. Meta revert reason should be resolved now.

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

Labels

ci-no-td Do not run TD on this PR ci-refresh-hf-cache ciflow/b200 ciflow/docker ciflow/h100 ciflow/inductor ciflow/inductor-pallas ciflow/inductor-rocm-mi300 Trigger "inductor" config CI on ROCm MI300/MI325 ciflow/mps Run MPS tests (subset of trunk) ciflow/periodic-rocm-mi300 Trigger "distributed" config CI on ROCm MI300/MI325 ciflow/rocm ciflow/rocm-mi300 Trigger "default" config CI on ROCm MI300 ciflow/torchtitan Run TorchTitan integration tests ciflow/trunk Trigger trunk jobs on your pull request ciflow/vllm Merged module: amp (automated mixed precision) autocast module: cpu CPU specific problem (e.g., perf, algorithm) module: rocm AMD GPU support for Pytorch open source release notes: quantization release notes category release notes: rocm mandatorylabel Reverted 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.

CK SDPA flash attention kernel asserts on gfx1200/gfx1201 (RDNA4)

10 participants