Repository navigation
Conversation
…ge(HIP). Fixes TheRock #5175
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/183365
Note: Links to docs will display an error until the docs builds have been completed. ⏳ No Failures, 66 PendingAs of commit 1b073e8 with merge base 380fc8b ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@pytorchbot label "topic: not user facing" |
|
@pytorchbot merge -f "rocm-only cmake change inside if(WIN32) block, no pytorch/pytorch CI here can test it" |
Merge startedYour change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
This removes the MSVC flags from `CMAKE_HIP_FLAGS{,_<CONFIG>` after `enable_language(HIP)` as discussed here ROCm/TheRock#5175 (comment)
Fixes ROCm/TheRock#5175
Pull Request resolved: pytorch#183365
Approved by: https://github.com/jeffdaily
This removes the MSVC flags from `CMAKE_HIP_FLAGS{,_<CONFIG>` after `enable_language(HIP)` as discussed here ROCm/TheRock#5175 (comment)
Fixes ROCm/TheRock#5175
Pull Request resolved: pytorch#183365
Approved by: https://github.com/jeffdaily
…_FLAGS PR pytorch#180485 migrated the Windows HIP build to native enable_language(HIP). PR pytorch#183365 stripped MSVC-style defaults (/DWIN32 /D_WINDOWS /O2 /Ob2 /DNDEBUG) out of CMAKE_HIP_FLAGS{,_<CONFIG>} so clang++ would stop warn-ignoring them, and tried to reinstate GNU equivalents by appending to CMAKE_HIP_FLAGS_RELEASE, CMAKE_HIP_FLAGS_DEBUG, etc. The reinstatement step does not work on this code path. The generated HIP compile rule expands <FLAGS> from CMAKE_HIP_FLAGS, but the per-config CMAKE_HIP_FLAGS_<CONFIG> variables do not reach <FLAGS> (verified by inspecting build.ninja: CMAKE_HIP_FLAGS contents like --offload-compress and --offload-arch appear, but the -O3 -DNDEBUG appended to CMAKE_HIP_FLAGS_RELEASE does not). That is the actual cause of the "silent -O0 fallback" reported in TheRock#5157 / pytorch#183853: with the MSVC /O2 stripped and the GNU -O3 unreachable, HIP code was effectively compiled at -O0. The previous version of this PR hardcoded -O3 in the CMAKE_HIP_COMPILE_OBJECT rule template. That restores Release perf but the -O3 sits outside the per-config plumbing, so it also leaks into Debug, RelWithDebInfo, and MinSizeRel builds. Inject the per-config optimization flags into CMAKE_HIP_FLAGS instead, gated on CMAKE_BUILD_TYPE. CMAKE_HIP_FLAGS does reach <FLAGS> in the generated rule, so this lands -O3/-O2/-O0/-Os (matching the build type) on the compile line for single-config generators (Ninja, Makefiles) without contaminating other configs. Drop the now-dead string(APPEND CMAKE_HIP_FLAGS_<CONFIG>) lines and the -O3 hack in the compile rule. Validation on gfx1151 / Radeon AI MAX 395 with CMake 4.3.2: Release shows -O3 -DNDEBUG in build.ninja FLAGS and Sleep.hip compiles cleanly with optimized ISA; Debug shows -O0 -g. Co-investigated with @astrelsky and @adityas-amd on TheRock#5157. Authored with assistance from Claude.
…_FLAGS (#183856) ## Issue Fixes ROCm/TheRock#5157. Fixes #183853. Windows ROCm HIP code was effectively compiled at `-O0` after #180485 + #183365 landed, causing a ~99% conv2d FP16 perf regression on gfx1150 (bisected and validated by @astrelsky and @adityas-amd at ROCm/TheRock#5157). ## Diagnosis After #183365 stripped the MSVC-style `/O2 /Ob2 /DNDEBUG` out of `CMAKE_HIP_FLAGS_RELEASE` and re-appended GNU `-O3 -DNDEBUG`, the actual build command still came up unoptimized. Inspecting the generated `build.ninja` shows why: - `CMAKE_HIP_FLAGS` contents (e.g. `--offload-compress -std=c++20 --offload-arch=...`) **do** reach the `$FLAGS` ninja variable used by every HIP compile. - `CMAKE_HIP_FLAGS_<CONFIG>` contents (e.g. `-O3 -DNDEBUG`) **do not**. That's the actual cause of the `-O0` fallback — `CMAKE_HIP_FLAGS_RELEASE` is dead code on the Windows HIP compile path. ## Fix - Drop the dead `string(APPEND CMAKE_HIP_FLAGS_<CONFIG> ...)` lines. - Inject the appropriate `-O{3,2,0,s}` plus `-DNDEBUG`/`-g` directly into `CMAKE_HIP_FLAGS`, gated on `CMAKE_BUILD_TYPE`. This works for single-config generators (Ninja, Makefiles), which is what the Windows ROCm build uses. - Drop the `-O3` from the compile rule template so non-Release configs aren't tainted. Pull Request resolved: #183856 Approved by: https://github.com/jeffdaily, https://github.com/astrelsky Co-authored-by: Jeff Daily <[email protected]>
This removes the MSVC flags from `CMAKE_HIP_FLAGS{,_<CONFIG>` after `enable_language(HIP)` as discussed here ROCm/TheRock#5175 (comment)
Fixes ROCm/TheRock#5175
Pull Request resolved: pytorch#183365
Approved by: https://github.com/jeffdaily
…_FLAGS (pytorch#183856) ## Issue Fixes ROCm/TheRock#5157. Fixes pytorch#183853. Windows ROCm HIP code was effectively compiled at `-O0` after pytorch#180485 + pytorch#183365 landed, causing a ~99% conv2d FP16 perf regression on gfx1150 (bisected and validated by @astrelsky and @adityas-amd at ROCm/TheRock#5157). ## Diagnosis After pytorch#183365 stripped the MSVC-style `/O2 /Ob2 /DNDEBUG` out of `CMAKE_HIP_FLAGS_RELEASE` and re-appended GNU `-O3 -DNDEBUG`, the actual build command still came up unoptimized. Inspecting the generated `build.ninja` shows why: - `CMAKE_HIP_FLAGS` contents (e.g. `--offload-compress -std=c++20 --offload-arch=...`) **do** reach the `$FLAGS` ninja variable used by every HIP compile. - `CMAKE_HIP_FLAGS_<CONFIG>` contents (e.g. `-O3 -DNDEBUG`) **do not**. That's the actual cause of the `-O0` fallback — `CMAKE_HIP_FLAGS_RELEASE` is dead code on the Windows HIP compile path. ## Fix - Drop the dead `string(APPEND CMAKE_HIP_FLAGS_<CONFIG> ...)` lines. - Inject the appropriate `-O{3,2,0,s}` plus `-DNDEBUG`/`-g` directly into `CMAKE_HIP_FLAGS`, gated on `CMAKE_BUILD_TYPE`. This works for single-config generators (Ninja, Makefiles), which is what the Windows ROCm build uses. - Drop the `-O3` from the compile rule template so non-Release configs aren't tainted. Pull Request resolved: pytorch#183856 Approved by: https://github.com/jeffdaily, https://github.com/astrelsky Co-authored-by: Jeff Daily <[email protected]>
This removes the MSVC flags from `CMAKE_HIP_FLAGS{,_<CONFIG>` after `enable_language(HIP)` as discussed here ROCm/TheRock#5175 (comment)
Fixes ROCm/TheRock#5175
Pull Request resolved: pytorch#183365
Approved by: https://github.com/jeffdaily
…_FLAGS (pytorch#183856) ## Issue Fixes ROCm/TheRock#5157. Fixes pytorch#183853. Windows ROCm HIP code was effectively compiled at `-O0` after pytorch#180485 + pytorch#183365 landed, causing a ~99% conv2d FP16 perf regression on gfx1150 (bisected and validated by @astrelsky and @adityas-amd at ROCm/TheRock#5157). ## Diagnosis After pytorch#183365 stripped the MSVC-style `/O2 /Ob2 /DNDEBUG` out of `CMAKE_HIP_FLAGS_RELEASE` and re-appended GNU `-O3 -DNDEBUG`, the actual build command still came up unoptimized. Inspecting the generated `build.ninja` shows why: - `CMAKE_HIP_FLAGS` contents (e.g. `--offload-compress -std=c++20 --offload-arch=...`) **do** reach the `$FLAGS` ninja variable used by every HIP compile. - `CMAKE_HIP_FLAGS_<CONFIG>` contents (e.g. `-O3 -DNDEBUG`) **do not**. That's the actual cause of the `-O0` fallback — `CMAKE_HIP_FLAGS_RELEASE` is dead code on the Windows HIP compile path. ## Fix - Drop the dead `string(APPEND CMAKE_HIP_FLAGS_<CONFIG> ...)` lines. - Inject the appropriate `-O{3,2,0,s}` plus `-DNDEBUG`/`-g` directly into `CMAKE_HIP_FLAGS`, gated on `CMAKE_BUILD_TYPE`. This works for single-config generators (Ninja, Makefiles), which is what the Windows ROCm build uses. - Drop the `-O3` from the compile rule template so non-Release configs aren't tainted. Pull Request resolved: pytorch#183856 Approved by: https://github.com/jeffdaily, https://github.com/astrelsky Co-authored-by: Jeff Daily <[email protected]>
## Linked issue or supporting maintainer Fixes #184397 Supported by @jeffdaily Related: #183856 (the workaround this replaces), #183853 and ROCm/TheRock#5157 (the original -O0 regression). ## BC-breaking? No. ## Summary (human written only) Replaces the CMAKE_BUILD_TYPE-gated HIP flag injection on Windows with per-config defaults, so multi-config generators get optimized HIP code too. ## Agent details (if applicable) Problem: #183856 injects the HIP optimization flags into `CMAKE_HIP_FLAGS` based on `CMAKE_BUILD_TYPE`, because per-config flags were believed not to reach the HIP compile line under LoadHIP's custom `CMAKE_HIP_COMPILE_OBJECT`. As a result, Ninja Multi-Config compiles HIP with no `-O` flag at all, in every configuration. Cause: that belief was wrong. The rule's `<FLAGS>` includes `CMAKE_HIP_FLAGS_<CONFIG>` as for any language; the tree just before #183856 already had `-O3 -DNDEBUG` on every HIP compile in build.ninja (CMake 3.31.6 through 4.4.4). The -O0 regression came from CMake treating HIP as an MSVC-frontend language when C/CXX use clang-cl: no per-config HIP defaults before CMake 4.3, MSVC ones that clang++ rejects from 4.3 on. #183365 had already fixed that; the regression was measured only on builds predating it. Change: drop the `CMAKE_BUILD_TYPE` injection and, after the existing strip, set each standard config's GNU default (`-O0 -g`, `-O3 -DNDEBUG`, `-Os -DNDEBUG`, `-O2 -g -DNDEBUG`) in `CMAKE_HIP_FLAGS_<CONFIG>` unless it already has an `-O` level. This keeps user overrides and is idempotent for the second `include(LoadHIP)` in `aten/CMakeLists.txt`. Test plan, done with Claude on Windows 11, TheRock rocm-sdk 7.14, gfx1151, SDK clang-cl, cmake 4.4.4: ``` python tools/amd_build/build_amd.py python -m pip install -e . -v --no-build-isolation ``` All 262 HIP compile edges in build/build.ninja get `-O3 -DNDEBUG` in the per-config position. A standalone project with LoadHIP's setup on CMake 3.31.6, 4.2.3, 4.3.2 and 4.4.4: Ninja Debug/Release/RelWithDebInfo/MinSizeRel each get their config's flags, Ninja Multi-Config gets per-config flags (main gives none), and `-DCMAKE_HIP_FLAGS_RELEASE=-O1 ...` is kept. conv2d fp16 (1x3x1024x1024, k7, 64 out channels) runs at parity with the TheRock 2.12 wheel on gfx1151 (2458-2907 vs 2437-2517 GFLOP/s). Pull Request resolved: #201482 Approved by: https://github.com/jeffdaily Co-authored-by: Jeff Daily <[email protected]>
This removes the MSVC flags from
CMAKE_HIP_FLAGS{,_<CONFIG>afterenable_language(HIP)as discussed here ROCm/TheRock#5175 (comment)Fixes ROCm/TheRock#5175
cc @jeffdaily @sunway513 @jithunnair-amd @pruthvistony @ROCmSupport @jataylo @hongxiayang @naromero77amd @pragupta @jerrymannil @xinyazhang