Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cmake diagnostics of the used backend #959

Merged
merged 1 commit into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,29 @@ endif()

include(CMakePackageConfigHelpers)
include(CheckCXXCompilerFlag)
include(CheckIncludeFileCXX)
include(GNUInstallDirs)

# Set default back-end in according with compiler (DPC++ or others)
# 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")
endif()
if (_sycl_header OR _sycl_header_old)
set(_sycl_support TRUE)
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}")
endif()

# Set the default backend if one has not been explicitly provided
if (NOT ONEDPL_BACKEND)
if (_fsycl_option)
if (_sycl_support)
set(ONEDPL_BACKEND "dpcpp" CACHE STRING "Threading backend")
else()
set(ONEDPL_BACKEND "tbb" CACHE STRING "Threading backend")
Expand Down Expand Up @@ -161,12 +178,8 @@ if (ONEDPL_BACKEND MATCHES "^(tbb|dpcpp|dpcpp_only)$")
)

if (ONEDPL_BACKEND MATCHES "^(dpcpp|dpcpp_only)$")
if (NOT _fsycl_option)
message(FATAL_ERROR "${CMAKE_CXX_COMPILER} doesn't support -fsycl option.\n"
"It is required if ONEDPL_BACKEND=${ONEDPL_BACKEND}")
endif()
# Enable SYCL* with compilers/compiler drivers not passing -fsycl by default
if (_fsycl_option AND NOT CMAKE_CXX_COMPILER MATCHES ".*(dpcpp-cl|dpcpp)(.exe)?$")
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()
Expand Down
14 changes: 13 additions & 1 deletion cmake/templates/oneDPLConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ if (EXISTS "${_onedpl_headers}")
endif()

include(CheckCXXCompilerFlag)
include(CheckIncludeFileCXX)

add_library(oneDPL INTERFACE IMPORTED)
set_target_properties(oneDPL PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${_onedpl_headers}")
Expand Down Expand Up @@ -106,16 +107,27 @@ if (EXISTS "${_onedpl_headers}")
set_property(TARGET oneDPL APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS ONEDPL_USE_TBB_BACKEND=0 ONEDPL_USE_OPENMP_BACKEND=0)
endif()

# 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")
endif()
if (_sycl_header OR _sycl_header_old)
set(_sycl_support TRUE)
endif()
endif()

if (_sycl_support)
# Enable SYCL* with compilers/compiler drivers not passing -fsycl by default
if (NOT CMAKE_CXX_COMPILER MATCHES ".*(dpcpp-cl|dpcpp)(.exe)?$")
message(STATUS "Adding -fsycl compiler option")
target_compile_options(oneDPL INTERFACE -fsycl)
target_link_libraries(oneDPL INTERFACE -fsycl)
endif()
else()
message(STATUS "oneDPL: -fsycl is not supported by current compiler, set ONEDPL_USE_DPCPP_BACKEND=0")
message(STATUS "oneDPL: -fsycl compiler option is not supported or sycl.hpp is not available, set ONEDPL_USE_DPCPP_BACKEND=0")
set_property(TARGET oneDPL APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS ONEDPL_USE_DPCPP_BACKEND=0)
endif()
endif()
Expand Down