Skip to content

[release/2.13] Fix Windows HIP extension build when hipified sources span drives - #3550

Merged
pragupta merged 1 commit into
ROCm:release/2.13from
tvukovic-amd:release-2.13/fix-windows-hip-extension-cross-drive-relpath
Aug 10, 2026
Merged

pragupta merged 1 commit into
ROCm:release/2.13from
tvukovic-amd:release-2.13/fix-windows-hip-extension-cross-drive-relpath

Conversation

@tvukovic-amd

Copy link
Copy Markdown

cherry pick of pytorch#191743 which solves ROCm/TheRock#6963

…torch#191743)

Fixes CUDAExtension crashing on Windows HIP builds when the build directory and hipified source paths are on different drives.

During hipify, CUDAExtension calls os.path.relpath(hipified_path, build_dir). On Windows, that raises ValueError if the paths are on different drive letters (e.g. checkout on B:, Python/torch on C:). This breaks Windows ROCm extension builds such as torchaudio ROCm/TheRock#6963).

Prefer a relative path when possible; if relpath fails, use the absolute hipified path instead. Linux behavior is unchanged because cross-drive relpath does not fail there.
Pull Request resolved: pytorch#191743
Approved by: https://github.com/pruthvistony, https://github.com/jeffdaily

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Fixes a Windows-specific failure in torch.utils.cpp_extension.CUDAExtension when hipified source files end up on a different drive than the build directory (where os.path.relpath cannot compute a relative path).

Changes:

  • Catch ValueError from os.path.relpath() in the HIP hipification path and fall back to an absolute path for the hipified source.
  • Adjust how hipified source paths are added to the sources list during extension construction.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +1611 to +1615
try:
hip_path = os.path.relpath(hipified_s_abs, build_dir)
except ValueError:
# Cross-drive on Windows: no relative path exists; fall back to absolute (#91797).
hip_path = hipified_s_abs
Comment on lines 1609 to +1613
# setup() arguments must *always* be /-separated paths relative to the setup.py directory,
# *never* absolute paths
hipified_sources.add(os.path.relpath(hipified_s_abs, build_dir))
try:
hip_path = os.path.relpath(hipified_s_abs, build_dir)
except ValueError:
@ethanwee1

Copy link
Copy Markdown

@tvukovic-amd can you start a build on theRock to confirm the cherry pick works?

@ethanwee1

Copy link
Copy Markdown

Please also add it in the PR description

@pragupta
pragupta merged commit 4be323c into ROCm:release/2.13 Aug 10, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants