|
| 1 | +# Data Parallel Control (dpctl) |
| 2 | +# |
| 3 | +# Copyright 2020-2021 Intel Corporation |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | +# |
| 17 | +# CMake find_package() module for the IntelSycl compiler and development |
| 18 | +# environment. |
| 19 | +# |
| 20 | +# Example usage: |
| 21 | +# |
| 22 | +# find_package(IntelSycl) |
| 23 | +# |
| 24 | +# If successful, the following variables will be defined: |
| 25 | +# IntelSycl_FOUND |
| 26 | +# IntelSycl_VERSION |
| 27 | +# IntelSycl_INCLUDE_DIR |
| 28 | +# IntelSycl_C_COMPILER |
| 29 | +# IntelSycl_CXX_COMPILER |
| 30 | +# IntelSycl_SYCL_INCLUDE_DIR |
| 31 | +# IntelSycl_LIBRARY_DIR |
| 32 | +# IntelSycl_SYCL_LIBRARY |
| 33 | +# IntelSycl_OPENCL_LIBRARY |
| 34 | + |
| 35 | +include(FindPackageHandleStandardArgs) |
| 36 | + |
| 37 | +# Check if a specific DPC++ installation directory was provided then set |
| 38 | +# IntelSycl_ROOT to that path. |
| 39 | +if(DPCTL_CUSTOM_DPCPP_INSTALL_DIR) |
| 40 | + set(IntelSycl_ROOT ${DPCTL_CUSTOM_IntelSycl_INSTALL_DIR}) |
| 41 | + set(USING_ONEAPI_DPCPP False) |
| 42 | +# If DPC++ installation was not specified, check for ONEAPI_ROOT |
| 43 | +elseif(DEFINED ENV{ONEAPI_ROOT}) |
| 44 | + if(CMAKE_SYSTEM_NAME STREQUAL "Windows") |
| 45 | + set(IntelSycl_ROOT $ENV{ONEAPI_ROOT}/compiler/latest/windows) |
| 46 | + elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") |
| 47 | + set(IntelSycl_ROOT $ENV{ONEAPI_ROOT}/compiler/latest/linux) |
| 48 | + else() |
| 49 | + message(FATAL_ERROR "Unsupported system.") |
| 50 | + endif() |
| 51 | + set(USING_ONEAPI_DPCPP True) |
| 52 | +else() |
| 53 | + message(FATAL_ERROR, |
| 54 | + "Could not locate a DPC++ installation. Either pass the path to a " |
| 55 | + "custom location using CUSTOM_IntelSycl_INSTALL_DIR or set the ONEAPI_ROOT " |
| 56 | + "environment variable." |
| 57 | + ) |
| 58 | + return() |
| 59 | +endif() |
| 60 | + |
| 61 | +# We will extract the version information from the compiler |
| 62 | +if(USING_ONEAPI_DPCPP) |
| 63 | + set(dpcpp_cmd "${IntelSycl_ROOT}/bin/dpcpp") |
| 64 | + set(dpcpp_arg "--version") |
| 65 | +else() |
| 66 | + set(dpcpp_cmd "${IntelSycl_ROOT}/bin/clang++") |
| 67 | + set(dpcpp_arg "--version") |
| 68 | +endif() |
| 69 | + |
| 70 | +# Check if dpcpp is available |
| 71 | +execute_process( |
| 72 | + COMMAND ${dpcpp_cmd} ${dpcpp_arg} |
| 73 | + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} |
| 74 | + RESULT_VARIABLE dpcpp_result |
| 75 | + OUTPUT_VARIABLE dpcpp_ver |
| 76 | +) |
| 77 | + |
| 78 | +# If dpcpp is found then set the package variables |
| 79 | +if(${dpcpp_result} MATCHES "0") |
| 80 | + string(REPLACE "\n" ";" IntelSycl_VERSION_LIST "${dpcpp_ver}") |
| 81 | + set(IDX 0) |
| 82 | + list(GET IntelSycl_VERSION_LIST 0 dpcpp_ver_line) |
| 83 | + foreach(X ${IntelSycl_VERSION_LIST}) |
| 84 | + message(STATUS "dpcpp ver[${IDX}]: ${X}") |
| 85 | + MATH(EXPR IDX "${IDX}+1") |
| 86 | + endforeach() |
| 87 | + list(GET IntelSycl_VERSION_LIST 0 VERSION_STRING) |
| 88 | + |
| 89 | + # Get the dpcpp version |
| 90 | + string(REGEX MATCH "[0-9]+\.[0-9]+\.[0-9]+" IntelSycl_VERSION ${VERSION_STRING}) |
| 91 | + # Split out the version into major, minor an patch |
| 92 | + string(REPLACE "." ";" IntelSycl_VERSION_LIST1 "${IntelSycl_VERSION}") |
| 93 | + list(GET IntelSycl_VERSION_LIST1 0 IntelSycl_VERSION_MAJOR) |
| 94 | + list(GET IntelSycl_VERSION_LIST1 1 IntelSycl_VERSION_MINOR) |
| 95 | + list(GET IntelSycl_VERSION_LIST1 2 IntelSycl_VERSION_PATCH) |
| 96 | + set(IntelSycl_INCLUDE_DIR ${IntelSycl_ROOT}/include) |
| 97 | + set(IntelSycl_SYCL_INCLUDE_DIR ${IntelSycl_ROOT}/include/sycl) |
| 98 | + set(IntelSycl_LIBRARY_DIR ${IntelSycl_ROOT}/lib) |
| 99 | + if(CMAKE_SYSTEM_NAME STREQUAL "Windows") |
| 100 | + set(IntelSycl_SYCL_LIBRARY ${IntelSycl_ROOT}/lib/sycl.lib) |
| 101 | + set(IntelSycl_OPENCL_LIBRARY ${IntelSycl_ROOT}/lib/OpenCL.lib) |
| 102 | + # Set which compiler wrapper is used by default |
| 103 | + if(USING_ONEAPI_DPCPP) |
| 104 | + set(IntelSycl_CXX_COMPILER ${IntelSycl_ROOT}/bin/dpcpp.exe) |
| 105 | + set(IntelSycl_C_COMPILER ${IntelSycl_ROOT}/bin/clang-cl.exe) |
| 106 | + else() |
| 107 | + set(IntelSycl_CXX_COMPILER ${IntelSycl_ROOT}/bin/clang++-cl.exe) |
| 108 | + set(IntelSycl_C_COMPILER ${IntelSycl_ROOT}/bin/clang-cl.exe) |
| 109 | + endif() |
| 110 | + elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") |
| 111 | + set(IntelSycl_SYCL_LIBRARY ${IntelSycl_ROOT}/lib/libsycl.so) |
| 112 | + set(IntelSycl_OPENCL_LIBRARY ${IntelSycl_ROOT}/lib/libOpenCL.so) |
| 113 | + # Set which compiler wrapper is used by default |
| 114 | + if(USING_ONEAPI_DPCPP) |
| 115 | + set(IntelSycl_CXX_COMPILER ${IntelSycl_ROOT}/bin/dpcpp) |
| 116 | + set(IntelSycl_C_COMPILER ${IntelSycl_ROOT}/bin/clang) |
| 117 | + else() |
| 118 | + set(IntelSycl_CXX_COMPILER ${IntelSycl_ROOT}/bin/clang++) |
| 119 | + set(IntelSycl_C_COMPILER ${IntelSycl_ROOT}/bin/clang) |
| 120 | + endif() |
| 121 | + endif() |
| 122 | + |
| 123 | +endif() |
| 124 | + |
| 125 | +# Check if a specific version of DPCPP is requested. |
| 126 | +if(IntelSycl_FIND_VERSION AND (DEFINED IntelSycl_VERSION)) |
| 127 | + string(COMPARE EQUAL ${IntelSycl_FIND_VERSION} ${IntelSycl_VERSION} VERSION_MATCH) |
| 128 | + if(VERSION_MATCH) |
| 129 | + set(IntelSycl_FOUND TRUE) |
| 130 | + endif() |
| 131 | +else() |
| 132 | + set(IntelSycl_FOUND TRUE) |
| 133 | +endif() |
| 134 | + |
| 135 | +find_package_handle_standard_args(IntelSycl DEFAULT_MSG |
| 136 | + IntelSycl_ROOT |
| 137 | + IntelSycl_FOUND |
| 138 | + IntelSycl_VERSION |
| 139 | + IntelSycl_INCLUDE_DIR |
| 140 | + IntelSycl_SYCL_INCLUDE_DIR |
| 141 | + IntelSycl_LIBRARY_DIR |
| 142 | + IntelSycl_SYCL_LIBRARY |
| 143 | + IntelSycl_OPENCL_LIBRARY |
| 144 | + IntelSycl_C_COMPILER |
| 145 | + IntelSycl_CXX_COMPILER |
| 146 | +) |
0 commit comments