xpu: improve error handling and reporting in XPU cmake files (#149353)

For #149075

* Add a graceful cmake error instead of cryptic one if SYCL runtime is not found:
```
The link interface of target "c10_xpu" contains:

    torch::xpurt

  but the target was not found.
```
* Suppress unclear cmake error if SYCL compiler is not available and further version query fails:
```
CMake Error at /home/dvrogozh/pytorch/torch/share/cmake/Caffe2/FindSYCLToolkit.cmake:37 (string):
  string sub-command REGEX, mode REPLACE needs at least 6 arguments total to
  command.
```

CC: @gujinghui @EikanWang @fengyuan14 @guangyey @jgong5
Pull Request resolved: https://github.com/pytorch/pytorch/pull/149353
Approved by: https://github.com/guangyey, https://github.com/malfet
This commit is contained in:
Dmitry Rogozhkin
2025-03-20 02:00:36 +00:00
committed by PyTorch MergeBot
parent 3b7bd6c63d
commit 45a879e55b
2 changed files with 10 additions and 1 deletions

View File

@ -100,6 +100,13 @@ if(@USE_XPU@)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
include("${CMAKE_CURRENT_LIST_DIR}/public/xpu.cmake") include("${CMAKE_CURRENT_LIST_DIR}/public/xpu.cmake")
set(CMAKE_MODULE_PATH "${old_CMAKE_MODULE_PATH}") set(CMAKE_MODULE_PATH "${old_CMAKE_MODULE_PATH}")
if(@USE_XPU@ AND NOT PYTORCH_FOUND_XPU)
message(FATAL_ERROR
"Your installed Caffe2 version uses XPU but I cannot find the XPU runtime"
"libraries. Please set the proper oneAPI paths and / or install "
"oneAPI.")
endif()
endif() endif()
if(@CAFFE2_USE_MKL@) if(@CAFFE2_USE_MKL@)

View File

@ -46,7 +46,9 @@ function(parse_sycl_compiler_version version_number)
set(${version_number} "${VERSION_NUMBER_MATCH}" PARENT_SCOPE) set(${version_number} "${VERSION_NUMBER_MATCH}" PARENT_SCOPE)
endfunction() endfunction()
parse_sycl_compiler_version(SYCL_COMPILER_VERSION) if(SYCL_COMPILER)
parse_sycl_compiler_version(SYCL_COMPILER_VERSION)
endif()
if(NOT SYCL_COMPILER_VERSION) if(NOT SYCL_COMPILER_VERSION)
set(SYCL_FOUND False) set(SYCL_FOUND False)