From 45a879e55bb43bf79c0158128da83b4e99b5a212 Mon Sep 17 00:00:00 2001 From: Dmitry Rogozhkin Date: Thu, 20 Mar 2025 02:00:36 +0000 Subject: [PATCH] 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 --- cmake/Caffe2Config.cmake.in | 7 +++++++ cmake/Modules/FindSYCLToolkit.cmake | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/cmake/Caffe2Config.cmake.in b/cmake/Caffe2Config.cmake.in index c23b3990aff8..3465e91cab8e 100644 --- a/cmake/Caffe2Config.cmake.in +++ b/cmake/Caffe2Config.cmake.in @@ -100,6 +100,13 @@ if(@USE_XPU@) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") include("${CMAKE_CURRENT_LIST_DIR}/public/xpu.cmake") 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() if(@CAFFE2_USE_MKL@) diff --git a/cmake/Modules/FindSYCLToolkit.cmake b/cmake/Modules/FindSYCLToolkit.cmake index 808a3ec33eca..5ac3785c4709 100644 --- a/cmake/Modules/FindSYCLToolkit.cmake +++ b/cmake/Modules/FindSYCLToolkit.cmake @@ -46,7 +46,9 @@ function(parse_sycl_compiler_version version_number) set(${version_number} "${VERSION_NUMBER_MATCH}" PARENT_SCOPE) endfunction() -parse_sycl_compiler_version(SYCL_COMPILER_VERSION) +if(SYCL_COMPILER) + parse_sycl_compiler_version(SYCL_COMPILER_VERSION) +endif() if(NOT SYCL_COMPILER_VERSION) set(SYCL_FOUND False)