forked from oneapi-src/oneMKL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
355 lines (318 loc) · 11.9 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
#===============================================================================
# Copyright 2020-2022 Intel Corporation
# Copyright (C) 2022 Heidelberg University, Engineering Mathematics and Computing Lab (EMCL) and Computing Centre (URZ)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions
# and limitations under the License.
#
#
# SPDX-License-Identifier: Apache-2.0
#===============================================================================
cmake_minimum_required (VERSION 3.13)
# Define build type
set(DEFAULT_BUILD_TYPE "Release")
if("${CMAKE_BUILD_TYPE}" STREQUAL "")
message(STATUS "CMAKE_BUILD_TYPE: None, set to ${DEFAULT_BUILD_TYPE} by default")
set(CMAKE_BUILD_TYPE ${DEFAULT_BUILD_TYPE} CACHE STRING
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel RelWithAssert" FORCE)
else()
message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
endif()
# Build options
option(BUILD_SHARED_LIBS "Build dynamic libraries" ON)
## Backends
option(ENABLE_MKLCPU_BACKEND "Enable the Intel oneMKL CPU backend for supported interfaces" ON)
option(ENABLE_MKLGPU_BACKEND "Enable the Intel oneMKL GPU backend for supported interfaces" ON)
if(ENABLE_MKLCPU_BACKEND)
option(ENABLE_MKLCPU_THREAD_TBB "Enable the use of Intel TBB with the oneMKL CPU backend" ON)
endif()
# blas
option(ENABLE_CUBLAS_BACKEND "Enable the cuBLAS backend for the BLAS interface" OFF)
option(ENABLE_ROCBLAS_BACKEND "Enable the rocBLAS backend for the BLAS interface" OFF)
option(ENABLE_NETLIB_BACKEND "Enable the Netlib backend for the BLAS interface" OFF)
option(ENABLE_PORTBLAS_BACKEND "Enable the portBLAS backend for the BLAS interface. Cannot be used with other BLAS backends." OFF)
# rand
option(ENABLE_CURAND_BACKEND "Enable the cuRAND backend for the RNG interface" OFF)
option(ENABLE_ROCRAND_BACKEND "Enable the rocRAND backend for the RNG interface" OFF)
# lapack
option(ENABLE_CUSOLVER_BACKEND "Enable the cuSOLVER backend for the LAPACK interface" OFF)
option(ENABLE_ROCSOLVER_BACKEND "Enable the rocSOLVER backend for the LAPACK interface" OFF)
# dft
option(ENABLE_CUFFT_BACKEND "Enable the cuFFT backend for the DFT interface" OFF)
option(ENABLE_ROCFFT_BACKEND "Enable the rocFFT backend for the DFT interface" OFF)
option(ENABLE_PORTFFT_BACKEND "Enable the portFFT DFT backend for the DFT interface. Cannot be used with other DFT backends." OFF)
set(ONEMKL_SYCL_IMPLEMENTATION "dpc++" CACHE STRING "Name of the SYCL compiler")
set(HIP_TARGETS "" CACHE STRING "Target HIP architectures")
## Testing
option(BUILD_FUNCTIONAL_TESTS "" ON)
## Examples
option(BUILD_EXAMPLES "" ON)
## Documentation
option(BUILD_DOC "" OFF)
## Supported domains
set(DOMAINS_LIST "")
if(ENABLE_MKLCPU_BACKEND
OR ENABLE_MKLGPU_BACKEND
OR ENABLE_CUBLAS_BACKEND
OR ENABLE_ROCBLAS_BACKEND
OR ENABLE_NETLIB_BACKEND
OR ENABLE_PORTBLAS_BACKEND)
list(APPEND DOMAINS_LIST "blas")
endif()
if(ENABLE_MKLCPU_BACKEND
OR ENABLE_MKLGPU_BACKEND
OR ENABLE_CUSOLVER_BACKEND
OR ENABLE_ROCSOLVER_BACKEND)
list(APPEND DOMAINS_LIST "lapack")
endif()
if(ENABLE_MKLCPU_BACKEND
OR ENABLE_MKLGPU_BACKEND
OR ENABLE_CURAND_BACKEND
OR ENABLE_ROCRAND_BACKEND)
list(APPEND DOMAINS_LIST "rng")
endif()
if(ENABLE_MKLGPU_BACKEND
OR ENABLE_MKLCPU_BACKEND
OR ENABLE_CUFFT_BACKEND
OR ENABLE_ROCFFT_BACKEND
OR ENABLE_PORTFFT_BACKEND)
list(APPEND DOMAINS_LIST "dft")
endif()
if(ENABLE_MKLCPU_BACKEND
OR ENABLE_MKLGPU_BACKEND)
list(APPEND DOMAINS_LIST "sparse_blas")
endif()
if(ENABLE_PORTBLAS_BACKEND
AND (ENABLE_MKLCPU_BACKEND
OR ENABLE_MKLGPU_BACKEND
OR ENABLE_CUBLAS_BACKEND
OR ENABLE_ROCBLAS_BACKEND
OR ENABLE_NETLIB_BACKEND))
message(FATAL_ERROR "ENABLE_PORTBLAS_BACKEND cannot be enabled at the same time as other BLAS backends.")
endif()
if (ENABLE_PORTFFT_BACKEND
AND (ENABLE_MKLCPU_BACKEND
OR ENABLE_MKLGPU_BACKEND
OR ENABLE_ROCFFT_BACKEND
OR ENABLE_CUFFT_BACKEND))
message(FATAL_ERROR "ENABLE_PORTFFT_BACKEND cannot be enabled at the same time as other DFT backends.")
endif()
# Define required CXX compilers before project
if(CMAKE_CXX_COMPILER OR NOT ONEMKL_SYCL_IMPLEMENTATION STREQUAL "dpc++")
if(WIN32)
string(REPLACE "\\" "/" CMAKE_CXX_COMPILER ${CMAKE_CXX_COMPILER})
endif()
else()
if(ENABLE_CUBLAS_BACKEND OR ENABLE_CURAND_BACKEND OR ENABLE_CUSOLVER_BACKEND OR ENABLE_CUFFT_BACKEND
OR ENABLE_ROCBLAS_BACKEND OR ENABLE_ROCRAND_BACKEND OR ENABLE_ROCSOLVER_BACKEND OR ENABLE_ROCFFT_BACKEND)
set(CMAKE_CXX_COMPILER "clang++")
elseif(ENABLE_MKLGPU_BACKEND)
if(UNIX)
set(CMAKE_CXX_COMPILER "icpx")
else()
set(CMAKE_CXX_COMPILER "icx")
endif()
else()
if(UNIX)
find_program(ICPX_ICX_PATH icpx)
else()
find_program(ICPX_ICX_PATH icx)
endif()
if(ICPX_ICX_PATH)
if(UNIX)
message(STATUS "CXX compiler: icpx was found in PATH, using icpx")
set(CMAKE_CXX_COMPILER "icpx")
else()
message(STATUS "CXX compiler: icx was found in PATH, using icx")
set(CMAKE_CXX_COMPILER "icx")
endif()
else()
if(WIN32)
message(STATUS "CXX compiler: icx was not found in PATH, using clang-cl instead")
set(CMAKE_CXX_COMPILER "clang-cl")
else()
message(STATUS "CXX compiler: icpx was not found in PATH, using clang++ instead")
set(CMAKE_CXX_COMPILER "clang++")
endif()
endif()
endif()
endif()
# Define required C compilers before project
if(CMAKE_C_COMPILER OR NOT ONEMKL_SYCL_IMPLEMENTATION STREQUAL "dpc++")
if(WIN32)
string(REPLACE "\\" "/" CMAKE_C_COMPILER ${CMAKE_C_COMPILER})
endif()
else()
find_program(ICX_PATH icx)
if(ICX_PATH)
message(STATUS "C compiler: icx was found in PATH, using icx")
set(CMAKE_C_COMPILER "icx")
else()
if(WIN32)
message(STATUS "C compiler: icx was not found in PATH, using clang-cl instead")
set(CMAKE_C_COMPILER "clang-cl")
else()
message(STATUS "C compiler: icx was not found in PATH, using clang instead")
set(CMAKE_C_COMPILER "clang")
endif()
endif()
endif()
project(oneMKL VERSION 0.2.0 LANGUAGES CXX)
# Override default CXX compile/link lines for Windows after project
if(WIN32 AND ONEMKL_SYCL_IMPLEMENTATION STREQUAL "dpc++")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-function -w")
foreach (flag_var
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
string(REPLACE "/MD" "" ${flag_var} "${${flag_var}}")
endforeach()
set(CMAKE_CXX_COMPILE_OBJECT "<CMAKE_CXX_COMPILER> -fsycl /nologo <DEFINES> <INCLUDES> /EHsc <FLAGS> /Fo<OBJECT> -c <SOURCE>")
set(CMAKE_CXX_CREATE_STATIC_LIBRARY "lib /nologo <OBJECTS> /out:<TARGET>")
if(CMAKE_VERSION VERSION_LESS "3.25.2")
set(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_CXX_COMPILER> -fsycl -fsycl-device-code-split=per_kernel /nologo <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
set(CMAKE_CXX_CREATE_SHARED_LIBRARY "<CMAKE_CXX_COMPILER> -fsycl -fsycl-device-code-split=per_kernel /nologo <OBJECTS> <LINK_LIBRARIES> /link /out:<TARGET> /implib:<TARGET_IMPLIB> /pdb:<TARGET_PDB> /dll /version:<TARGET_VERSION_MAJOR>.<TARGET_VERSION_MINOR>")
endif()
endif()
# Temporary disable sycl 2020 deprecations warnings for cuSOLVER and rocSOLVER
if(ONEMKL_SYCL_IMPLEMENTATION STREQUAL "dpc++" AND (ENABLE_ROCSOLVER_BACKEND))
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSYCL2020_DISABLE_DEPRECATION_WARNINGS")
endif()
# Target domains
if(NOT TARGET_DOMAINS OR TARGET_DOMAINS STREQUAL "None")
# Set to all by default
set(TARGET_DOMAINS ${DOMAINS_LIST})
else()
# Make sure the input was converted to list
string(REPLACE " " ";" TARGET_DOMAINS ${TARGET_DOMAINS})
set(NOT_FOUND 0)
foreach(domain ${TARGET_DOMAINS})
if(NOT ${domain} IN_LIST DOMAINS_LIST)
set(NOT_FOUND 1)
break()
endif()
endforeach()
if(NOT_FOUND)
message(STATUS "TARGET_DOMAINS contains unsupported options, reset to all")
set(TARGET_DOMAINS ${DOMAINS_LIST})
endif()
endif()
message(STATUS "TARGET_DOMAINS: ${TARGET_DOMAINS}")
# Include Intel oneMKL
if(ENABLE_MKLGPU_BACKEND OR ENABLE_MKLCPU_BACKEND)
set(MKL_ARCH intel64)
set(MKL_INTERFACE ilp64)
if(ENABLE_MKLCPU_THREAD_TBB)
set(MKL_THREADING tbb_thread)
else()
set(MKL_THREADING sequential)
endif()
if(BUILD_SHARED_LIBS AND NOT WIN32)
set(MKL_LINK dynamic)
else()
set(MKL_LINK static)
endif()
# Enable SYCL API
set(DPCPP_COMPILER ON)
set(SYCL_COMPILER ON)
# In case Intel oneMKL package doesn't include MKLConfig,
# use MKLConfig from the repo
find_package(MKL REQUIRED
HINTS ${MKL_ROOT}/lib/cmake
${MKL_ROOT}/lib/cmake/mkl
$ENV{MKLROOT}
${PROJECT_SOURCE_DIR}/cmake/mkl)
endif()
# Set output directories for the project
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
# Add CMake Finders
add_subdirectory(cmake)
# Include general cmake config files
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
# Add DPC++ options for Linux
if(WIN32)
add_library(ONEMKL::SYCL::SYCL INTERFACE IMPORTED)
else()
# Find necessary packages
if(ONEMKL_SYCL_IMPLEMENTATION)
string( TOLOWER "${ONEMKL_SYCL_IMPLEMENTATION}" ONEMKL_SYCL_IMPLEMENTATION)
if (ONEMKL_SYCL_IMPLEMENTATION STREQUAL "hipsycl")
message(STATUS "Looking for hipSYCL")
find_package(hipSYCL CONFIG REQUIRED)
set(USE_ADD_SYCL_TO_TARGET_INTEGRATION true)
set (CMAKE_CXX_STANDARD 17)
add_library(ONEMKL::SYCL::SYCL INTERFACE IMPORTED)
elseif(ONEMKL_SYCL_IMPLEMENTATION STREQUAL "dpc++")
message(STATUS "Looking for dpc++")
set(USE_ADD_SYCL_TO_TARGET_INTEGRATION false)
find_package(Compiler REQUIRED)
else()
message(FATAL_ERROR "SYCL implementation ${ONEMKL_SYCL_IMPLEMENTATION} is not known")
endif()
else()
message(STATUS "Looking for dpc++")
set(USE_ADD_SYCL_TO_TARGET_INTEGRATION false)
find_package(Compiler REQUIRED)
endif()
endif()
if(DEFINED REF_BLAS_ROOT)
find_file(REF_BLAS_LIBNAME NAMES blas.dll libblas.so HINTS ${REF_BLAS_ROOT} PATH_SUFFIXES lib lib64)
find_file(REF_CBLAS_LIBNAME NAMES cblas.dll libcblas.so HINTS ${REF_BLAS_ROOT} PATH_SUFFIXES lib lib64)
endif()
# Add source directory and output to bin/
add_subdirectory(src bin)
# Functional Tests
if(BUILD_FUNCTIONAL_TESTS OR BUILD_EXAMPLES)
enable_testing()
endif()
if(BUILD_FUNCTIONAL_TESTS)
add_subdirectory(tests)
endif()
# Examples
if (BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
if(BUILD_DOC)
add_subdirectory(docs)
endif()
install(DIRECTORY include/
DESTINATION include
COMPONENT Devel
)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/oneMKLConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
export(EXPORT oneMKLTargets
FILE "${CMAKE_CURRENT_BINARY_DIR}/oneMKLTargets.cmake"
NAMESPACE ONEMKL::
)
configure_file("${PROJECT_SOURCE_DIR}/cmake/oneMKLConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/oneMKLConfig.cmake"
COPYONLY
)
set(config_package_location "lib/cmake/${PROJECT_NAME}")
install(EXPORT oneMKLTargets
FILE oneMKLTargets.cmake
NAMESPACE MKL::
DESTINATION ${config_package_location}
)
install(
FILES
"${PROJECT_SOURCE_DIR}/cmake/oneMKLConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/oneMKLConfigVersion.cmake"
DESTINATION ${config_package_location}
COMPONENT Devel
)