Skip to content

[ROCm] Keep an already-set HIP compiler in LoadHIP - #201449

Closed
0xDELUXA wants to merge 2 commits into
pytorch:mainfrom
0xDELUXA:rocm-loadhip-keep-hip-compiler
Closed

0xDELUXA wants to merge 2 commits into
pytorch:mainfrom
0xDELUXA:rocm-loadhip-keep-hip-compiler

Conversation

@0xDELUXA

@0xDELUXA 0xDELUXA commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Linked issue or supporting maintainer

Fixes #201447

BC-breaking?

No

Summary (human written only)

LoadHIP.cmake now picks the HIP compiler only when CMAKE_HIP_COMPILER is not already defined. A project that passes -DCMAKE_HIP_COMPILER, or enables HIP before find_package(Torch), keeps its own compiler instead of having it replaced, which made CMake delete the cache and reconfigure without the user's options. When nothing sets the compiler, nothing changes. Changing ROCM_PATH or HIP_CLANG_PATH in an existing build directory no longer switches compilers, which matches how CMake treats other compilers.

Agent details (if applicable)

Prepared with Claude; I reviewed the change and reran the tests myself.

Tested on Windows with ROCm torch 2.16.0a0+rocm10.2.0a20261022 (gfx1200), using a copy of the installed torch CMake config with this change applied. Two consumers hit the cache reset before the change: one that enables HIP with a differently spelled path to the same clang++, and one that only passes -DCMAKE_HIP_COMPILER with a different spelling. Both configure repeatedly with their options intact after the change, and build and run a HIP kernel alongside LibTorch. A consumer that sets no compiler behaves as before. Not tested on Linux.

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

@pytorch-bot pytorch-bot Bot added the module: rocm AMD GPU support for Pytorch label Oct 19, 2026
@pytorch-bot

pytorch-bot Bot commented Oct 19, 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/201449

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

✅ No Failures

As of commit e3c3f1e with merge base 3d7a235 (image):
💚 Looks good so far! There are no failures yet. 💚

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

@0xDELUXA

Copy link
Copy Markdown
Contributor Author

@pytorchbot label "release notes: rocm"

@pytorch-bot pytorch-bot Bot added the release notes: rocm mandatorylabel label Oct 19, 2026
@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 Oct 19, 2026

@jeffdaily jeffdaily left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Non-blocking: the guard covers a project that calls enable_language(HIP) before find_package(Torch). It does not cover a project that only passes -DCMAKE_HIP_COMPILER=<path> with a different spelling (for example a lowercase drive letter) and lets LoadHIP enable HIP. In that case the first configure succeeds, but LoadHIP's spelling silently replaces the user's value. Every re-run of the same configure command then sees the -D value and LoadHIP's value disagree, and deletes the cache again. Checking if(NOT DEFINED CMAKE_HIP_COMPILER) instead would cover both cases. The tradeoff is that changing ROCM_PATH or HIP_CLANG_PATH in an existing build directory would no longer switch compilers, which is CMake's usual compiler behavior. Fine to leave for a follow-up.

@0xDELUXA
0xDELUXA force-pushed the rocm-loadhip-keep-hip-compiler branch from 54dfb3d to 848a486 Compare October 28, 2026 10:39
@0xDELUXA

Copy link
Copy Markdown
Contributor Author

Thanks, confirmed: passing only -DCMAKE_HIP_COMPILER with a different spelling made every second configure delete the cache. Switching the guard to if(NOT DEFINED CMAKE_HIP_COMPILER) fixes that and still covers the enable-first case, so I folded it into this PR instead of a follow-up.

@0xDELUXA 0xDELUXA changed the title [ROCm] Keep the project's HIP compiler when LoadHIP runs after enable_language(HIP) [ROCm] Keep an already-set HIP compiler in LoadHIP Oct 28, 2026
@jeffdaily

Copy link
Copy Markdown
Collaborator

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Oct 29, 2026
@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: 13 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

@0xDELUXA

Copy link
Copy Markdown
Contributor Author

@pytorchbot rebase

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Successfully rebased rocm-loadhip-keep-hip-compiler onto refs/remotes/origin/viable/strict, please pull locally before adding more changes (for example, via git checkout rocm-loadhip-keep-hip-compiler && git pull --rebase)

@pytorchmergebot
pytorchmergebot force-pushed the rocm-loadhip-keep-hip-compiler branch from 848a486 to 7d84cb0 Compare October 29, 2026 19:09
@pytorch-bot

pytorch-bot Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Workflows were awaiting approval. CI has now been triggered for the ciflow labels on this PR.

@0xDELUXA

Copy link
Copy Markdown
Contributor Author

@jeffdaily the earlier merge failed because build-external-packages was missing from main during the #202327 window. Rebased now; could you please approve the workflows and re-run the merge?

A project that calls check_language(HIP) before find_package(Torch), with no HIP compiler on PATH, caches CMAKE_HIP_COMPILER as NOTFOUND. That value is DEFINED, so LoadHIP skipped its own lookup and enable_language(HIP) failed with "No CMAKE_HIP_COMPILER could be found". Test the value instead of DEFINED; a compiler set by -D or an earlier enable_language(HIP) is still kept.

Test Plan: a NONE-language project that runs check_language(HIP) with no clang on PATH, then includes utils.cmake and LoadHIP.cmake, configured against the TheRock ROCm SDK on Windows. Before this change it fails in enable_language(HIP); after it, HIP is enabled with the SDK clang++. With -DCMAKE_HIP_COMPILER set, the given compiler is kept, and a reconfigure keeps the cache.

```
cmake -S src -B build -G Ninja -DLOADHIP=<checkout>/cmake/public/LoadHIP.cmake -DCMAKE_HIP_COMPILER_ROCM_ROOT=<rocm>
```

Authored with Claude.
@jeffdaily

Copy link
Copy Markdown
Collaborator

I pushed a small maintainer commit on top of the rebase, e3c3f1e.

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

The 10-28 revision changed the guard from "HIP not yet enabled" to if(NOT DEFINED CMAKE_HIP_COMPILER). That correctly keeps a compiler set by -D or by an earlier enable_language(HIP), but a project that calls check_language(HIP) before find_package(Torch) with no HIP compiler on PATH gets CMAKE_HIP_COMPILER cached as NOTFOUND. That value is DEFINED, so LoadHIP skipped its own lookup and enable_language(HIP) failed with "No CMAKE_HIP_COMPILER could be found". The commit tests the value instead (if(NOT CMAKE_HIP_COMPILER)), which is false for both unset and NOTFOUND. Verified on Windows with the TheRock SDK: that case failed before and configures after; a -D compiler is still kept, and a reconfigure keeps the cache.

@0xDELUXA

Copy link
Copy Markdown
Contributor Author

Thanks, I hadn't considered that check_language(HIP) could leave NOTFOUND in the cache. Testing the value instead of DEFINED covers both cases while still keeping a -D compiler.

@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

dominikjastrzebskix pushed a commit to dominikjastrzebskix/pytorch that referenced this pull request Nov 5, 2026
## Linked issue or supporting maintainer

Fixes pytorch#201447

## BC-breaking?

No

## Summary (human written only)

LoadHIP.cmake now picks the HIP compiler only when CMAKE_HIP_COMPILER is not already defined. A project that passes -DCMAKE_HIP_COMPILER, or enables HIP before find_package(Torch), keeps its own compiler instead of having it replaced, which made CMake delete the cache and reconfigure without the user's options. When nothing sets the compiler, nothing changes. Changing ROCM_PATH or HIP_CLANG_PATH in an existing build directory no longer switches compilers, which matches how CMake treats other compilers.

## Agent details (if applicable)

Prepared with Claude; I reviewed the change and reran the tests myself.

> Tested on Windows with ROCm torch 2.16.0a0+rocm10.2.0a20261022 (gfx1200), using a copy of the installed torch CMake config with this change applied. Two consumers hit the cache reset before the change: one that enables HIP with a differently spelled path to the same clang++, and one that only passes -DCMAKE_HIP_COMPILER with a different spelling. Both configure repeatedly with their options intact after the change, and build and run a HIP kernel alongside LibTorch. A consumer that sets no compiler behaves as before. Not tested on Linux.

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

Co-authored-by: Jeff Daily <[email protected]>
dominikjastrzebskix pushed a commit to dominikjastrzebskix/pytorch that referenced this pull request Nov 9, 2026
## Linked issue or supporting maintainer

Fixes pytorch#201447

## BC-breaking?

No

## Summary (human written only)

LoadHIP.cmake now picks the HIP compiler only when CMAKE_HIP_COMPILER is not already defined. A project that passes -DCMAKE_HIP_COMPILER, or enables HIP before find_package(Torch), keeps its own compiler instead of having it replaced, which made CMake delete the cache and reconfigure without the user's options. When nothing sets the compiler, nothing changes. Changing ROCM_PATH or HIP_CLANG_PATH in an existing build directory no longer switches compilers, which matches how CMake treats other compilers.

## Agent details (if applicable)

Prepared with Claude; I reviewed the change and reran the tests myself.

> Tested on Windows with ROCm torch 2.16.0a0+rocm10.2.0a20261022 (gfx1200), using a copy of the installed torch CMake config with this change applied. Two consumers hit the cache reset before the change: one that enables HIP with a differently spelled path to the same clang++, and one that only passes -DCMAKE_HIP_COMPILER with a different spelling. Both configure repeatedly with their options intact after the change, and build and run a HIP kernel alongside LibTorch. A consumer that sets no compiler behaves as before. Not tested on Linux.

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

Co-authored-by: Jeff Daily <[email protected]>
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/trunk Trigger trunk jobs on your pull request Merged missing actionable issue A PR without a linked actionable issue or maintainer sponsor 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] find_package(Torch) replaces an already-enabled CMAKE_HIP_COMPILER, so CMake deletes the project's cache

4 participants