1
+ function (set_env)
2
+ set (CMAKE_CXX_STANDARD 17 PARENT_SCOPE)
3
+ set (CMAKE_CUDA_STANDARD 17 PARENT_SCOPE)
4
+ set (CMAKE_CUDA_STANDARD_REQUIRED TRUE PARENT_SCOPE)
5
+ set (CMAKE_CXX_STANDARD_REQUIRED TRUE PARENT_SCOPE)
6
+
7
+ if ("$ENV{ICICLE_PIC} " STREQUAL "OFF" OR ICICLE_PIC STREQUAL "OFF" )
8
+ message (WARNING "Note that PIC (position-independent code) is disabled." )
9
+ else ()
10
+ set (CMAKE_POSITION_INDEPENDENT_CODE ON PARENT_SCOPE)
11
+ endif ()
12
+ endfunction ()
13
+
14
+ function (set_gpu_env)
15
+ # add the target cuda architectures
16
+ # each additional architecture increases the compilation time and output file size
17
+ if (DEFINED CUDA_ARCH) # user defined arch takes priority
18
+ set (CMAKE_CUDA_ARCHITECTURES ${CUDA_ARCH} PARENT_SCOPE)
19
+ elseif (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24.0" ) # otherwise, use native to detect GPU arch
20
+ set (CMAKE_CUDA_ARCHITECTURES native PARENT_SCOPE)
21
+ else ()
22
+ find_program (_nvidia_smi "nvidia-smi" )
23
+
24
+ if (_nvidia_smi)
25
+ execute_process (
26
+ COMMAND ${_nvidia_smi} --query-gpu=compute_cap --format=csv,noheader
27
+ OUTPUT_VARIABLE GPU_COMPUTE_CAPABILITIES
28
+ OUTPUT_STRIP_TRAILING_WHITESPACE
29
+ )
30
+ # Process the output to form the CUDA architectures string
31
+ string (REPLACE "\n " ";" GPU_COMPUTE_CAPABILITIES_LIST "${GPU_COMPUTE_CAPABILITIES} " )
32
+
33
+ set (CUDA_ARCHITECTURES "" )
34
+ foreach (CAPABILITY ${GPU_COMPUTE_CAPABILITIES_LIST} )
35
+ # Remove the dot in compute capability to match CMake format
36
+ string (REPLACE "." "" CAPABILITY "${CAPABILITY} " )
37
+ if (CUDA_ARCHITECTURES)
38
+ set (CUDA_ARCHITECTURES "${CUDA_ARCHITECTURES} ;${CAPABILITY} " )
39
+ else ()
40
+ set (CUDA_ARCHITECTURES "${CAPABILITY} " )
41
+ endif ()
42
+ endforeach ()
43
+
44
+ message ("Setting CMAKE_CUDA_ARCHITECTURES to: ${CUDA_ARCHITECTURES} " )
45
+ set (CMAKE_CUDA_ARCHITECTURES "${CUDA_ARCHITECTURES} " PARENT_SCOPE)
46
+ else ()
47
+ # no GPUs found, like on Github CI runners
48
+ message ("Setting CMAKE_CUDA_ARCHITECTURES to: 50" )
49
+ set (CMAKE_CUDA_ARCHITECTURES 50 PARENT_SCOPE) # some safe value
50
+ endif ()
51
+ endif ()
52
+
53
+ # Check CUDA version and, if possible, enable multi-threaded compilation
54
+ if (CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL "12.2" )
55
+ message (STATUS "Using multi-threaded CUDA compilation." )
56
+ set (CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --split-compile 0" PARENT_SCOPE)
57
+ else ()
58
+ message (STATUS "Can't use multi-threaded CUDA compilation." )
59
+ endif ()
60
+ set (CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --expt-relaxed-constexpr" PARENT_SCOPE)
61
+ set (CMAKE_CUDA_FLAGS_RELEASE "" PARENT_SCOPE)
62
+ set (CMAKE_CUDA_FLAGS_DEBUG "${CMAKE_CUDA_FLAGS_DEBUG} -g -lineinfo" PARENT_SCOPE)
63
+ endfunction ()
64
+
65
+ function (find_cuda_compiler)
66
+ # Find the CUDA compiler
67
+ execute_process (
68
+ COMMAND which nvcc
69
+ OUTPUT_VARIABLE CUDA_COMPILER_PATH
70
+ OUTPUT_STRIP_TRAILING_WHITESPACE
71
+ )
72
+
73
+ # Set the CUDA compiler
74
+ set (CMAKE_CUDA_COMPILER ${CUDA_COMPILER_PATH} PARENT_SCOPE)
75
+ endfunction ()
0 commit comments