-
Notifications
You must be signed in to change notification settings - Fork 25.1k
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
Conversation
🔗 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 ( 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. |
6051cae
to
3e2a85c
Compare
torch/CMakeLists.txt
Outdated
@@ -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); |
There was a problem hiding this comment.
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.
There was a problem hiding this 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
torch/csrc/xpu/Module.cpp
Outdated
@@ -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); |
There was a problem hiding this comment.
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.
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.
When will |
When people don't want to perform compilation for device. |
77b0c18
to
4058202
Compare
torch/csrc/xpu/Module.cpp
Outdated
// 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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
696d4b4
to
def8263
Compare
def8263
to
4cb0843
Compare
@pytorchbot rebase |
@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here |
Co-authored-by: Aaron Gokaslan <aaronGokaslan@gmail.com>
Co-authored-by: Yu, Guangye <106960996+guangyey@users.noreply.github.com>
Successfully rebased |
d47fa27
to
fe6bfc8
Compare
@pytorchbot merge |
Merge startedYour 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 |
When
XPU_ARCH_FLAGS
is an empty string, compilation will fail onC10_STRINGIZE(XPU_ARCH_FLAGS)
in filetorch/csrc/xpu/Module.cpp
on Windows.This PR fixes this issue by setting
TORCH_XPU_ARCH_LIST
to""
to avoid an empty string conversion inC10_STRINGIZE()
when compiling without an AOT.