Skip to content

[ROCm] Use HIP include paths in libtorch_agnostic version-compatibility test - #206919

Open
amd-mcieslak wants to merge 1 commit into
pytorch:mainfrom
amd-mcieslak:amd-mcieslak/version-compat-hip-includes
Open

amd-mcieslak wants to merge 1 commit into
pytorch:mainfrom
amd-mcieslak:amd-mcieslak/version-compat-hip-includes

Conversation

@amd-mcieslak

@amd-mcieslak amd-mcieslak commented Nov 27, 2026 •

Copy link
Copy Markdown

Linked issue or supporting maintainer

Supported by @jeffdaily

BC-breaking?

No. Strict no-op on CUDA builds: IS_HIP_EXTENSION is false there, so the test keeps the device_type="cpu" include set it uses today. Only ROCm/HIP builds get a different include list.

Summary (human written)

This is a follow-up to PR #206478, which added <rocm>/include/hipccl to the include path. However, it does not fix tests that do not use the extension builder. In particular, test_cuda_kernel_works_with_2_9 uses torch_include_paths(device_type="cpu") which does not have ROCm paths in it. Because of this, libhipcxx is unreachable and the test does not compile, producing the error: "Could not find libhipcxx!".

The change in this PR is to request the "cuda" include set when torch is built against ROCm (IS_HIP_EXTENSION is true). In that case, it reuses the folder list from PR #206478 (that is where the path for ROCm headers lives). The test_cuda_kernel_works_with_2_9 now requests that set.

I verified on gfx90a with torch 2.15.0 and ROCm-10.3.0a20261126 nightly. The full test class passes, with all 40 negative tests correctly failing to compile.

I also considered an alternative where the include set could be from include_paths("cuda", torch_include_dirs=False), but the proposed change keeps a no-op on CUDA instead.

Agent details

Claude Code assisted with the investigation and produced the trace and measurements below. I reviewed the change and the results and can speak to both.

Why the test reaches rocThrust at all — cuda_kernel.cu includes no thrust header directly; the dependency arrives through torch/headeronly:

cuda_kernel.cu -> kernel.h -> torch/headeronly/core/Dispatch_v2.h -> Dispatch.h
  -> ScalarType.h -> torch/headeronly/util/complex.h:10 -> thrust/complex.h
  -> thrust/detail/config.h -> config/config.h -> libcxx_wrapper/__cccl_config.h
  -> thrust/detail/config/libcxx.h:91: error: Could not find libhipcxx!

complex.h pulls in <thrust/complex.h> under #if defined(__CUDACC__) || defined(__HIPCC__), so any hipcc compile of a source reaching ScalarType.h hits this unless include/hipccl is on the include path. Note thrust resolves from hipcc's builtin include path (<rocm>/lib/llvm/bin/../../../include/thrust/), not from the -I$GPU_HOME/include the test passes, so that flag plays no part in the failure.

Measured include sets, with #206478 applied:

include_paths("cuda"): .../torch/include
                       .../torch/include/torch/csrc/api/include
                       .../torch/include/THH
                       .../<rocm>/include
                       .../<rocm>/include/hipccl     <- added by #206478

include_paths("cpu"):  .../torch/include
                       .../torch/include/torch/csrc/api/include

Reconstructing the test's exact command line, still with #206478 applied:

A) hipcc -c -std=c++20 -DTORCH_TARGET_VERSION=0x0209000000000000 \
     -I$EXT $INC -I$ROCM/include -DUSE_CUDA -DUSE_ROCM=1 cuda_kernel.cu
   -> thrust/detail/config/libcxx.h:91: error: Could not find libhipcxx!

B) identical, plus -I$ROCM/include/hipccl
   -> compiles clean

Full class result after this change (gfx90a, torch 2.15.0+rocm10.3.0a20261126, ROCm devel wheels):

Ran 42 tests in 53.006s
OK

test_cuda_kernel_works_with_2_9 ... ok      <- was failing
test_kernel_works_with_2_9      ... ok
+ 40 "requires 2.10+" negatives ... ok      <- none flipped to a false pass

The negative cases matter here: they assert that 2.10+ sources fail to compile, so a wider include set could in principle turn one into a false pass. Gating on IS_HIP_EXTENSION rather than GPU_HOME keeps CUDA builds byte-identical, and the run above confirms none flipped on ROCm.

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

@pytorch-bot

pytorch-bot Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

PR Status: in progress

Please address review feedback on your PR either with a code/PR description change. If a review comment is irrelevant, react with 👎 on that specific comment to reject it, and leave a short reply explaining why. The change must pass any running CI and existing failures must be classified as unrelated (see status below in this comment).

Passing automated review does not guarantee that this PR will be merged. It still requires maintainer review and may be closed if its design or direction does not align with the project.

To minimize iteration time, feel free to run the pr-review skill from the repo locally. To trigger a fresh automated review, make a new push or comment @pytorchbot review. To bypass automated review, please add the "no automated review" label.

✅ AUTOMATED REVIEW - OUTDATED (earlier commit) - Ready for human review:

On ROCm builds, the PR switches the libtorch_agnostic version-compatibility test
to include_paths("cuda") so that <rocm>/include/hipccl is on the include path
and test_cuda_kernel_works_with_2_9 can find libhipcxx again; CUDA builds are
unaffected. The recommendation is Approve: the fix is correct and the review
raises only one non-blocking cleanup, about where the include set is placed.

Findings (3):

[minor]
test/cpp_extensions/libtorch_agn_2_10_extension/test_version_compatibility.py:66
Non-blocking: the ROCm include set went into the shared `cls.pytorch_includes`
instead of `cls.cuda_includes`. `pytorch_includes` is also passed, with no
condition, to the host-compiler builds in `_compile_cpp_file` (line 110). On
ROCm, the `kernel.cpp` 2.9 control and every `.cpp` "requires 2.10" negative now
get THH, <rocm>/include and <rocm>/include/hipccl, even when `cuda_available` is
False. The host builds don't need them: the rocThrust reason only applies under
__CUDACC__/__HIPCC__, which g++ doesn't define. Also, -I<rocm>/include now
reaches hipcc twice (lines 144-145). The risk is only potential, since all 40
negatives still fail on gfx90a. But a negative passes on any compile error, so
the extra includes make it harder to tell whether it fails for the right reason.
Fix: keep `pytorch_includes` as the "cpu" set. On HIP, fill `cls.cuda_includes`
from `torch_include_paths("cuda", torch_include_dirs=False)`. Gated on
IS_HIP_EXTENSION, that is just as much a no-op on CUDA.

[minor]
test/cpp_extensions/libtorch_agn_2_10_extension/test_version_compatibility.py:58
With or without the suggested move to `cls.cuda_includes`, the new comment at
lines 58-62 should say that the include set applies to every compile in the
class, not only the HIP ones.

[info]
test/cpp_extensions/libtorch_agn_2_10_extension/test_version_compatibility.py:66
Optional: the rest of the file picks ROCm with `ROCM_HOME`/`CUDA_HOME` (lines
39, 139, 149). Using `ROCM_HOME` here instead of `IS_HIP_EXTENSION` would keep
the checks consistent. The two always agree, so behaviour doesn't change.

Reviewed commit: 27ee79c (NOT the current head 66639b0)

Review run

🐛 Report a bad review

🔗 Helpful Links

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

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

⚠️ 4 Awaiting Approval

As of commit 66639b0 with merge base 5f22867 (image):

AWAITING APPROVAL - The following workflows need approval before CI can run:

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

@pytorch-bot pytorch-bot Bot added module: rocm AMD GPU support for Pytorch topic: not user facing topic category labels Nov 27, 2026
@linux-foundation-easycla

linux-foundation-easycla Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

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

  • ✅ Unknown (27ee79c)
  • ✅ login: amd-mcieslak / name: amd-mcieslak (27ee79c)

One or more co-authors of this pull request were not found. You must specify co-authors in commit message trailer via:

Co-authored-by: name <email>

Supported Co-authored-by: formats include:

  1. Anything <[email protected]> - it will locate your GitHub user by id part.
  2. Anything <[email protected]> - it will locate your GitHub user by login part.
  3. Anything <public-email> - it will locate your GitHub user by public-email part. Note that this email must be made public on Github.
  4. Anything <other-email> - it will locate your GitHub user by other-email part but only if that email was used before for any other CLA as a main commit author.
  5. login <any-valid-email> - it will locate your GitHub user by login part, note that login part must be at least 3 characters long.

Alternatively, if the co-author should not be included, remove the Co-authored-by: line from the commit message.

Please update your commit message(s) by doing git commit --amend and then git push [--force] and then request re-running CLA check via commenting on this pull request:

/easycla

@amd-mcieslak
amd-mcieslak marked this pull request as ready for review December 2, 2026 21:02
@github-actions
github-actions Bot requested a review from jeffdaily December 2, 2026 21:07
@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 Dec 2, 2026
@pytorch-bot pytorch-bot Bot added in progress PR is being worked on by the author, until the automated review accepts it 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 Dec 2, 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.
@amd-mcieslak
amd-mcieslak force-pushed the amd-mcieslak/version-compat-hip-includes branch from 27ee79c to 66639b0 Compare December 3, 2026 05:04
@amd-mcieslak

Copy link
Copy Markdown
Author

/easycla

This branch was previously deployed

1 inactive (outdated) deployment
bedrock — 27ee79c5 Deployed Dec 2, 2026 by amd-mcieslak via analyze #47806
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 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.

2 participants