From cbe1cb70183dd0d08dd555353eeca72399401ae8 Mon Sep 17 00:00:00 2001 From: "Yu, Guangye" Date: Mon, 21 Jul 2025 09:31:09 +0000 Subject: [PATCH] [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 --- CMakeLists.txt | 4 ---- cmake/public/xpu.cmake | 3 +++ 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d1f8a13fb9fd..63a2f74404c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/cmake/public/xpu.cmake b/cmake/public/xpu.cmake index be083cb93af1..b39e31d0ade8 100644 --- a/cmake/public/xpu.cmake +++ b/cmake/public/xpu.cmake @@ -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})