Skip to content

[ROCm][Windows] Fix Linux-only headers in CUDACachingAllocator.cpp - #176727

Closed
moonshadow-25 wants to merge 1 commit into
pytorch:mainfrom
moonshadow-25:fix/windows-caching-allocator-headers
Closed

moonshadow-25 wants to merge 1 commit into
pytorch:mainfrom
moonshadow-25:fix/windows-caching-allocator-headers

Conversation

@moonshadow-25

@moonshadow-25 moonshadow-25 commented Mar 6, 2026 •

Copy link
Copy Markdown
Contributor

When building PyTorch with ROCm (USE_ROCM=ON) on Windows, the compiler fails with:

fatal error: 'sys/syscall.h' file not found

The file CUDACachingAllocator.cpp (and its HIPIFY-generated counterpart HIPCachingAllocator.cpp) includes Linux-only POSIX headers under the USE_ROCM preprocessor condition without guarding them for Windows:

#if defined(PYTORCH_C10_DRIVER_API_SUPPORTED) || defined(USE_ROCM)
#include <sys/syscall.h> // Linux only
#include <sys/types.h> // Linux only
#include <unistd.h> // Linux only
#endif

This patch adds #ifndef _WIN32 guards around the Linux-only includes and adds #include <process.h> for Windows (provides _getpid()).

Additional Windows-specific fixes in the same file:

  • pid_t (POSIX type) in ShareHeader struct -> int on Windows
  • getpid() -> _getpid() on Windows in share()
  • Guard syscall(SYS_pidfd_open/getfd, ...) with #ifndef _WIN32 in fromShared() (Linux kernel IPC not available on Windows); add a TORCH_CHECK(false, ...) stub so the code still compiles and gives a clear runtime error if called
  • Guard close() of file descriptor in unmapHandles() with #ifndef _WIN32

Tested on Windows 11 with AMD gfx1151 (Strix Halo iGPU), ROCm 7.12, clang-cl (MSVC-compatible frontend). PyTorch builds and torch.cuda.is_available() returns True.

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

@pytorch-bot

pytorch-bot Bot commented Mar 6, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ You can merge normally! (6 Unrelated Failures)

As of commit 1a60019 with merge base b1a18c5 (image):

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

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

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

pytorch-bot Bot commented Mar 6, 2026

Copy link
Copy Markdown

This PR needs a release notes: label

If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

@linux-foundation-easycla

linux-foundation-easycla Bot commented Mar 6, 2026 •

Copy link
Copy Markdown

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: moonshadow-25 / name: MoonShadow (1a60019)

@moonshadow-25

Copy link
Copy Markdown
Contributor Author

This PR needs a release notes: label

If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example @pytorchbot label "topic: not user facing"

For more information, see https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

@pytorchbot label "topic: not user facing"

@pytorch-bot pytorch-bot Bot added the topic: not user facing topic category label Mar 6, 2026
@moonshadow-25
moonshadow-25 force-pushed the fix/windows-caching-allocator-headers branch from 7c14422 to 4bcfbfd Compare March 6, 2026 17:12
@moonshadow-25

Copy link
Copy Markdown
Contributor Author

/easycla

@moonshadow-25
moonshadow-25 force-pushed the fix/windows-caching-allocator-headers branch from 4bcfbfd to d302984 Compare March 6, 2026 17:17
@moonshadow-25

Copy link
Copy Markdown
Contributor Author

/easycla

@moonshadow-25
moonshadow-25 force-pushed the fix/windows-caching-allocator-headers branch from d302984 to 110ae8c Compare March 6, 2026 17:20
@zou3519 zou3519 added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Mar 7, 2026
@astrelsky

Copy link
Copy Markdown
Contributor

Oh nice, you beat me to it and I noticed just before submitting a pull request to temporarily disable it for windows.

@astrelsky

Copy link
Copy Markdown
Contributor

@ethanwee1 just pinging to make sure you're tracking since I see you were assigned ROCm/TheRock#3603

When building PyTorch with ROCm (USE_ROCM=ON) on Windows, the compiler
fails with:

  fatal error: 'sys/syscall.h' file not found

The file CUDACachingAllocator.cpp (and its HIPIFY-generated counterpart
HIPCachingAllocator.cpp) includes Linux-only POSIX headers under the
`USE_ROCM` preprocessor condition without guarding them for Windows:

  #if defined(PYTORCH_C10_DRIVER_API_SUPPORTED) || defined(USE_ROCM)
  #include <sys/syscall.h>   // Linux only
  #include <sys/types.h>     // Linux only
  #include <unistd.h>        // Linux only
  #endif

This patch adds `#ifndef _WIN32` guards around the Linux-only includes
and adds `#include <process.h>` for Windows (provides `_getpid()`).

Additional Windows-specific fixes in the same file:
- `pid_t` (POSIX type) in `ShareHeader` struct -> `int` on Windows
- `getpid()` -> `_getpid()` on Windows in `share()`
- Guard `syscall(SYS_pidfd_open/getfd, ...)` with `#ifndef _WIN32` in
  `fromShared()` (Linux kernel IPC not available on Windows); add a
  `TORCH_CHECK(false, ...)` stub so the code still compiles and gives
  a clear runtime error if called
- Guard `close()` of file descriptor in `unmapHandles()` with
  `#ifndef _WIN32`

Tested on Windows 11 with AMD gfx1151 (Strix Halo iGPU), ROCm 7.12,
clang-cl (MSVC-compatible frontend). PyTorch builds and
`torch.cuda.is_available()` returns True.
@ethanwee1

ethanwee1 commented Mar 9, 2026 •

Copy link
Copy Markdown
Contributor

@moonshadow-25

Copy link
Copy Markdown
Contributor Author

Thanks @ethanwee1 and @jeffdaily for the review and the CI run!

Closing this as the upstream code has already addressed the ROCm+Windows
issue — the problematic POSIX headers and the ExpandableSegment IPC
implementation are now guarded by #if !defined(USE_ROCM), so they are
excluded from ROCm builds entirely.

@jeffdaily

Copy link
Copy Markdown
Collaborator

The expandable segments PR #173330 got reverted. As part of the rework, I've cherry-picked this PR into it. Thanks for the contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module: rocm AMD GPU support for Pytorch open source 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.

7 participants