1
1
2
2
register_flag_optional(THRUST_IMPL
3
3
"Which Thrust implementation to use, supported options include:
4
- - CUDA (via https://github.com/NVIDIA/thrust)
4
+ - CUDA (via https://github.com/NVIDIA/thrust or https://github.com/NVIDIA/CCCL )
5
5
- ROCM (via https://github.com/ROCmSoftwarePlatform/rocThrust)
6
6
"
7
7
"CUDA" )
8
8
9
9
register_flag_optional(SDK_DIR
10
- "Path to the selected Thrust implementation (e.g `/opt/nvidia/hpc_sdk/Linux_x86_64/21.9 /cuda/include ` for NVHPC, `/opt/rocm` for ROCm)"
10
+ "Path to the installation prefix for CCCL or Thrust (e.g `/opt/nvidia/hpc_sdk/Linux_x86_64/22.3 /cuda/11.6 ` for NVHPC, or `/usr/local/cuda` for nvcc, or `/opt/rocm` for ROCm)"
11
11
"" )
12
12
13
13
register_flag_optional(BACKEND
14
14
"[THRUST_IMPL==CUDA] CUDA's Thrust implementation supports the following backends:
15
- - CUDA
15
+ - CUD
16
16
- OMP
17
17
- TBB
18
18
"
19
19
"CUDA" )
20
20
21
- register_flag_optional(MANAGED "Enabled managed memory mode."
21
+ register_flag_optional(MANAGED "Enabled managed memory mode."
22
22
"OFF" )
23
23
24
24
register_flag_optional(CMAKE_CUDA_COMPILER
@@ -34,6 +34,9 @@ register_flag_optional(CUDA_EXTRA_FLAGS
34
34
"[THRUST_IMPL==CUDA] Additional CUDA flags passed to nvcc, this is appended after `CUDA_ARCH`"
35
35
"" )
36
36
37
+ option (FETCH_CCCL "Fetch (download) the CCCL library. This uses CMake's FetchContent feature.
38
+ Specify version by setting FETCH_CCCL_VERSION" OFF )
39
+ set (FETCH_CCCL_VERSION "v2.4.0" CACHE STRING "Specify version of CCCL to use if FETCH_CCCL is ON" )
37
40
38
41
macro (setup)
39
42
set (CMAKE_CXX_STANDARD 14)
@@ -42,44 +45,48 @@ macro(setup)
42
45
endif ()
43
46
44
47
if (${THRUST_IMPL} STREQUAL "CUDA" )
45
-
46
- # see CUDA.cmake, we're only adding a few Thrust related libraries here
47
-
48
48
if (POLICY CMP0104)
49
49
cmake_policy (SET CMP0104 NEW)
50
50
endif ()
51
-
52
51
set (CMAKE_CUDA_ARCHITECTURES ${CUDA_ARCH} )
53
- # add -forward-unknown-to-host-compiler for compatibility reasons
54
52
set (CMAKE_CUDA_FLAGS ${CMAKE_CUDA_FLAGS} "--expt-extended-lambda " ${CUDA_EXTRA_FLAGS} )
55
53
enable_language (CUDA)
56
- # CMake defaults to -O2 for CUDA at Release, let's wipe that and use the global RELEASE_FLAG
57
- # appended later
54
+ # CMake defaults to -O2 for CUDA at Release, let's wipe that and use the global RELEASE_FLAG appended later
58
55
wipe_gcc_style_optimisation_flags(CMAKE_CUDA_FLAGS_${BUILD_TYPE} )
59
56
60
57
message (STATUS "NVCC flags: ${CMAKE_CUDA_FLAGS} ${CMAKE_CUDA_FLAGS_${BUILD_TYPE} }" )
61
58
62
-
63
- # XXX NVHPC <= 21.9 has cub-config in `Linux_x86_64/21.9/cuda/11.4/include/cub/cmake`
64
- # XXX NVHPC >= 22.3 has cub-config in `Linux_x86_64/22.3/cuda/11.6/lib64/cmake/cub/`
65
- # same thing for thrust
66
59
if (SDK_DIR)
60
+ # CMake tries several subdirectories below SDK_DIR, see documentation:
61
+ # https://cmake.org/cmake/help/latest/command/find_package.html#config-mode-search-procedure
67
62
list (APPEND CMAKE_PREFIX_PATH ${SDK_DIR} )
68
- find_package (CUB REQUIRED CONFIG PATHS ${SDK_DIR} /cub)
69
- find_package (Thrust REQUIRED CONFIG PATHS ${SDK_DIR} /thrust)
70
- else ()
71
- find_package (CUB REQUIRED CONFIG)
72
- find_package (Thrust REQUIRED CONFIG)
73
63
endif ()
74
64
75
- message (STATUS "Using Thrust backend: ${BACKEND} " )
76
-
77
- # this creates the interface that we can link to
78
- thrust_create_target(Thrust${BACKEND}
79
- HOST CPP
80
- DEVICE ${BACKEND} )
81
-
82
- register_link_library(Thrust${BACKEND} )
65
+ set (CCCL_THRUST_DEVICE_SYSTEM ${BACKEND} CACHE STRING "" FORCE)
66
+
67
+ # fetch CCCL if user wants to
68
+ if (FETCH_CCCL)
69
+ FetchContent_Declare(
70
+ CCCL
71
+ GIT_REPOSITORY https://github.com/nvidia/cccl.git
72
+ GIT_TAG "${FETCH_CCCL_VERSION} "
73
+ )
74
+ FetchContent_MakeAvailable(CCCL)
75
+ register_link_library(CCCL::CCCL)
76
+ else ()
77
+ # try to find CCCL locally
78
+ find_package (CCCL CONFIG)
79
+ if (CCCL_FOUND)
80
+ register_link_library(CCCL::CCCL)
81
+ else ()
82
+ # backup: find legacy projects separately
83
+ message (WARNING "No CCCL found on your system. Trying Thrust and CUB legacy targets." )
84
+ find_package (CUB REQUIRED CONFIG)
85
+ find_package (Thrust REQUIRED CONFIG)
86
+ thrust_create_target(Thrust${BACKEND} HOST CPP DEVICE ${BACKEND} )
87
+ register_link_library(Thrust${BACKEND} )
88
+ endif ()
89
+ endif ()
83
90
elseif (${THRUST_IMPL} STREQUAL "ROCM" )
84
91
if (SDK_DIR)
85
92
find_package (rocprim REQUIRED CONFIG PATHS ${SDK_DIR} /rocprim)
0 commit comments