Skip to content

[ROCm] Add hipccl include dir for HIP extension builds - #206478

Closed
Naraenda wants to merge 1 commit into
pytorch:mainfrom
Naraenda:users/naraenda/make-hipccl-include-dirs-visible-upstream
Closed

Naraenda wants to merge 1 commit into
pytorch:mainfrom
Naraenda:users/naraenda/make-hipccl-include-dirs-visible-upstream

Conversation

@Naraenda

@Naraenda Naraenda commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Linked issue or supporting maintainer

Supported by @jeffdaily

BC-breaking?

No. Upcoming changes in ROCm/rocm-libraries (ROCm/rocm-libraries#15610) will likely break ROCm/HIP-based builds of plugins (torchaudio, torchvision, and any third-party torch.utils.cpp_extension consumers) unless they include this patch.

Backporting is required, but should be done on ROCm/pytorch.

Summary

  • Plugins (torchaudio, torchvision) cannot be built because they cannot find libhipcxx, see TheRock CI.
  • Root cause is that hipCUB and rocThrust now rely on libhipcxx, which is only provided under ${ROCM_HOME}/include/hipccl. CMake-based builds (PyTorch itself) find it through find_package(libhipcxx), but cpp_extension compiles have no such mechanism.
  • A minimal fix on the PyTorch side is to add this directory to include_paths() for HIP extensions, guarded by an existence check so it is a no-op on ROCm installs that do not ship hipccl.

Agent details

Key steps: traced the Could not find libhipcxx! error to __has_include(<hip/std/version>) probes in rocthrust's thrust/detail/config/libcxx.h; confirmed the probe path only resolves with -I${ROCM_HOME}/include/hipccl; placed the fix in include_paths() so it reaches the CUDAExtension/CppExtension setup.py flow, JIT load()/load_inline(), and hipify header resolution.

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

@pytorch-bot

pytorch-bot Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

PR Status: Approved 🚀

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

✅ AUTOMATED REVIEW - Ready for human review:

On HIP builds, the PR adds `${ROCM_HOME}/include/hipccl` to
`include_paths(device_type="cuda")` when that directory exists, so
`cpp_extension` builds can find libhipcxx. Recommendation: Approve. The review
found nothing blocking and labels all three points non-blocking, though it asks
that the include-order question be settled with the ROCm maintainers before the
PR leaves draft.

Findings (3):

[minor] torch/utils/cpp_extension.py:1914
Include order when headers exist in both places (non-blocking, low confidence).
hipccl is appended after `${ROCM_HOME}/include`. If an install ships rocprim,
hipCUB and rocThrust both at the top level and under `include/hipccl`, which
copy wins depends on the layout. With `ROCM_HOME=/opt/rocm`, `<hipcub/...>`,
`<thrust/...>` and `<rocprim/...>` come from the top-level copies and only
`<hip/std/...>` comes from hipccl, so top-level hipCUB/rocThrust could be mixed
with hipccl's libhipcxx. With `ROCM_HOME=/usr`, `/usr/include` is skipped, so
the hipccl copies win. Also, JIT users who already pass hipccl via
`extra_include_paths` (emitted as `-I`) will now get it as `-isystem` too. GCC
and clang drop a `-I` dir that is also a system dir, so hipccl would quietly
move after `-isystem ${ROCM_HOME}/include`. Please confirm whether these headers
really exist in both places. If they do, either insert hipccl before
`rocm_home_include` or say in the comment which copy is meant to win.

[minor] torch/utils/cpp_extension.py:1911
Comment wording (non-blocking). "In newer versions of ROCm" is vaguer than the
existing note at `cmake/public/LoadHIP.cmake:382-384`, which says "ROCm 8.0 and
later requires libhipcxx" and plans to make it `REQUIRED` once 8.0 is the
minimum. Please name ROCm 8.0 and point to that `find_package(libhipcxx)`, so
both workarounds get cleaned up together.

[minor] torch/utils/cpp_extension.py:1910
PR description overstates where the fix applies (non-blocking). The description
says the fix reaches "hipify header resolution", but it doesn't. In
`CUDAExtension`, hipify gets `header_include_dirs=include_dirs` (line 1724), and
`include_paths(device_type="cuda")` is only appended later (line 1758). JIT
hipify gets only `extra_include_paths` (line 2561) and ignores everything under
`ROCM_HOME` (line 2563). The code doesn't need hipify to see these headers,
since they are already HIP. Please correct the description anyway, because it is
meant to guide the ROCm/pytorch backport.

Reviewed commit: d0ae17d

Review run

🐛 Report a bad review

🔗 Helpful Links

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

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

✅ No Failures

As of commit d0ae17d with merge base 304eed3 (image):
💚 Looks good so far! There are no failures yet. 💚

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

@Naraenda

Copy link
Copy Markdown
Contributor Author

Drafted until discussed with ROCm maintainers.

@Naraenda

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 Nov 24, 2026
@jeffdaily jeffdaily changed the title fix(cpp_extension): add hipccl include dir for hip extension builds [ROCm] Add hipccl include dir for HIP extension builds Nov 25, 2026
@pytorch-bot pytorch-bot Bot added the module: rocm AMD GPU support for Pytorch label Nov 25, 2026
@Naraenda
Naraenda marked this pull request as ready for review November 25, 2026 12:15
@github-actions
github-actions Bot requested a review from jeffdaily November 25, 2026 12:17
@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 25, 2026
@pytorch-bot pytorch-bot Bot added the in progress PR is being worked on by the author, until the automated review accepts it label Nov 25, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Automated review of d0ae17d: nothing blocking; ready for human review.

On HIP builds, the PR adds ${ROCM_HOME}/include/hipccl to include_paths(device_type="cuda") when that directory exists, so cpp_extension builds can find libhipcxx. Recommendation: Approve. The review found nothing blocking and labels all three points non-blocking, though it asks that the include-order question be settled with the ROCm maintainers before the PR leaves draft.

⚪ 3 non-blocking findings

if os.path.exists(hipccl_include):

Include order when headers exist in both places (non-blocking, low confidence). hipccl is appended after ${ROCM_HOME}/include. If an install ships rocprim, hipCUB and rocThrust both at the top level and under include/hipccl, which copy wins depends on the layout. With ROCM_HOME=/opt/rocm, &lt;hipcub/...&gt;, &lt;thrust/...&gt; and &lt;rocprim/...&gt; come from the top-level copies and only &lt;hip/std/...&gt; comes from hipccl, so top-level hipCUB/rocThrust could be mixed with hipccl's libhipcxx. With ROCM_HOME=/usr, /usr/include is skipped, so the hipccl copies win. Also, JIT users who already pass hipccl via extra_include_paths (emitted as -I) will now get it as -isystem too. GCC and clang drop a -I dir that is also a system dir, so hipccl would quietly move after -isystem ${ROCM_HOME}/include. Please confirm whether these headers really exist in both places. If they do, either insert hipccl before rocm_home_include or say in the comment which copy is meant to win.


# In newer versions of ROCm, hipCUB and rocThrust require libhipcxx,

Comment wording (non-blocking). "In newer versions of ROCm" is vaguer than the existing note at cmake/public/LoadHIP.cmake:382-384, which says "ROCm 8.0 and later requires libhipcxx" and plans to make it REQUIRED once 8.0 is the minimum. Please name ROCm 8.0 and point to that find_package(libhipcxx), so both workarounds get cleaned up together.


# The hipccl directory holds libhipcxx, rocprim, hipCUB, rocThrust.

PR description overstates where the fix applies (non-blocking). The description says the fix reaches "hipify header resolution", but it doesn't. In CUDAExtension, hipify gets header_include_dirs=include_dirs (line 1724), and include_paths(device_type="cuda") is only appended later (line 1758). JIT hipify gets only extra_include_paths (line 2561) and ignores everything under ROCM_HOME (line 2563). The code doesn't need hipify to see these headers, since they are already HIP. Please correct the description anyway, because it is meant to guide the ROCm/pytorch backport.

This review is AI-generated and advisory. Each new automated review replaces the previous one. Report a bad review

@pytorch-bot pytorch-bot Bot added ready for review Automated review passed, ready for a final review by a maintainer. and removed in progress PR is being worked on by the author, until the automated review accepts it labels Nov 25, 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.

Checked against the hipCCL staging ROCm that TheRock's failing run used (10.3.0.dev0+9c85da5) on MI300X, with torch built from this PR's merge base. Without the change, torchvision main and ROCm/audio release/2.11.0.2 fail with "Could not find libhipcxx!", exactly as in TheRock's logs. With only this change to cpp_extension.py, both build with no errors, import, and their GPU ops (nms, roi_align, rnnt_loss) match CPU.

@jeffdaily

Copy link
Copy Markdown
Collaborator

@pytorchbot merge

@pytorch-bot

pytorch-bot Bot commented Nov 25, 2026

Copy link
Copy Markdown

Pull workflow has not been scheduled for the PR yet. It could be because author doesn't have permissions to run those or skip-checks keywords were added to PR/commits, aborting merge. Please get/give approval for the workflows and/or remove skip ci decorators before next merge attempt. If you think this is a mistake, please contact PyTorch Dev Infra.

@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 Nov 25, 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

@jeffdaily

Copy link
Copy Markdown
Collaborator

@pytorchbot merge -i

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

The merge job was canceled or timed out. This most often happen if two merge requests were issued for the same PR, or if merge job was waiting for more than 6 hours for tests to finish. In later case, please do not hesitate to reissue the merge command
For more information see pytorch-bot wiki.

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged while ignoring the following 1 checks: trunk / linux-jammy-cuda13.2-py3.11-gcc11 / test (pr_time_benchmarks, 1, 1, mt-l-bx86iavx512-94-344-t4-8)

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

jeffdaily pushed a commit to ROCm/pytorch that referenced this pull request Nov 26, 2026
…pytorch#206478) (#4069)

## Linked issue or supporting maintainer

Supported by @jeffdaily

## BC-breaking?

No. Upcoming changes in ROCm/rocm-libraries
(ROCm/rocm-libraries#15610) will likely break
ROCm/HIP-based builds of plugins (torchaudio, torchvision, and any
third-party `torch.utils.cpp_extension` consumers) unless they include
this patch.

Backporting is required, but should be done on
[ROCm/pytorch](https://github.com/ROCm/pytorch).

## Summary

* Plugins (torchaudio, torchvision) cannot be built because they cannot
find libhipcxx, [see TheRock
CI](https://github.com/ROCm/TheRock/actions/runs/45290518963/job/138097890882).
* Root cause is that hipCUB and rocThrust now rely on libhipcxx, which
is only provided under `${ROCM_HOME}/include/hipccl`. CMake-based builds
(PyTorch itself) find it through `find_package(libhipcxx)`, but
`cpp_extension` compiles have no such mechanism.
* A minimal fix on the PyTorch side is to add this directory to
`include_paths()` for HIP extensions, guarded by an existence check so
it is a no-op on ROCm installs that do not ship hipccl.

## Agent details

Key steps: traced the `Could not find libhipcxx!` error to
`__has_include(<hip/std/version>)` probes in rocthrust's
`thrust/detail/config/libcxx.h`; confirmed the probe path only resolves
with `-I${ROCM_HOME}/include/hipccl`; placed the fix in
`include_paths()` so it reaches the `CUDAExtension`/`CppExtension`
setup.py flow, JIT `load()`/`load_inline()`, and hipify header
resolution.

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

Co-authored-by: Nara Prasetya <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
jeffdaily pushed a commit to ROCm/pytorch that referenced this pull request Nov 26, 2026
…pytorch#206478) (#4070)

## Linked issue or supporting maintainer

Supported by @jeffdaily

## BC-breaking?

No. Upcoming changes in ROCm/rocm-libraries
(ROCm/rocm-libraries#15610) will likely break
ROCm/HIP-based builds of plugins (torchaudio, torchvision, and any
third-party `torch.utils.cpp_extension` consumers) unless they include
this patch.

Backporting is required, but should be done on
[ROCm/pytorch](https://github.com/ROCm/pytorch).

## Summary

* Plugins (torchaudio, torchvision) cannot be built because they cannot
find libhipcxx, [see TheRock
CI](https://github.com/ROCm/TheRock/actions/runs/45290518963/job/138097890882).
* Root cause is that hipCUB and rocThrust now rely on libhipcxx, which
is only provided under `${ROCM_HOME}/include/hipccl`. CMake-based builds
(PyTorch itself) find it through `find_package(libhipcxx)`, but
`cpp_extension` compiles have no such mechanism.
* A minimal fix on the PyTorch side is to add this directory to
`include_paths()` for HIP extensions, guarded by an existence check so
it is a no-op on ROCm installs that do not ship hipccl.

## Agent details

Key steps: traced the `Could not find libhipcxx!` error to
`__has_include(<hip/std/version>)` probes in rocthrust's
`thrust/detail/config/libcxx.h`; confirmed the probe path only resolves
with `-I${ROCM_HOME}/include/hipccl`; placed the fix in
`include_paths()` so it reaches the `CUDAExtension`/`CppExtension`
setup.py flow, JIT `load()`/`load_inline()`, and hipify header
resolution.

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

Co-authored-by: Nara Prasetya <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
jeffdaily pushed a commit to ROCm/pytorch that referenced this pull request Nov 26, 2026
…pytorch#206478) (#4071)

## Linked issue or supporting maintainer

Supported by @jeffdaily

## BC-breaking?

No. Upcoming changes in ROCm/rocm-libraries
(ROCm/rocm-libraries#15610) will likely break
ROCm/HIP-based builds of plugins (torchaudio, torchvision, and any
third-party `torch.utils.cpp_extension` consumers) unless they include
this patch.

Backporting is required, but should be done on
[ROCm/pytorch](https://github.com/ROCm/pytorch).

## Summary

* Plugins (torchaudio, torchvision) cannot be built because they cannot
find libhipcxx, [see TheRock
CI](https://github.com/ROCm/TheRock/actions/runs/45290518963/job/138097890882).
* Root cause is that hipCUB and rocThrust now rely on libhipcxx, which
is only provided under `${ROCM_HOME}/include/hipccl`. CMake-based builds
(PyTorch itself) find it through `find_package(libhipcxx)`, but
`cpp_extension` compiles have no such mechanism.
* A minimal fix on the PyTorch side is to add this directory to
`include_paths()` for HIP extensions, guarded by an existence check so
it is a no-op on ROCm installs that do not ship hipccl.

## Agent details

Key steps: traced the `Could not find libhipcxx!` error to
`__has_include(<hip/std/version>)` probes in rocthrust's
`thrust/detail/config/libcxx.h`; confirmed the probe path only resolves
with `-I${ROCM_HOME}/include/hipccl`; placed the fix in
`include_paths()` so it reaches the `CUDAExtension`/`CppExtension`
setup.py flow, JIT `load()`/`load_inline()`, and hipify header
resolution.

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

Co-authored-by: Nara Prasetya <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
@amd-mcieslak

amd-mcieslak commented Nov 26, 2026 •

Copy link
Copy Markdown

@jgong5 sorry for the direct ping. Would you be willing to support a small
follow-up to #206478? I'd name you under "Supported by" so the PR isn't
auto-closed; @jeffdaily is the natural reviewer but it's Thanksgiving
in the US.

#206478 added <rocm>/include/hipccl to include_paths(), which fixes
cpp_extension consumers. It doesn't reach one test, which fails with
Could not find libhipcxx!. The fix is one line plus a comment: request the "cuda" include set when IS_HIP_EXTENSION.
Here is the new PR #206919.

Happy to go to @jithunnair-amd or wait for Jeff instead if you'd rather not. Please let me know.

pytorchmergebot pushed a commit that referenced this pull request Dec 1, 2026
## Linked issue or supporting maintainer

* Fixes ROCm/TheRock#10275
* Related to #206478
* Supported by @jeffdaily

## BC-breaking?

No, though backporting may be useful on [ROCm/pytorch](https://github.com/ROCm/pytorch) downstream release branches.

## Summary (human written only)

Upcoming changes to ROCm (ROCm/rocm-libraries#15610) start pulling in code that leaks macros from `windows.h` into HIP compilation for plugin builds (torchaudio, torchvision, etc.) unless `-DNOMINMAX` is added there too, leading to errors like:
```
2026-11-25T08:40:22.9961647Z .../_rocm_sdk_devel/include/hipccl/rocprim/device/detail/device_reduce.hpp:124:41:
error: expected unqualified-id
  124 |                                    std::min(valid_in_last_block, block_size),
2026-11-25T08:40:22.9962014Z C:\Program Files (x86)\Windows
Kits\10\include\10.0.26100.0\shared\minwindef.h:197:29: note: expanded from macro 'min'
  197 | #define min(a,b)            (((a) < (b)) ? (a) : (b))
2026-11-25T08:40:22.9967949Z .../hipccl/hipcub/backend/rocprim/device/device_reduce.hpp:93:48: error: too few
arguments provided to function-like macro invocation
   93 |     return _HIPCUB_STD::numeric_limits<T>::max();
```

We would like to patch this in three places:
1. Here in PyTorch for future libraries that leak macro definitions (setting `-DNOMINMAX` is generally expected when compiling on Windows across many projects). Note that PyTorch already defines `NOMINMAX` for host code here: https://github.com/pytorch/pytorch/blob/a19fc3c3396233aac0d645be7952a76cfd4184b0/CMakeLists.txt#L1286-L1287
2. In TheRock, temporarily: ROCm/TheRock#10283
3. In libhipcxx where the macros are being leaked: ROCm/libhipcxx#44

Pull Request resolved: #206662
Approved by: https://github.com/jeffdaily
amd-mcieslak added a commit to amd-mcieslak/pytorch that referenced this pull request Dec 3, 2026
…ty test

The hipccl include dir added in pytorch#206478 reaches torch.utils.cpp_extension
consumers but not this test, which never uses the extension builder: it
assembles its own hipcc command line from the device_type "cpu" include
set plus a hardcoded -I$GPU_HOME/include.

The "cpu" set carries no ROCm paths at all, and $GPU_HOME/include is the
parent of hipccl rather than hipccl itself, so libhipcxx stays unreachable
and test_cuda_kernel_works_with_2_9 still fails on ROCm with
"thrust/detail/config/libcxx.h:91: error: Could not find libhipcxx!".

Request the "cuda" include set when IS_HIP_EXTENSION, reusing the directory
list from pytorch#206478 rather than hardcoding the path a second time. Strict
no-op on CUDA builds, which keep the "cpu" set.

This branch was previously deployed

1 inactive deployment
bedrock — d0ae17df Deployed Nov 25, 2026 by Naraenda via analyze #41650
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 module: rocm AMD GPU support for Pytorch open source ready for review Automated review passed, ready for a final review by a maintainer. 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.

5 participants