Repository navigation
[ROCm] Add opt-in CK SDPA build for gfx11 (RDNA3, RDNA3.5) - #203095
mgehre-amd wants to merge 2 commits into
Conversation
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.
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 FailuresAs of commit a6d49a7 with merge base f6585f7 ( NEW FAILURES - The following jobs have failed:
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. |
|
|
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.
|
I pushed a maintainer commit, a6d49a7, that extends My agent came up with this analysis, but I've read and approved it.
|
This comment was marked as resolved.
This comment was marked as resolved.
|
@pytorchbot merge -i |
Merge startedYour change will be merged while ignoring the following 5 checks: Lint / Test collect_env (older_python_version, linux.24_04.4x), Lint / Test collect_env (with_torch, linux.24_04.4x), trunk / macos-py3-arm64 / test (default, 3, 3, macos-m1-stable), trunk / linux-noble-rocm-py3.11-mi350 / test (default, 1, 8, amd-dpx-linux.rocm.gpu.gfx950.1), trunk / win-vs2022-cpu-py3 / test (default, 11, 12, windows.4xlarge.nonephemeral) Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
## 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
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