Skip to content

[xpu][feature] enable Sycl CPP extension on Windows#162579

Closed
tbohutyn wants to merge 6 commits intopytorch:mainfrom
tbohutyn:windows_cpp_extension
Closed

[xpu][feature] enable Sycl CPP extension on Windows#162579
tbohutyn wants to merge 6 commits intopytorch:mainfrom
tbohutyn:windows_cpp_extension

Conversation

@tbohutyn
Copy link
Contributor

PR for enabling #153265 on Windows

@pytorch-bot
Copy link

pytorch-bot bot commented Sep 10, 2025

🔗 Helpful Links

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

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

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

@dvrogozh
Copy link
Contributor

@pytorchbot label "release notes: xpu"

@pytorch-bot pytorch-bot bot added the release notes: xpu release notes category label Sep 10, 2025
@dvrogozh
Copy link
Contributor

@tbohutyn, can you, please, make 2 book keeping changes:

  1. Rename the PR to state affinity with XPU and Sycl cpp extension. For example, "xpu: enable Sycl CPP extension on Windows"
  2. Describe current status in the PR description. From internal discussion it seems that /sdl option passed to DPC++ compiler breaks compilation. This needs to be stated as a reason for PR to be a draft.

]
if IS_WINDOWS:
host_cflags = [
"-fsycl",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm curious why Windows build requires -fsycl, while Linux does not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed



def _prepare_ldflags(extra_ldflags, with_cuda, verbose, is_standalone):
def _prepare_ldflags(extra_ldflags, with_cuda, with_sycl, verbose, is_standalone):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you help generalize it a little bit by handling with_cuda and with_sycl with different functions accordingly?

@tbohutyn tbohutyn changed the title cpp extension on windows xpu: enable Sycl CPP extension on Windows Sep 12, 2025
@tbohutyn tbohutyn force-pushed the windows_cpp_extension branch from feb3469 to 335362b Compare September 17, 2025 15:52

external_include = _join_sycl_home("include").replace("\\", "\\\\")
wrapped_host_cflags = [
f"-fsycl-host-compiler={host_cxx}",
Copy link
Contributor

Choose a reason for hiding this comment

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

The /std:c++17 which you add on the next line is actually handled by append_std17_if_no_std_present(host_cflags) which you also call. Can you drop explicit /std:c++17 from the line below?

@jerryzh168 jerryzh168 added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Sep 29, 2025
@tbohutyn tbohutyn force-pushed the windows_cpp_extension branch from 0e32f7c to b05ee61 Compare October 15, 2025 15:52
Copy link
Contributor

@dvrogozh dvrogozh left a comment

Choose a reason for hiding this comment

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

LGTM

@tbohutyn tbohutyn force-pushed the windows_cpp_extension branch from b05ee61 to 4f0320f Compare October 22, 2025 11:58
extra_ldflags.append(f'-L{_join_rocm_home("lib")}')
extra_ldflags.append('-lamdhip64')
if with_sycl:
if IS_WINDOWS:
Copy link
Collaborator

Choose a reason for hiding this comment

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

@dvrogozh I know this is not directly related to this PR, but I’m curious — why isn’t there a Linux branch here?

Copy link
Contributor

Choose a reason for hiding this comment

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

I looked into this. These libraries are needed for both Windows and Linux, otherwise there will be unresolved symbols. The reason why it works on Linux without adding these libraries on the command line is 1) lazy linkage on the build stage, 2) global symbol resolution at runtime (i.e. required libraries are already loaded by import torch by the time extension is being loaded and symbols got resolved).

I think it makes sense to align the code between xpu and cuda/hip and add these libs on Linux as well. @tbohutyn, I have submitted a PR against your fork: tbohutyn#1. It adds libs on Linux and adds a test to formally test this out. Please, take a look on PR and merge to your fork if you are ok with it. Once done your pytorch PR will be automatically updated.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks @dvrogozh

Copy link
Contributor

Choose a reason for hiding this comment

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

@tbohutyn, can you, please, take a look at tbohutyn#1 PR and let me know if you plan to merge it in or you would like me to follow up on 162579 once it's merged?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it would be better to handle this as a follow-up since it targets Linux, while this PR focuses on Windows.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am fine with that. I'll post the Linux PR as soon as this one will get merged as they partially overlap and there will be conflicts to resolve. @guangyey, please, help to merge Windows PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Filed #169322.

@EikanWang EikanWang added ciflow/trunk Trigger trunk jobs on your pull request keep-going Don't stop on first failure, keep running tests until the end labels Nov 21, 2025
@pytorch-bot
Copy link

pytorch-bot bot commented Nov 21, 2025

To add the ciflow label ciflow/trunk please first approve the workflows that are awaiting approval (scroll to the bottom of this page).

This helps ensure we don't trigger CI on this PR until it is actually authorized to do so. Please ping one of the reviewers if you do not have access to approve and run workflows.

@pytorch-bot pytorch-bot bot removed the ciflow/trunk Trigger trunk jobs on your pull request label Nov 21, 2025
@EikanWang EikanWang added the ciflow/trunk Trigger trunk jobs on your pull request label Nov 21, 2025
shutil.rmtree(temp_dir)
if IS_WINDOWS:
# rmtree returns permission error: [WinError 5] Access is denied
# on Windows, this is a workaround
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not set ignore_error=True in rmtree?

Copy link
Contributor

Choose a reason for hiding this comment

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

@tbohutyn : can you, please, check if that's something which can be quick addressed? If not, please, post a note here and let's do that as a follow up.

@astachowiczhabana
Copy link

Hi @EikanWang
I'm taking over this PR after @tbohutyn (he's no longer available). The failing test (xpu / linux-noble-xpu-n-py3.10 / test ) is unrelated to the changes in this PR. It’s caused by a timeout issue that has been observed in other PRs as well HUD.

@EikanWang
Copy link
Collaborator

@pytorchbot merge

@pytorchmergebot
Copy link
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
Collaborator

Merge failed

Reason: 1 jobs have failed, first few of them are: xpu / linux-noble-xpu-n-py3.10 / test (default, 7, 12, linux.idc.xpu)

Details for Dev Infra team Raised by workflow job

@EikanWang
Copy link
Collaborator

@pytorchbot merge -i

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged while ignoring the following 0 checks:

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
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.

@EikanWang
Copy link
Collaborator

@pytorchbot merge -i

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged while ignoring the following 1 checks: xpu / linux-noble-xpu-n-py3.10 / test (default, 7, 12, linux.idc.xpu)

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

@github-project-automation github-project-automation bot moved this from Review Required to Done in PyTorch Intel Dec 1, 2025
dvrogozh added a commit to dvrogozh/pytorch that referenced this pull request Dec 1, 2025
A follow up on the noticed Linux specific issue for sycl cpp
extension. We need to link with more libraries we are linking so far.
Issue got unnoticed as these libraries were already loaded during torch
import. This commit adds missing libs formally to the linker cmdline and
adds test for such a case.

See pytorch#162579 (comment)
Signed-off-by: Dmitry Rogozhkin <dmitry.v.rogozhkin@intel.com>
dvrogozh added a commit to dvrogozh/pytorch that referenced this pull request Dec 1, 2025
A follow up on the noticed Linux specific issue for sycl cpp
extension. We need to link with more libraries we are linking so far.
Issue got unnoticed as these libraries were already loaded during torch
import. This commit adds missing libs formally to the linker cmdline and
adds test for such a case.

See pytorch#162579 (comment)
Signed-off-by: Dmitry Rogozhkin <dmitry.v.rogozhkin@intel.com>
dvrogozh added a commit to dvrogozh/pytorch that referenced this pull request Dec 4, 2025
A follow up on the noticed Linux specific issue for sycl cpp
extension. We need to link with more libraries we are linking so far.
Issue got unnoticed as these libraries were already loaded during torch
import. The dd18a75 commit has added missing libs formally to the linker
cmdline. Current commit further adds test for such a case.

See pytorch#162579 (comment)
Signed-off-by: Dmitry Rogozhkin <dmitry.v.rogozhkin@intel.com>
pytorchmergebot pushed a commit to dvrogozh/pytorch that referenced this pull request Dec 8, 2025
A follow up on the noticed Linux specific issue for sycl cpp
extension. We need to link with more libraries we are linking so far.
Issue got unnoticed as these libraries were already loaded during torch
import. The dd18a75 commit has added missing libs formally to the linker
cmdline. Current commit further adds test for such a case.

See pytorch#162579 (comment)
Signed-off-by: Dmitry Rogozhkin <dmitry.v.rogozhkin@intel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request ciflow/xpu Run XPU CI tasks keep-going Don't stop on first failure, keep running tests until the end Merged open source release notes: xpu release notes category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.