|
| 1 | +##===----------------------------------------------------------------------===## |
| 2 | +# |
| 3 | +# Copyright (C) Intel Corporation |
| 4 | +# |
| 5 | +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +# |
| 7 | +# This file incorporates work covered by the following copyright and permission |
| 8 | +# notice: |
| 9 | +# |
| 10 | +# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 11 | +# See https://llvm.org/LICENSE.txt for license information. |
| 12 | +# |
| 13 | +##===----------------------------------------------------------------------===## |
| 14 | + |
| 15 | +# Installation path: <onedpl_root>/lib/cmake/oneDPL/ |
| 16 | +get_filename_component(_onedpl_root "${CMAKE_CURRENT_LIST_DIR}" REALPATH) |
| 17 | +get_filename_component(_onedpl_root "${_onedpl_root}/../../../" ABSOLUTE) |
| 18 | + |
| 19 | +if (WIN32) |
| 20 | + set(_onedpl_headers_subdir windows) |
| 21 | +else() |
| 22 | + set(_onedpl_headers_subdir linux) |
| 23 | +endif() |
| 24 | + |
| 25 | + |
| 26 | +find_path(_onedpl_headers |
| 27 | + NAMES oneapi/dpl |
| 28 | + PATHS ${_onedpl_root} |
| 29 | + HINTS ENV DPL_ROOT_HINT |
| 30 | + PATH_SUFFIXES include ${_onedpl_headers_subdir}/include |
| 31 | +) |
| 32 | + |
| 33 | + |
| 34 | +if (EXISTS "${_onedpl_headers}") |
| 35 | + if (NOT TARGET oneDPL) |
| 36 | + include(CheckCXXCompilerFlag) |
| 37 | + |
| 38 | + add_library(oneDPL INTERFACE IMPORTED) |
| 39 | + set_target_properties(oneDPL PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${_onedpl_headers}") |
| 40 | + |
| 41 | + if (ONEDPL_PAR_BACKEND AND NOT ONEDPL_PAR_BACKEND MATCHES "^(tbb|openmp|serial)$") |
| 42 | + message(STATUS "oneDPL: ONEDPL_PAR_BACKEND=${ONEDPL_PAR_BACKEND} is requested, but not supported, available backends: tbb, openmp, serial") |
| 43 | + set(oneDPL_FOUND FALSE) |
| 44 | + return() |
| 45 | + endif() |
| 46 | + |
| 47 | + if (NOT ONEDPL_PAR_BACKEND OR ONEDPL_PAR_BACKEND STREQUAL "tbb") # Handle oneTBB backend |
| 48 | + if (NOT TBB_FOUND) |
| 49 | + find_package(TBB 2021 QUIET COMPONENTS tbb PATHS ${CMAKE_SOURCE_DIR}/dpnp/backend/cmake/Modules NO_DEFAULT_PATH) |
| 50 | + endif() |
| 51 | + if (NOT TBB_FOUND AND ONEDPL_PAR_BACKEND STREQUAL "tbb") # If oneTBB backend is requested explicitly, but not found. |
| 52 | + message(STATUS "oneDPL: ONEDPL_PAR_BACKEND=${ONEDPL_PAR_BACKEND} requested, but not found") |
| 53 | + set(oneDPL_FOUND FALSE) |
| 54 | + return() |
| 55 | + elseif (TBB_FOUND) |
| 56 | + set(ONEDPL_PAR_BACKEND tbb) |
| 57 | + message(STATUS "oneDPL: ONEDPL_PAR_BACKEND=${ONEDPL_PAR_BACKEND}, disable OpenMP backend") |
| 58 | + set_target_properties(oneDPL PROPERTIES INTERFACE_LINK_LIBRARIES TBB::tbb) |
| 59 | + set_property(TARGET oneDPL APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS ONEDPL_USE_TBB_BACKEND=1 ONEDPL_USE_OPENMP_BACKEND=0) |
| 60 | + endif() |
| 61 | + endif() |
| 62 | + |
| 63 | + if (NOT ONEDPL_PAR_BACKEND OR ONEDPL_PAR_BACKEND STREQUAL "openmp") # Handle OpenMP backend |
| 64 | + if (UNIX) |
| 65 | + set(_openmp_flag "-fopenmp") |
| 66 | + else() |
| 67 | + set(_openmp_flag "-Qopenmp") |
| 68 | + endif() |
| 69 | + |
| 70 | + # Some compilers may fail if _openmp_flag is not in CMAKE_REQUIRED_LIBRARIES. |
| 71 | + set(_onedpl_saved_required_libs ${CMAKE_REQUIRED_LIBRARIES}) |
| 72 | + set(CMAKE_REQUIRED_LIBRARIES ${_openmp_option}) |
| 73 | + check_cxx_compiler_flag(${_openmp_flag} _openmp_option) |
| 74 | + set(CMAKE_REQUIRED_LIBRARIES ${_onedpl_saved_required_libs}) |
| 75 | + unset(_onedpl_saved_required_libs) |
| 76 | + |
| 77 | + if (NOT _openmp_option AND ONEDPL_PAR_BACKEND STREQUAL "openmp") # If OpenMP backend is requested explicitly, but not supported. |
| 78 | + message(STATUS "oneDPL: ONEDPL_PAR_BACKEND=${ONEDPL_PAR_BACKEND} requested, but not supported") |
| 79 | + set(oneDPL_FOUND FALSE) |
| 80 | + return() |
| 81 | + elseif (_openmp_option) |
| 82 | + set(ONEDPL_PAR_BACKEND openmp) |
| 83 | + message(STATUS "oneDPL: ONEDPL_PAR_BACKEND=${ONEDPL_PAR_BACKEND}, disable oneTBB backend") |
| 84 | + set_target_properties(oneDPL PROPERTIES INTERFACE_COMPILE_OPTIONS ${_openmp_flag}) |
| 85 | + set_target_properties(oneDPL PROPERTIES INTERFACE_LINK_LIBRARIES ${_openmp_flag}) |
| 86 | + set_property(TARGET oneDPL APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS ONEDPL_USE_TBB_BACKEND=0 ONEDPL_USE_OPENMP_BACKEND=1) |
| 87 | + endif() |
| 88 | + endif() |
| 89 | + |
| 90 | + if (NOT ONEDPL_PAR_BACKEND OR ONEDPL_PAR_BACKEND STREQUAL "serial") |
| 91 | + set(ONEDPL_PAR_BACKEND serial) |
| 92 | + message(STATUS "oneDPL: ONEDPL_PAR_BACKEND=${ONEDPL_PAR_BACKEND}, disable oneTBB and OpenMP backends") |
| 93 | + set_property(TARGET oneDPL APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS ONEDPL_USE_TBB_BACKEND=0 ONEDPL_USE_OPENMP_BACKEND=0) |
| 94 | + endif() |
| 95 | + |
| 96 | + check_cxx_compiler_flag("-fsycl" _fsycl_option) |
| 97 | + if (NOT _fsycl_option) |
| 98 | + message(STATUS "oneDPL: -fsycl is not supported by current compiler, set ONEDPL_USE_DPCPP_BACKEND=0") |
| 99 | + set_property(TARGET oneDPL APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS ONEDPL_USE_DPCPP_BACKEND=0) |
| 100 | + endif() |
| 101 | + endif() |
| 102 | +else() |
| 103 | + message(STATUS "oneDPL: headers do not exist ${_onedpl_headers}") |
| 104 | + set(oneDPL_FOUND FALSE) |
| 105 | +endif() |
0 commit comments