Add default XPU toolkit path to CMake (#149270)

# Motivation
Add default XPU runtime path to CMake to mitigate https://github.com/pytorch/pytorch/issues/149075
This ensures proper linking with `libtorch` when a user does not source the Torch XPU toolkit while working on a C++ library or executable.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/149270
Approved by: https://github.com/dvrogozh, https://github.com/EikanWang, https://github.com/atalman
This commit is contained in:
Yu, Guangye 2025-03-21 03:52:51 +00:00 committed by PyTorch MergeBot
parent 66b0a0b61a
commit db9b031b00

View File

@ -12,6 +12,16 @@ if(DEFINED ENV{SYCL_ROOT})
set(SYCL_ROOT $ENV{SYCL_ROOT})
elseif(DEFINED ENV{CMPLR_ROOT})
set(SYCL_ROOT $ENV{CMPLR_ROOT})
else()
# Use the default path to ensure proper linking with torch::xpurt when the user is working with libtorch.
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
set(SYCL_ROOT "/opt/intel/oneapi/compiler/latest")
elseif(CMAKE_SYSTEM_NAME MATCHES "Windows")
set(SYCL_ROOT "C:/Program Files (x86)/Intel/oneAPI/compiler/latest")
endif()
if(NOT EXISTS ${SYCL_ROOT})
set(SYCL_ROOT "")
endif()
endif()
string(COMPARE EQUAL "${SYCL_ROOT}" "" nosyclfound)