E58A fix a compilation issue when TORCH_XPU_ARCH_LIST is an empty string by jingxu10 · Pull Request #153604 · pytorch/pytorch · GitHub
[go: up one dir, main page]

Skip to content

fix a compilation issue when TORCH_XPU_ARCH_LIST is an empty string #153604

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from

Conversation

jingxu10
Copy link
Contributor
@jingxu10 jingxu10 commented May 15, 2025

When XPU_ARCH_FLAGS is an empty string, compilation will fail on C10_STRINGIZE(XPU_ARCH_FLAGS) in file torch/csrc/xpu/Module.cpp on Windows.
This PR fixes this issue by setting TORCH_XPU_ARCH_LIST to "" to avoid an empty string conversion in C10_STRINGIZE() when compiling without an AOT.

@jingxu10 jingxu10 requested a review from guangyey May 15, 2025 09:11
Copy link
pytorch-bot bot commented May 15, 2025

🔗 Helpful Links

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

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

✅ You can merge normally! (1 Unrelated Failure)

As of commit fe6bfc8 with merge base 8c16d0e (image):

UNSTABLE - The following job is marked as unstable, possibly due to flakiness on trunk:

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

@pytorch-bot pytorch-bot bot added the topic: not user facing topic category label May 15, 2025
@jingxu10 jingxu10 marked this pull request as draft May 15, 2025 09:42
@jingxu10 jingxu10 force-pushed the jingxu10/null_xpu_aot_main branch from 6051cae to 3e2a85c Compare May 15, 2025 22:19
@jingxu10 jingxu10 marked this pull request as ready for review May 15, 2025 22:20
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Change the empty string to "" to avoid string conversion failure in C10_STRINGIZE function.

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 a better way is to promote C10_STRINGIZE to support the empty string "", like

#define C10_STRINGIZE_IMPL(...) #__VA_ARGS__
#define C10_STRINGIZE(...) C10_STRINGIZE_IMPL(__VA_ARGS__)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried. It doesn't work. Still have the parsing issue.
image

@@ -431,6 +431,9 @@ endif()
# Preserve XPU arch flags
if(USE_XPU)
string(REPLACE "," " " _ARCH_FLAGS_readable "${TORCH_XPU_ARCH_LIST}")
if("${TORCH_XPU_ARCH_LIST}" STREQUAL "")
set(_ARCH_FLAGS_readable "\\\"\\\"")
@@ -19,7 +19,7 @@ static PyObject* THXPModule_getArchFlags(PyObject* self, PyObject* noargs) {
HANDLE_TH_ERRORS
#ifdef XPU_ARCH_FLAGS
static const char* flags = C10_STRINGIZE(XPU_ARCH_FLAGS);
return THPUtils_packString(flags);
return THPUtils_packString(strcmp(flags, "\"\"") == 0 ? "" : flags);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Set the value back from "" to an empty string to avoid torch._C._xpu_getArchFlags() function returns "" as the arch flag.

@etaf etaf requested a review from Copilot May 15, 2025 23:49
Copy link
Contributor
@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a compilation issue on Windows when compiling without an AOT by ensuring that an empty XPU_ARCH_FLAGS value is handled correctly.

  • Replace the direct return of THPUtils_packString(flags) with a conditional check on flags.
  • Updates the behavior in torch/csrc/xpu/Module.cpp to avoid passing an empty string literal to C10_STRINGIZE.
Files not reviewed (1)
  • torch/CMakeLists.txt: Language not supported

@@ -19,7 +19,7 @@ static PyObject* THXPModule_getArchFlags(PyObject* self, PyObject* noargs) {
HANDLE_TH_ERRORS
#ifdef XPU_ARCH_FLAGS
static const char* flags = C10_STRINGIZE(XPU_ARCH_FLAGS);
return THPUtils_packString(flags);
return THPUtils_packString(strcmp(flags, "\"\"") == 0 ? "" : flags);
Copy link
Preview
Copilot AI May 15, 2025

Choose a reason for hiding this comment

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

[nitpick] The conditional check compares 'flags' to a hard-coded magic literal """". Consider defining a named constant or adding a comment to clarify why the comparison is needed for handling empty flags.

Suggested change
return THPUtils_packString(strcmp(flags, "\"\"") == 0 ? "" : flags);
static const char* EMPTY_FLAGS = "\"\""; // Represents an empty flags string
return THPUtils_packString(strcmp(flags, EMPTY_FLAGS) == 0 ? "" : flags);

Copilot uses AI. Check for mistakes.

@etaf etaf added the ciflow/xpu Run XPU CI tasks label May 15, 2025
@EikanWang
Copy link
Collaborator

When will XPU_ARCH_FLAGS be an empty string?

@jingxu10
Copy link
Contributor Author

When will XPU_ARCH_FLAGS be an empty string?

When people don't want to perform compilation for device.

@jingxu10 jingxu10 force-pushed the jingxu10/null_xpu_aot_main branch from 77b0c18 to 4058202 Compare May 16, 2025 03:32
@jerryzh168 jerryzh168 added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label May 16, 2025
@jingxu10 jingxu10 marked this pull request as draft May 20, 2025 21:30
@jingxu10 jingxu10 marked this pull request as ready for review May 22, 2025 07:55
// Since C10_STRINGIZE doesn't handle an empty string as its input correctly,
// the string "\"\"" will be passed from cmake to indicate an empty string.
static const char* EMPTY_FLAGS = "\"\"";
return THPUtils_packString(std::strcmp(flags, EMPTY_FLAGS) == 0 ? "" : flags);
Copy link
Collaborator
@guangyey guangyey May 23, 2025

Choose a reason for hiding this comment

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

Suggested change
return THPUtils_packString(std::strcmp(flags, EMPTY_FLAGS) == 0 ? "" : flags);
static const std::string flags = std::string(C10_STRINGIZE(XPU_ARCH_FLAGS));
return THPUtils_packString(flags);

Let's work around this issue using std::string constructor.

@jingxu10 jingxu10 marked this pull request as draft May 23, 2025 09:14
@jingxu10 jingxu10 force-pushed the jingxu10/null_xpu_aot_main branch from 696d4b4 to def8263 Compare May 23, 2025 12:28
@jingxu10 jingxu10 force-pushed the jingxu10/null_xpu_aot_main branch from def8263 to 4cb0843 Compare May 23, 2025 21:20
@guangyey
Copy link
Collaborator

@pytorchbot rebase

@pytorchmergebot
Copy link
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here

@pytorchmergebot
Copy link
Collaborator

Successfully rebased jingxu10/null_xpu_aot_main onto refs/remotes/origin/viable/strict, please pull locally before adding more changes (for example, via git checkout jingxu10/null_xpu_aot_main && git pull --rebase)

@pytorchmergebot pytorchmergebot force-pushed the jingxu10/null_xpu_aot_main branch from d47fa27 to fe6bfc8 Compare May 26, 2025 09:51
@guangyey guangyey moved this to Review Required in PyTorch Intel May 26, 2025
@guangyey guangyey marked this pull request as ready for review May 26, 2025 09:53
@guangyey
Copy link
Collaborator

@pytorchbot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label May 27, 2025
@guangyey guangyey moved this from Review Required to Approved in PyTorch Intel May 27, 2025
@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

@github-project-automation github-project-automation bot moved this from Approved to Done in PyTorch Intel May 27, 2025
@jingxu10 jingxu10 deleted the jingxu10/null_xpu_aot_main branch May 27, 2025 05:35
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 Merged 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
Status: Done
Development

Successfully merging this pull request may close these issues.

8 participants
0