[CMake] Move xpu flag to xpu.cmake (#158542)

Pull Request resolved: https://github.com/pytorch/pytorch/pull/158542
Approved by: https://github.com/gujinghui, https://github.com/ezyang
This commit is contained in:
Yu, Guangye 2025-07-21 09:31:09 +00:00 committed by PyTorch MergeBot
parent 9894d43b6c
commit cbe1cb7018
2 changed files with 3 additions and 4 deletions

View File

@ -1190,10 +1190,6 @@ if(APPLE)
append_cxx_flag_if_supported("-Wno-missing-braces" CMAKE_CXX_FLAGS)
endif()
if(USE_XPU)
string(APPEND CMAKE_CXX_FLAGS " -DUSE_XPU")
endif()
if(EMSCRIPTEN)
string(
APPEND

View File

@ -11,6 +11,7 @@ set(XPU_HOST_CXX_FLAGS)
find_package(SYCLToolkit REQUIRED)
if(NOT SYCL_FOUND)
set(PYTORCH_FOUND_XPU FALSE)
# Exit early to avoid populating XPU_HOST_CXX_FLAGS.
return()
endif()
set(PYTORCH_FOUND_XPU TRUE)
@ -36,6 +37,8 @@ torch_xpu_get_arch_list(XPU_ARCH_FLAGS)
# propagate to torch-xpu-ops
set(TORCH_XPU_ARCH_LIST ${XPU_ARCH_FLAGS})
# Ensure USE_XPU is enabled.
string(APPEND XPU_HOST_CXX_FLAGS " -DUSE_XPU")
string(APPEND XPU_HOST_CXX_FLAGS " -DSYCL_COMPILER_VERSION=${SYCL_COMPILER_VERSION}")
if(DEFINED ENV{XPU_ENABLE_KINETO})