forked from alpaka-group/alpaka
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alpakaConfig.cmake
663 lines (581 loc) · 29.5 KB
/
alpakaConfig.cmake
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
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
#
# Copyright 2014-2016 Benjamin Worpitz, Erik Zenker
#
# This file is part of alpaka.
#
# alpaka is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# alpaka is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with alpaka.
# If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
# Required cmake version.
################################################################################
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12)
################################################################################
# alpaka.
################################################################################
# Return values.
UNSET(alpaka_FOUND)
UNSET(alpaka_VERSION)
UNSET(alpaka_COMPILE_OPTIONS)
UNSET(alpaka_COMPILE_DEFINITIONS)
UNSET(alpaka_DEFINITIONS)
UNSET(alpaka_INCLUDE_DIR)
UNSET(alpaka_INCLUDE_DIRS)
UNSET(alpaka_LIBRARY)
UNSET(alpaka_LIBRARIES)
# Internal usage.
UNSET(_ALPAKA_FOUND)
UNSET(_ALPAKA_COMPILE_OPTIONS_PUBLIC)
UNSET(_ALPAKA_COMPILE_DEFINITIONS_PUBLIC)
UNSET(_ALPAKA_INCLUDE_DIRECTORY)
UNSET(_ALPAKA_INCLUDE_DIRECTORIES_PUBLIC)
UNSET(_ALPAKA_LINK_LIBRARIES_PUBLIC)
UNSET(_ALPAKA_LINK_FLAGS_PUBLIC)
UNSET(_ALPAKA_COMMON_FILE)
UNSET(_ALPAKA_ADD_EXECUTABLE_FILE)
UNSET(_ALPAKA_ADD_LIBRRAY_FILE)
UNSET(_ALPAKA_FILES_HEADER)
UNSET(_ALPAKA_FILES_SOURCE)
UNSET(_ALPAKA_FILES_OTHER)
UNSET(_ALPAKA_VERSION_DEFINE)
UNSET(_ALPAKA_VER_MAJOR)
UNSET(_ALPAKA_VER_MINOR)
UNSET(_ALPAKA_VER_PATCH)
#-------------------------------------------------------------------------------
# Common.
#-------------------------------------------------------------------------------
# Directory of this file.
SET(_ALPAKA_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR})
# Normalize the path (e.g. remove ../)
GET_FILENAME_COMPONENT(_ALPAKA_ROOT_DIR "${_ALPAKA_ROOT_DIR}" ABSOLUTE)
# Add common functions.
SET(_ALPAKA_COMMON_FILE "${_ALPAKA_ROOT_DIR}/cmake/common.cmake")
INCLUDE("${_ALPAKA_COMMON_FILE}")
# Add ALPAKA_ADD_EXECUTABLE function.
SET(_ALPAKA_ADD_EXECUTABLE_FILE "${_ALPAKA_ROOT_DIR}/cmake/addExecutable.cmake")
INCLUDE("${_ALPAKA_ADD_EXECUTABLE_FILE}")
# Add ALPAKA_ADD_LIBRARY function.
SET(_ALPAKA_ADD_LIBRARY_FILE "${_ALPAKA_ROOT_DIR}/cmake/addLibrary.cmake")
INCLUDE("${_ALPAKA_ADD_LIBRARY_FILE}")
# Set found to true initially and set it to false if a required dependency is missing.
SET(_ALPAKA_FOUND TRUE)
# Add module search path
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${_ALPAKA_ROOT_DIR}/cmake/modules/")
#-------------------------------------------------------------------------------
# Options.
#-------------------------------------------------------------------------------
OPTION(ALPAKA_ACC_GPU_CUDA_ONLY_MODE "Only back-ends using CUDA can be enabled in this mode (This allows to mix alpaka code with native CUDA code)." OFF)
OPTION(ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLE "Enable the serial CPU back-end" ON)
OPTION(ALPAKA_ACC_CPU_B_SEQ_T_THREADS_ENABLE "Enable the threads CPU block thread back-end" ON)
OPTION(ALPAKA_ACC_CPU_B_SEQ_T_FIBERS_ENABLE "Enable the fibers CPU block thread back-end" ON)
OPTION(ALPAKA_ACC_CPU_B_TBB_T_SEQ_ENABLE "Enable the TBB CPU grid block back-end" ON)
OPTION(ALPAKA_ACC_CPU_B_OMP2_T_SEQ_ENABLE "Enable the OpenMP 2.0 CPU grid block back-end" ON)
OPTION(ALPAKA_ACC_CPU_B_SEQ_T_OMP2_ENABLE "Enable the OpenMP 2.0 CPU block thread back-end" ON)
OPTION(ALPAKA_ACC_CPU_BT_OMP4_ENABLE "Enable the OpenMP 4.0 CPU block and block thread back-end" OFF)
OPTION(ALPAKA_ACC_GPU_CUDA_ENABLE "Enable the CUDA GPU back-end" ON)
IF(ALPAKA_ACC_GPU_CUDA_ONLY_MODE AND
(ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLE OR
ALPAKA_ACC_CPU_B_SEQ_T_THREADS_ENABLE OR
ALPAKA_ACC_CPU_B_SEQ_T_FIBERS_ENABLE OR
ALPAKA_ACC_CPU_B_TBB_T_SEQ_ENABLE OR
ALPAKA_ACC_CPU_B_OMP2_T_SEQ_ENABLE OR
ALPAKA_ACC_CPU_B_SEQ_T_OMP2_ENABLE OR
ALPAKA_ACC_CPU_BT_OMP4_ENABLE))
MESSAGE(WARNING "If ALPAKA_ACC_GPU_CUDA_ONLY_MODE is enabled, only back-ends using CUDA can be enabled! This allows to mix alpaka code with native CUDA code. However, this prevents any non-CUDA back-ends from being enabled.")
ENDIF()
# Drop-down combo box in cmake-gui.
SET(ALPAKA_DEBUG "0" CACHE STRING "Debug level")
SET_PROPERTY(CACHE ALPAKA_DEBUG PROPERTY STRINGS "0;1;2")
#-------------------------------------------------------------------------------
# Debug output of common variables.
#-------------------------------------------------------------------------------
IF(${ALPAKA_DEBUG} GREATER 1)
MESSAGE(STATUS "_ALPAKA_ROOT_DIR : ${_ALPAKA_ROOT_DIR}")
MESSAGE(STATUS "_ALPAKA_COMMON_FILE : ${_ALPAKA_COMMON_FILE}")
MESSAGE(STATUS "_ALPAKA_ADD_EXECUTABLE_FILE : ${_ALPAKA_ADD_EXECUTABLE_FILE}")
MESSAGE(STATUS "_ALPAKA_ADD_LIBRARY_FILE : ${_ALPAKA_ADD_LIBRARY_FILE}")
MESSAGE(STATUS "CMAKE_BUILD_TYPE : ${CMAKE_BUILD_TYPE}")
ENDIF()
#-------------------------------------------------------------------------------
# Find Boost.
#-------------------------------------------------------------------------------
SET(_ALPAKA_BOOST_MIN_VER "1.59.0") # minimum version for basic features
IF(${ALPAKA_DEBUG} GREATER 1)
SET(Boost_DEBUG ON)
SET(Boost_DETAILED_FAILURE_MSG ON)
ENDIF()
IF(ALPAKA_ACC_CPU_B_SEQ_T_FIBERS_ENABLE)
FIND_PACKAGE(Boost ${_ALPAKA_BOOST_MIN_VER} QUIET COMPONENTS fiber context system thread atomic chrono date_time)
IF(NOT Boost_FIBER_FOUND)
MESSAGE(WARNING "Optional alpaka dependency Boost fiber could not be found! Fibers back-end disabled!")
SET(ALPAKA_ACC_CPU_B_SEQ_T_FIBERS_ENABLE OFF CACHE BOOL "Enable the Fibers CPU back-end" FORCE)
FIND_PACKAGE(Boost ${_ALPAKA_BOOST_MIN_VER} QUIET)
ENDIF()
ELSE()
FIND_PACKAGE(Boost ${_ALPAKA_BOOST_MIN_VER} QUIET)
ENDIF()
IF(${ALPAKA_DEBUG} GREATER 1)
MESSAGE(STATUS "Boost in:")
MESSAGE(STATUS "BOOST_ROOT : ${BOOST_ROOT}")
MESSAGE(STATUS "BOOSTROOT : ${BOOSTROOT}")
MESSAGE(STATUS "BOOST_INCLUDEDIR: ${BOOST_INCLUDEDIR}")
MESSAGE(STATUS "BOOST_LIBRARYDIR: ${BOOST_LIBRARYDIR}")
MESSAGE(STATUS "Boost_NO_SYSTEM_PATHS: ${Boost_NO_SYSTEM_PATHS}")
MESSAGE(STATUS "Boost_ADDITIONAL_VERSIONS: ${Boost_ADDITIONAL_VERSIONS}")
MESSAGE(STATUS "Boost_USE_MULTITHREADED: ${Boost_USE_MULTITHREADED}")
MESSAGE(STATUS "Boost_USE_STATIC_LIBS: ${Boost_USE_STATIC_LIBS}")
MESSAGE(STATUS "Boost_USE_STATIC_RUNTIME: ${Boost_USE_STATIC_RUNTIME}")
MESSAGE(STATUS "Boost_USE_DEBUG_RUNTIME: ${Boost_USE_DEBUG_RUNTIME}")
MESSAGE(STATUS "Boost_USE_DEBUG_PYTHON: ${Boost_USE_DEBUG_PYTHON}")
MESSAGE(STATUS "Boost_USE_STLPORT: ${Boost_USE_STLPORT}")
MESSAGE(STATUS "Boost_USE_STLPORT_DEPRECATED_NATIVE_IOSTREAMS: ${Boost_USE_STLPORT_DEPRECATED_NATIVE_IOSTREAMS}")
MESSAGE(STATUS "Boost_COMPILER: ${Boost_COMPILER}")
MESSAGE(STATUS "Boost_THREADAPI: ${Boost_THREADAPI}")
MESSAGE(STATUS "Boost_NAMESPACE: ${Boost_NAMESPACE}")
MESSAGE(STATUS "Boost_DEBUG: ${Boost_DEBUG}")
MESSAGE(STATUS "Boost_DETAILED_FAILURE_MSG: ${Boost_DETAILED_FAILURE_MSG}")
MESSAGE(STATUS "Boost_REALPATH: ${Boost_REALPATH}")
MESSAGE(STATUS "Boost_NO_BOOST_CMAKE: ${Boost_NO_BOOST_CMAKE}")
MESSAGE(STATUS "Boost out:")
MESSAGE(STATUS "Boost_FOUND: ${Boost_FOUND}")
MESSAGE(STATUS "Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
MESSAGE(STATUS "Boost_LIBRARY_DIRS: ${Boost_LIBRARY_DIRS}")
MESSAGE(STATUS "Boost_LIBRARIES: ${Boost_LIBRARIES}")
MESSAGE(STATUS "Boost_FIBER_FOUND: ${Boost_FIBER_FOUND}")
MESSAGE(STATUS "Boost_FIBER_LIBRARY: ${Boost_FIBER_LIBRARY}")
MESSAGE(STATUS "Boost_CONTEXT_FOUND: ${Boost_CONTEXT_FOUND}")
MESSAGE(STATUS "Boost_CONTEXT_LIBRARY: ${Boost_CONTEXT_LIBRARY}")
MESSAGE(STATUS "Boost_SYSTEM_FOUND: ${Boost_SYSTEM_FOUND}")
MESSAGE(STATUS "Boost_SYSTEM_LIBRARY: ${Boost_SYSTEM_LIBRARY}")
MESSAGE(STATUS "Boost_THREAD_FOUND: ${Boost_THREAD_FOUND}")
MESSAGE(STATUS "Boost_THREAD_LIBRARY: ${Boost_THREAD_LIBRARY}")
MESSAGE(STATUS "Boost_ATOMIC_FOUND: ${Boost_ATOMIC_FOUND}")
MESSAGE(STATUS "Boost_ATOMIC_LIBRARY: ${Boost_ATOMIC_LIBRARY}")
MESSAGE(STATUS "Boost_CHRONO_FOUND: ${Boost_CHRONO_FOUND}")
MESSAGE(STATUS "Boost_CHRONO_LIBRARY: ${Boost_CHRONO_LIBRARY}")
MESSAGE(STATUS "Boost_DATE_TIME_FOUND: ${Boost_DATE_TIME_FOUND}")
MESSAGE(STATUS "Boost_DATE_TIME_LIBRARY: ${Boost_DATE_TIME_LIBRARY}")
MESSAGE(STATUS "Boost_VERSION: ${Boost_VERSION}")
MESSAGE(STATUS "Boost_LIB_VERSION: ${Boost_LIB_VERSION}")
MESSAGE(STATUS "Boost_MAJOR_VERSION: ${Boost_MAJOR_VERSION}")
MESSAGE(STATUS "Boost_MINOR_VERSION: ${Boost_MINOR_VERSION}")
MESSAGE(STATUS "Boost_SUBMINOR_VERSION: ${Boost_SUBMINOR_VERSION}")
MESSAGE(STATUS "Boost_LIB_DIAGNOSTIC_DEFINITIONS: ${Boost_LIB_DIAGNOSTIC_DEFINITIONS}")
MESSAGE(STATUS "Boost_LIBRARIES: ${Boost_LIBRARIES}")
MESSAGE(STATUS "Boost cached:")
MESSAGE(STATUS "Boost_INCLUDE_DIR: ${Boost_INCLUDE_DIR}")
MESSAGE(STATUS "Boost_LIBRARY_DIR: ${Boost_LIBRARY_DIR}")
ENDIF()
IF(NOT Boost_FOUND)
MESSAGE(WARNING "Required alpaka dependency Boost (>=${_ALPAKA_BOOST_MIN_VER}) could not be found!")
SET(_ALPAKA_FOUND FALSE)
ELSE()
LIST(APPEND _ALPAKA_INCLUDE_DIRECTORIES_PUBLIC ${Boost_INCLUDE_DIRS})
LIST(APPEND _ALPAKA_LINK_LIBRARIES_PUBLIC ${Boost_LIBRARIES})
ENDIF()
#-------------------------------------------------------------------------------
# Find TBB.
#-------------------------------------------------------------------------------
IF(ALPAKA_ACC_CPU_B_TBB_T_SEQ_ENABLE)
FIND_PACKAGE(TBB 2.2)
IF(NOT TBB_FOUND)
MESSAGE(WARNING "Optional alpaka dependency TBB could not be found! TBB grid block back-end disabled!")
SET(ALPAKA_ACC_CPU_B_TBB_T_SEQ_ENABLE OFF CACHE BOOL "Enable the TBB grid block back-end" FORCE)
ELSE()
LIST(APPEND _ALPAKA_LINK_LIBRARIES_PUBLIC ${TBB_LIBRARIES})
LIST(APPEND _ALPAKA_INCLUDE_DIRECTORIES_PUBLIC ${TBB_INCLUDE_DIRS})
LIST(APPEND _ALPAKA_COMPILE_OPTIONS_PUBLIC ${TBB_DEFINITIONS})
ENDIF()
ENDIF()
#-------------------------------------------------------------------------------
# Find OpenMP.
#-------------------------------------------------------------------------------
IF(ALPAKA_ACC_CPU_B_OMP2_T_SEQ_ENABLE OR ALPAKA_ACC_CPU_B_SEQ_T_OMP2_ENABLE OR ALPAKA_ACC_CPU_BT_OMP4_ENABLE)
FIND_PACKAGE(OpenMP)
# Manually find OpenMP for the clang compiler if it was not already found.
# Even CMake 3.5 is unable to find libiomp and provide the correct OpenMP flags.
IF(NOT OPENMP_FOUND)
IF(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
FIND_PATH(_ALPAKA_LIBIOMP_INCLUDE_DIR NAMES "omp.h" PATH_SUFFIXES "include" "libiomp" "include/libiomp")
IF(_ALPAKA_LIBIOMP_INCLUDE_DIR)
SET(OPENMP_FOUND TRUE)
SET(OpenMP_CXX_FLAGS "-fopenmp=libiomp5")
SET(OpenMP_C_FLAGS "-fopenmp=libiomp5")
LIST(APPEND _ALPAKA_INCLUDE_DIRECTORIES_PUBLIC "${_ALPAKA_LIBIOMP_INCLUDE_DIR}")
ENDIF()
ENDIF()
ENDIF()
IF(NOT OPENMP_FOUND)
MESSAGE(WARNING "Optional alpaka dependency OpenMP could not be found! OpenMP back-ends disabled!")
SET(ALPAKA_ACC_CPU_B_OMP2_T_SEQ_ENABLE OFF CACHE BOOL "Enable the OpenMP 2.0 CPU grid block back-end" FORCE)
SET(ALPAKA_ACC_CPU_B_SEQ_T_OMP2_ENABLE OFF CACHE BOOL "Enable the OpenMP 2.0 CPU block thread back-end" FORCE)
SET(ALPAKA_ACC_CPU_BT_OMP4_ENABLE OFF CACHE BOOL "Enable the OpenMP 4.0 CPU block and thread back-end" FORCE)
ELSE()
LIST(APPEND _ALPAKA_COMPILE_OPTIONS_PUBLIC ${OpenMP_CXX_FLAGS})
IF(NOT MSVC)
LIST(APPEND _ALPAKA_LINK_FLAGS_PUBLIC ${OpenMP_CXX_FLAGS})
ENDIF()
# CUDA requires some special handling
IF(ALPAKA_ACC_GPU_CUDA_ENABLE)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
ENDIF()
ENDIF()
ENDIF()
#-------------------------------------------------------------------------------
# Find CUDA.
#-------------------------------------------------------------------------------
IF(ALPAKA_ACC_GPU_CUDA_ENABLE)
IF(NOT DEFINED ALPAKA_CUDA_VERSION)
SET(ALPAKA_CUDA_VERSION 7.0)
ENDIF()
IF(ALPAKA_CUDA_VERSION VERSION_LESS 7.0)
MESSAGE(WARNING "CUDA Toolkit < 7.0 is not supported!")
SET(_ALPAKA_FOUND FALSE)
ELSE()
FIND_PACKAGE(CUDA "${ALPAKA_CUDA_VERSION}")
IF(NOT CUDA_FOUND)
MESSAGE(WARNING "Optional alpaka dependency CUDA could not be found! CUDA back-end disabled!")
SET(ALPAKA_ACC_GPU_CUDA_ENABLE OFF CACHE BOOL "Enable the CUDA GPU back-end" FORCE)
ELSE()
SET(ALPAKA_CUDA_VERSION "${CUDA_VERSION}")
SET(ALPAKA_CUDA_ARCH sm_20 CACHE STRING "GPU architecture")
STRING(COMPARE EQUAL "${ALPAKA_CUDA_ARCH}" "sm_10" IS_CUDA_ARCH_UNSUPPORTED)
STRING(COMPARE EQUAL "${ALPAKA_CUDA_ARCH}" "sm_11" IS_CUDA_ARCH_UNSUPPORTED)
STRING(COMPARE EQUAL "${ALPAKA_CUDA_ARCH}" "sm_12" IS_CUDA_ARCH_UNSUPPORTED)
STRING(COMPARE EQUAL "${ALPAKA_CUDA_ARCH}" "sm_13" IS_CUDA_ARCH_UNSUPPORTED)
IF(IS_CUDA_ARCH_UNSUPPORTED)
MESSAGE(WARNING "Unsupported CUDA architecture ${ALPAKA_CUDA_ARCH} specified. SM 2.0 or higher is required for CUDA 7.0. Using sm_20 instead.")
SET(ALPAKA_CUDA_ARCH sm_20 CACHE STRING "Set GPU architecture" FORCE)
ENDIF(IS_CUDA_ARCH_UNSUPPORTED)
SET(ALPAKA_CUDA_COMPILER "nvcc" CACHE STRING "CUDA compiler")
SET_PROPERTY(CACHE ALPAKA_CUDA_COMPILER PROPERTY STRINGS "nvcc;clang")
OPTION(ALPAKA_CUDA_FAST_MATH "Enable fast-math" ON)
OPTION(ALPAKA_CUDA_SHOW_REGISTER "Show kernel registers and create PTX" OFF)
OPTION(ALPAKA_CUDA_KEEP_FILES "Keep all intermediate files that are generated during internal compilation steps (folder: nvcc_tmp)" OFF)
IF(ALPAKA_CUDA_COMPILER MATCHES "clang")
LIST(APPEND _ALPAKA_COMPILE_OPTIONS_PUBLIC "--cuda-gpu-arch=${ALPAKA_CUDA_ARCH}")
# This flag silences the warning produced by the Dummy.cpp files:
# clang: warning: argument unused during compilation: '--cuda-gpu-arch=sm_XX'
# This seems to be a false positive as all flags are 'unused' for an empty file.
LIST(APPEND _ALPAKA_COMPILE_OPTIONS_PUBLIC "-Qunused-arguments")
# Silences warnings that are produced by boost because clang is not correctly identified.
LIST(APPEND _ALPAKA_COMPILE_OPTIONS_PUBLIC "-Wno-unused-local-typedef")
IF(ALPAKA_CUDA_FAST_MATH)
# -ffp-contract=fast enables the usage of FMA
LIST(APPEND _ALPAKA_COMPILE_OPTIONS_PUBLIC "-ffast-math" "-ffp-contract=fast")
ENDIF()
IF(ALPAKA_CUDA_SHOW_REGISTER)
LIST(APPEND _ALPAKA_COMPILE_OPTIONS_PUBLIC "-Xcuda-ptxas=-v")
ENDIF()
IF(ALPAKA_CUDA_KEEP_FILES)
LIST(APPEND _ALPAKA_COMPILE_OPTIONS_PUBLIC "-save-temps")
ENDIF()
ELSE()
IF(${ALPAKA_DEBUG} GREATER 1)
SET(CUDA_VERBOSE_BUILD ON)
ENDIF()
SET(CUDA_PROPAGATE_HOST_FLAGS ON)
IF(CUDA_VERSION VERSION_EQUAL 8.0)
LIST(APPEND CUDA_NVCC_FLAGS "-Wno-deprecated-gpu-targets")
ENDIF()
IF(NOT CUDA_VERSION VERSION_LESS 7.5)
LIST(APPEND CUDA_NVCC_FLAGS "--expt-extended-lambda")
ENDIF()
LIST(APPEND CUDA_NVCC_FLAGS "-arch=${ALPAKA_CUDA_ARCH}")
IF(NOT MSVC)
LIST(APPEND CUDA_NVCC_FLAGS "-std=c++11")
SET(CUDA_HOST_COMPILER "${CMAKE_CXX_COMPILER}")
ENDIF()
if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
LIST(APPEND CUDA_NVCC_FLAGS "-g" "-G")
ENDIF()
IF(ALPAKA_CUDA_FAST_MATH)
LIST(APPEND CUDA_NVCC_FLAGS "--use_fast_math")
ENDIF()
OPTION(ALPAKA_CUDA_FTZ "Set flush to zero for GPU" OFF)
IF(ALPAKA_CUDA_FTZ)
LIST(APPEND CUDA_NVCC_FLAGS "--ftz=true")
ELSE()
LIST(APPEND CUDA_NVCC_FLAGS "--ftz=false")
ENDIF()
IF(ALPAKA_CUDA_SHOW_REGISTER)
LIST(APPEND CUDA_NVCC_FLAGS "-Xptxas=-v")
ENDIF()
IF(ALPAKA_CUDA_KEEP_FILES)
MAKE_DIRECTORY("${PROJECT_BINARY_DIR}/nvcc_tmp")
LIST(APPEND CUDA_NVCC_FLAGS "--keep" "--keep-dir" "${PROJECT_BINARY_DIR}/nvcc_tmp")
ENDIF()
OPTION(ALPAKA_CUDA_SHOW_CODELINES "Show kernel lines in cuda-gdb and cuda-memcheck" OFF)
IF(ALPAKA_CUDA_SHOW_CODELINES)
LIST(APPEND CUDA_NVCC_FLAGS "--source-in-ptx" "-lineinfo")
IF(NOT MSVC)
LIST(APPEND CUDA_NVCC_FLAGS "-Xcompiler" "-rdynamic")
ENDIF()
SET(ALPAKA_CUDA_KEEP_FILES ON CACHE BOOL "activate keep files" FORCE)
ENDIF()
ENDIF()
LIST(APPEND _ALPAKA_LINK_LIBRARIES_PUBLIC "general;${CUDA_CUDART_LIBRARY}")
LIST(APPEND _ALPAKA_INCLUDE_DIRECTORIES_PUBLIC ${CUDA_INCLUDE_DIRS})
ENDIF()
ENDIF()
ENDIF()
#-------------------------------------------------------------------------------
# Compiler settings.
#-------------------------------------------------------------------------------
IF(MSVC)
# Empty append to define it if it does not already exist.
LIST(APPEND _ALPAKA_COMPILE_OPTIONS_PUBLIC)
ELSE()
# Select C++ standard version.
LIST(APPEND _ALPAKA_COMPILE_OPTIONS_PUBLIC "-std=c++11")
# Add linker options.
# lipthread:
LIST(APPEND _ALPAKA_LINK_LIBRARIES_PUBLIC "general;pthread")
# librt: undefined reference to `clock_gettime'
LIST(APPEND _ALPAKA_LINK_LIBRARIES_PUBLIC "general;rt")
# GNU
IF(CMAKE_COMPILER_IS_GNUCXX)
LIST(APPEND _ALPAKA_COMPILE_OPTIONS_PUBLIC "-ftemplate-depth-512")
# Clang or AppleClang
ELSEIF(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
LIST(APPEND _ALPAKA_COMPILE_OPTIONS_PUBLIC "-ftemplate-depth=512")
ENDIF()
ENDIF()
#-------------------------------------------------------------------------------
# alpaka.
#-------------------------------------------------------------------------------
IF(ALPAKA_ACC_GPU_CUDA_ONLY_MODE)
LIST(APPEND _ALPAKA_COMPILE_DEFINITIONS_PUBLIC "ALPAKA_ACC_GPU_CUDA_ONLY_MODE")
MESSAGE(STATUS ALPAKA_ACC_GPU_CUDA_ONLY_MODE)
ENDIF()
IF(ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLE)
LIST(APPEND _ALPAKA_COMPILE_DEFINITIONS_PUBLIC "ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED")
MESSAGE(STATUS ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED)
ENDIF()
IF(ALPAKA_ACC_CPU_B_SEQ_T_THREADS_ENABLE)
LIST(APPEND _ALPAKA_COMPILE_DEFINITIONS_PUBLIC "ALPAKA_ACC_CPU_B_SEQ_T_THREADS_ENABLED")
MESSAGE(STATUS ALPAKA_ACC_CPU_B_SEQ_T_THREADS_ENABLED)
ENDIF()
IF(ALPAKA_ACC_CPU_B_SEQ_T_FIBERS_ENABLE)
LIST(APPEND _ALPAKA_COMPILE_DEFINITIONS_PUBLIC "ALPAKA_ACC_CPU_B_SEQ_T_FIBERS_ENABLED")
MESSAGE(STATUS ALPAKA_ACC_CPU_B_SEQ_T_FIBERS_ENABLED)
ENDIF()
IF(ALPAKA_ACC_CPU_B_TBB_T_SEQ_ENABLE)
LIST(APPEND _ALPAKA_COMPILE_DEFINITIONS_PUBLIC "ALPAKA_ACC_CPU_B_TBB_T_SEQ_ENABLED")
MESSAGE(STATUS ALPAKA_ACC_CPU_B_TBB_T_SEQ_ENABLED)
ENDIF()
IF(ALPAKA_ACC_CPU_B_OMP2_T_SEQ_ENABLE)
LIST(APPEND _ALPAKA_COMPILE_DEFINITIONS_PUBLIC "ALPAKA_ACC_CPU_B_OMP2_T_SEQ_ENABLED")
MESSAGE(STATUS ALPAKA_ACC_CPU_B_OMP2_T_SEQ_ENABLED)
ENDIF()
IF(ALPAKA_ACC_CPU_B_SEQ_T_OMP2_ENABLE)
LIST(APPEND _ALPAKA_COMPILE_DEFINITIONS_PUBLIC "ALPAKA_ACC_CPU_B_SEQ_T_OMP2_ENABLED")
MESSAGE(STATUS ALPAKA_ACC_CPU_B_SEQ_T_OMP2_ENABLED)
ENDIF()
IF(ALPAKA_ACC_CPU_BT_OMP4_ENABLE)
LIST(APPEND _ALPAKA_COMPILE_DEFINITIONS_PUBLIC "ALPAKA_ACC_CPU_BT_OMP4_ENABLED")
MESSAGE(STATUS ALPAKA_ACC_CPU_BT_OMP4_ENABLED)
ENDIF()
IF(ALPAKA_ACC_GPU_CUDA_ENABLE)
LIST(APPEND _ALPAKA_COMPILE_DEFINITIONS_PUBLIC "ALPAKA_ACC_GPU_CUDA_ENABLED")
MESSAGE(STATUS ALPAKA_ACC_GPU_CUDA_ENABLED)
ENDIF()
LIST(APPEND _ALPAKA_COMPILE_DEFINITIONS_PUBLIC "ALPAKA_DEBUG=${ALPAKA_DEBUG}")
IF(ALPAKA_CI)
LIST(APPEND _ALPAKA_COMPILE_DEFINITIONS_PUBLIC "ALPAKA_CI")
ENDIF()
SET(_ALPAKA_INCLUDE_DIRECTORY "${_ALPAKA_ROOT_DIR}/include")
LIST(APPEND _ALPAKA_INCLUDE_DIRECTORIES_PUBLIC "${_ALPAKA_INCLUDE_DIRECTORY}")
SET(_ALPAKA_SUFFIXED_INCLUDE_DIR "${_ALPAKA_INCLUDE_DIRECTORY}/alpaka")
SET(_ALPAKA_LINK_LIBRARY)
LIST(APPEND _ALPAKA_LINK_LIBRARIES_PUBLIC "${_ALPAKA_LINK_LIBRARY}")
# Add all the source and include files in all recursive subdirectories and group them accordingly.
append_recursive_files_add_to_src_group("${_ALPAKA_SUFFIXED_INCLUDE_DIR}" "${_ALPAKA_SUFFIXED_INCLUDE_DIR}" "hpp" _ALPAKA_FILES_HEADER)
append_recursive_files_add_to_src_group("${_ALPAKA_SUFFIXED_INCLUDE_DIR}" "${_ALPAKA_SUFFIXED_INCLUDE_DIR}" "cpp" _ALPAKA_FILES_SOURCE)
append_recursive_files_add_to_src_group("${_ALPAKA_ROOT_DIR}/travis" "${_ALPAKA_ROOT_DIR}" "sh" _ALPAKA_FILES_TRAVIS)
SET_SOURCE_FILES_PROPERTIES(${_ALPAKA_FILES_TRAVIS} PROPERTIES HEADER_FILE_ONLY TRUE)
append_recursive_files_add_to_src_group("${_ALPAKA_ROOT_DIR}/cmake" "${_ALPAKA_ROOT_DIR}" "cmake" _ALPAKA_FILES_CMAKE)
LIST(APPEND _ALPAKA_FILES_CMAKE "${_ALPAKA_ROOT_DIR}/alpakaConfig.cmake" "${_ALPAKA_ROOT_DIR}/Findalpaka.cmake" "${_ALPAKA_ROOT_DIR}/CMakeLists.txt" "${_ALPAKA_ROOT_DIR}/cmake/dev.cmake" "${_ALPAKA_ROOT_DIR}/cmake/common.cmake" "${_ALPAKA_ROOT_DIR}/cmake/addExecutable.cmake" "${_ALPAKA_ADD_LIBRRAY_FILE}")
SET_SOURCE_FILES_PROPERTIES(${_ALPAKA_FILES_CMAKE} PROPERTIES HEADER_FILE_ONLY TRUE)
append_recursive_files_add_to_src_group("${_ALPAKA_ROOT_DIR}/doc/markdown" "${_ALPAKA_ROOT_DIR}" "md" _ALPAKA_FILES_DOC)
SET_SOURCE_FILES_PROPERTIES(${_ALPAKA_FILES_DOC} PROPERTIES HEADER_FILE_ONLY TRUE)
SET(_ALPAKA_FILES_OTHER "${_ALPAKA_ROOT_DIR}/.gitignore" "${_ALPAKA_ROOT_DIR}/.travis.yml" "${_ALPAKA_ROOT_DIR}/appveyor.yml" "${_ALPAKA_ROOT_DIR}/COPYING" "${_ALPAKA_ROOT_DIR}/COPYING.LESSER" "${_ALPAKA_ROOT_DIR}/README.md")
SET_SOURCE_FILES_PROPERTIES(${_ALPAKA_FILES_OTHER} PROPERTIES HEADER_FILE_ONLY TRUE)
#-------------------------------------------------------------------------------
# Target.
#-------------------------------------------------------------------------------
IF(NOT TARGET "alpaka")
ADD_LIBRARY(
"alpaka"
${_ALPAKA_FILES_HEADER} ${_ALPAKA_FILES_SOURCE} ${_ALPAKA_FILES_TRAVIS} ${_ALPAKA_FILES_CMAKE} ${_ALPAKA_FILES_DOC} ${_ALPAKA_FILES_OTHER})
# Compile options.
IF(${ALPAKA_DEBUG} GREATER 1)
MESSAGE(STATUS "_ALPAKA_COMPILE_OPTIONS_PUBLIC: ${_ALPAKA_COMPILE_OPTIONS_PUBLIC}")
ENDIF()
LIST(
LENGTH
_ALPAKA_COMPILE_OPTIONS_PUBLIC
_ALPAKA_COMPILE_OPTIONS_PUBLIC_LENGTH)
IF(${_ALPAKA_COMPILE_OPTIONS_PUBLIC_LENGTH} GREATER 0)
TARGET_COMPILE_OPTIONS(
"alpaka"
PUBLIC ${_ALPAKA_COMPILE_OPTIONS_PUBLIC})
ENDIF()
# Compile definitions.
IF(${ALPAKA_DEBUG} GREATER 1)
MESSAGE(STATUS "_ALPAKA_COMPILE_DEFINITIONS_PUBLIC: ${_ALPAKA_COMPILE_DEFINITIONS_PUBLIC}")
ENDIF()
LIST(
LENGTH
_ALPAKA_COMPILE_DEFINITIONS_PUBLIC
_ALPAKA_COMPILE_DEFINITIONS_PUBLIC_LENGTH)
IF(${_ALPAKA_COMPILE_DEFINITIONS_PUBLIC_LENGTH} GREATER 0)
TARGET_COMPILE_DEFINITIONS(
"alpaka"
PUBLIC ${_ALPAKA_COMPILE_DEFINITIONS_PUBLIC})
ENDIF()
# Include directories.
IF(${ALPAKA_DEBUG} GREATER 1)
MESSAGE(STATUS "_ALPAKA_INCLUDE_DIRECTORIES_PUBLIC: ${_ALPAKA_INCLUDE_DIRECTORIES_PUBLIC}")
ENDIF()
LIST(
LENGTH
_ALPAKA_INCLUDE_DIRECTORIES_PUBLIC
_ALPAKA_INCLUDE_DIRECTORIES_PUBLIC_LENGTH)
IF(${_ALPAKA_INCLUDE_DIRECTORIES_PUBLIC_LENGTH} GREATER 0)
TARGET_INCLUDE_DIRECTORIES(
"alpaka"
PUBLIC ${_ALPAKA_INCLUDE_DIRECTORIES_PUBLIC})
ENDIF()
# Link libraries.
# There are no PUBLIC_LINK_FLAGS in CMAKE:
# http://stackoverflow.com/questions/26850889/cmake-keeping-link-flags-of-internal-libs
IF(${ALPAKA_DEBUG} GREATER 1)
MESSAGE(STATUS "_ALPAKA_LINK_LIBRARIES_PUBLIC: ${_ALPAKA_LINK_LIBRARIES_PUBLIC}")
ENDIF()
LIST(
LENGTH
_ALPAKA_LINK_LIBRARIES_PUBLIC
_ALPAKA_LINK_LIBRARIES_PUBLIC_LENGTH)
IF(${_ALPAKA_LINK_LIBRARIES_PUBLIC_LENGTH} GREATER 0)
TARGET_LINK_LIBRARIES(
"alpaka"
PUBLIC ${_ALPAKA_LINK_LIBRARIES_PUBLIC} ${_ALPAKA_LINK_FLAGS_PUBLIC})
ENDIF()
ENDIF()
#-------------------------------------------------------------------------------
# Find alpaka version.
#-------------------------------------------------------------------------------
file(STRINGS "${CMAKE_CURRENT_LIST_DIR}/include/alpaka/version.hpp" ALPAKA_VERSION_MAJOR_HPP REGEX "#define ALPAKA_VERSION_MAJOR ")
file(STRINGS "${CMAKE_CURRENT_LIST_DIR}/include/alpaka/version.hpp" ALPAKA_VERSION_MINOR_HPP REGEX "#define ALPAKA_VERSION_MINOR ")
file(STRINGS "${CMAKE_CURRENT_LIST_DIR}/include/alpaka/version.hpp" ALPAKA_VERSION_PATCH_HPP REGEX "#define ALPAKA_VERSION_PATCH ")
string(REGEX MATCH "([0-9]+)" ALPAKA_VERSION_MAJOR ${ALPAKA_VERSION_MAJOR_HPP})
string(REGEX MATCH "([0-9]+)" ALPAKA_VERSION_MINOR ${ALPAKA_VERSION_MINOR_HPP})
string(REGEX MATCH "([0-9]+)" ALPAKA_VERSION_PATCH ${ALPAKA_VERSION_PATCH_HPP})
SET(PACKAGE_VERSION "${ALPAKA_VERSION_MAJOR}.${ALPAKA_VERSION_MINOR}.${ALPAKA_VERSION_PATCH}")
#-------------------------------------------------------------------------------
# Set return values.
#-------------------------------------------------------------------------------
SET(alpaka_VERSION "${ALPAKA_VERSION_MAJOR}.${ALPAKA_VERSION_MINOR}.${ALPAKA_VERSION_PATCH}")
SET(alpaka_COMPILE_OPTIONS ${_ALPAKA_COMPILE_OPTIONS_PUBLIC})
SET(alpaka_COMPILE_DEFINITIONS ${_ALPAKA_COMPILE_DEFINITIONS_PUBLIC})
# Add '-D' to the definitions
SET(alpaka_DEFINITIONS ${_ALPAKA_COMPILE_DEFINITIONS_PUBLIC})
list_add_prefix("-D" alpaka_DEFINITIONS)
# Add the compile options to the definitions.
LIST(APPEND alpaka_DEFINITIONS ${_ALPAKA_COMPILE_OPTIONS_PUBLIC})
SET(alpaka_INCLUDE_DIR ${_ALPAKA_INCLUDE_DIRECTORY})
SET(alpaka_INCLUDE_DIRS ${_ALPAKA_INCLUDE_DIRECTORIES_PUBLIC})
SET(alpaka_LIBRARY ${_ALPAKA_LINK_LIBRARY})
SET(alpaka_LIBRARIES ${_ALPAKA_LINK_FLAGS_PUBLIC})
LIST(APPEND alpaka_LIBRARIES ${_ALPAKA_LINK_LIBRARIES_PUBLIC})
#-------------------------------------------------------------------------------
# Print the return values.
#-------------------------------------------------------------------------------
IF(${ALPAKA_DEBUG} GREATER 0)
MESSAGE(STATUS "alpaka_FOUND: ${alpaka_FOUND}")
MESSAGE(STATUS "alpaka_VERSION: ${alpaka_VERSION}")
MESSAGE(STATUS "alpaka_COMPILE_OPTIONS: ${alpaka_COMPILE_OPTIONS}")
MESSAGE(STATUS "alpaka_COMPILE_DEFINITIONS: ${alpaka_COMPILE_DEFINITIONS}")
MESSAGE(STATUS "alpaka_DEFINITIONS: ${alpaka_DEFINITIONS}")
MESSAGE(STATUS "alpaka_INCLUDE_DIR: ${alpaka_INCLUDE_DIR}")
MESSAGE(STATUS "alpaka_INCLUDE_DIRS: ${alpaka_INCLUDE_DIRS}")
MESSAGE(STATUS "alpaka_LIBRARY: ${alpaka_LIBRARY}")
MESSAGE(STATUS "alpaka_LIBRARIES: ${alpaka_LIBRARIES}")
ENDIF()
# Unset already set variables if not found.
IF(NOT _ALPAKA_FOUND)
UNSET(alpaka_FOUND)
UNSET(alpaka_VERSION)
UNSET(alpaka_COMPILE_OPTIONS)
UNSET(alpaka_COMPILE_DEFINITIONS)
UNSET(alpaka_DEFINITIONS)
UNSET(alpaka_INCLUDE_DIR)
UNSET(alpaka_INCLUDE_DIRS)
UNSET(alpaka_LIBRARY)
UNSET(alpaka_LIBRARIES)
UNSET(_ALPAKA_FOUND)
UNSET(_ALPAKA_COMPILE_OPTIONS_PUBLIC)
UNSET(_ALPAKA_COMPILE_DEFINITIONS_PUBLIC)
UNSET(_ALPAKA_INCLUDE_DIRECTORY)
UNSET(_ALPAKA_INCLUDE_DIRECTORIES_PUBLIC)
UNSET(_ALPAKA_LINK_LIBRARY)
UNSET(_ALPAKA_LINK_LIBRARIES_PUBLIC)
UNSET(_ALPAKA_LINK_FLAGS_PUBLIC)
UNSET(_ALPAKA_COMMON_FILE)
UNSET(_ALPAKA_ADD_EXECUTABLE_FILE)
UNSET(_ALPAKA_ADD_LIBRARY_FILE)
UNSET(_ALPAKA_FILES_HEADER)
UNSET(_ALPAKA_FILES_SOURCE)
UNSET(_ALPAKA_FILES_OTHER)
UNSET(_ALPAKA_BOOST_MIN_VER)
UNSET(_ALPAKA_VERSION_DEFINE)
UNSET(_ALPAKA_VER_MAJOR)
UNSET(_ALPAKA_VER_MINOR)
UNSET(_ALPAKA_VER_PATCH)
ELSE()
# Make internal variables advanced options in the GUI.
MARK_AS_ADVANCED(
alpaka_INCLUDE_DIR
alpaka_LIBRARY
_ALPAKA_COMPILE_OPTIONS_PUBLIC
_ALPAKA_COMPILE_DEFINITIONS_PUBLIC
_ALPAKA_INCLUDE_DIRECTORY
_ALPAKA_INCLUDE_DIRECTORIES_PUBLIC
_ALPAKA_LINK_LIBRARY
_ALPAKA_LINK_LIBRARIES_PUBLIC
_ALPAKA_LINK_FLAGS_PUBLIC
_ALPAKA_COMMON_FILE
_ALPAKA_ADD_EXECUTABLE_FILE
_ALPAKA_ADD_LIBRARY_FILE
_ALPAKA_FILES_HEADER
_ALPAKA_FILES_SOURCE
_ALPAKA_FILES_OTHER
_ALPAKA_BOOST_MIN_VER
_ALPAKA_VERSION_DEFINE
_ALPAKA_VER_MAJOR
_ALPAKA_VER_MINOR
_ALPAKA_VER_PATCH)
ENDIF()
###############################################################################
# FindPackage options
###############################################################################
# Handles the REQUIRED, QUIET and version-related arguments for FIND_PACKAGE.
# NOTE: We do not check for alpaka_LIBRARIES and alpaka_DEFINITIONS because they can be empty.
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(
"alpaka"
FOUND_VAR alpaka_FOUND
REQUIRED_VARS alpaka_INCLUDE_DIR
VERSION_VAR alpaka_VERSION)