From 35e8c8195c81edce63a36282334e7f9edc5955d0 Mon Sep 17 00:00:00 2001 From: Dmitriy Sobolev Date: Mon, 25 Nov 2024 19:48:24 +0000 Subject: [PATCH] [Cmake] Make SYCL detection more portable Signed-off-by: Dmitriy Sobolev --- CMakeLists.txt | 47 +++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3cb28a1693..bb58d795a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -75,26 +75,35 @@ include(CheckCXXCompilerFlag) include(CheckIncludeFileCXX) include(GNUInstallDirs) -# Check SYCL support by the compiler -check_cxx_compiler_flag("-fsycl" _fsycl_option) -if (_fsycl_option) - CHECK_INCLUDE_FILE_CXX("sycl/sycl.hpp" _sycl_header "-fsycl") - if (NOT _sycl_header) - CHECK_INCLUDE_FILE_CXX("CL/sycl.hpp" _sycl_header_old "-fsycl") +# Detect SYCL support +if (NOT DEFINED ONEDPL_BACKEND OR ONEDPL_BACKEND MATCHES "^(dpcpp|dpcpp_only)$") + message(STATUS "Checking for SYCL support") + + set(FSYCL_OPTION "-fsycl") + check_cxx_compiler_flag(${FSYCL_OPTION} _fsycl_option) + if (_fsycl_option) + set(FSYCL_OPTION_IF_SUPPORTED ${FSYCL_OPTION}) endif() - if (_sycl_header OR _sycl_header_old) - set(_sycl_support TRUE) + + CHECK_INCLUDE_FILE_CXX("sycl/sycl.hpp" SYCL_HEADER ${FSYCL_OPTION_IF_SUPPORTED}) + if (NOT SYCL_HEADER) + CHECK_INCLUDE_FILE_CXX("CL/sycl.hpp" SYCL_HEADER_OLD ${FSYCL_OPTION_IF_SUPPORTED}) endif() -endif() -# Exit with an error when DPCPP backend is explicitly set and SYCL is not supported -if (ONEDPL_BACKEND MATCHES "^(dpcpp|dpcpp_only)$" AND NOT _sycl_support) - message(FATAL_ERROR "${CMAKE_CXX_COMPILER} doesn't support -fsycl option or sycl.hpp is not available. It is required if ONEDPL_BACKEND=${ONEDPL_BACKEND}") + if (SYCL_HEADER OR SYCL_HEADER_OLD) + message(STATUS "SYCL is supported") + else() + if (ONEDPL_BACKEND MATCHES "^(dpcpp|dpcpp_only)$") + message(FATAL_ERROR "SYCL is not supported. It is required for ONEDPL_BACKEND=${ONEDPL_BACKEND}") + else() + message(STATUS "SYCL is not supported") + endif() + endif() endif() # Set the default backend if one has not been explicitly provided -if (NOT ONEDPL_BACKEND) - if (_sycl_support) +if (NOT DEFINED ONEDPL_BACKEND) + if (SYCL_SUPPORT) set(ONEDPL_BACKEND "dpcpp" CACHE STRING "Threading backend") else() set(ONEDPL_BACKEND "tbb" CACHE STRING "Threading backend") @@ -186,12 +195,6 @@ if (ONEDPL_BACKEND MATCHES "^(tbb|dpcpp|dpcpp_only)$") ) if (ONEDPL_BACKEND MATCHES "^(dpcpp|dpcpp_only)$") - # Enable SYCL* with compilers/compiler drivers not passing -fsycl by default - if (_sycl_support AND NOT CMAKE_CXX_COMPILER MATCHES ".*(dpcpp-cl|dpcpp)(.exe)?$") - message(STATUS "Adding -fsycl compiler option") - set(USE_FSYCL_OPTION TRUE) - endif() - # check device type for oneDPL test targets if (ONEDPL_DEVICE_TYPE MATCHES "^(CPU|GPU|FPGA_EMU|FPGA_HW)$") if (NOT _ONEDPL_PSTL_OFFLOAD STREQUAL off) @@ -274,7 +277,7 @@ if (ONEDPL_BACKEND MATCHES "^(tbb|dpcpp|dpcpp_only)$") # DPC++ specific compiler options target_compile_options(oneDPL INTERFACE - $<$:-fsycl> + ${FSYCL_OPTION_IF_SUPPORTED} $<$,$>:-fintelfpga> ) if (DEFINED ONEDPL_USE_UNNAMED_LAMBDA) @@ -305,7 +308,7 @@ if (ONEDPL_BACKEND MATCHES "^(tbb|dpcpp|dpcpp_only)$") # DPC++ specific link options target_link_libraries(oneDPL INTERFACE - $<$:-fsycl> + ${FSYCL_OPTION_IF_SUPPORTED} $<$,$>:-fintelfpga> $<$:-Xshardware> $<$,$>:-fsycl-link>