Skip to content

Commit 139d7e3

Browse files
committed
Add CUDA support to top-level CMakeLists.txt
Signed-off-by: Ben Howe <[email protected]>
1 parent 8a7f74e commit 139d7e3

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

CMakeLists.txt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,44 @@ if (CUDAQX_INCLUDE_TESTS)
9191
endif()
9292
endif()
9393

94+
# Check for CUDA Support
95+
# ==============================================================================
96+
include(CheckLanguage)
97+
check_language(CUDA)
98+
set(CUDA_FOUND FALSE)
99+
# Generate -gencode arch=compute_XX,code=sm_XX for list of supported
100+
# arch values.
101+
# List should be sorted in increasing order.
102+
function(CUDA_get_gencode_args out_args_string arch_values)
103+
# allow the user to pass the list like a normal variable
104+
set(arch_list ${arch_values} ${ARGN})
105+
set(out "")
106+
foreach(arch IN LISTS arch_list)
107+
set(out "${out} -gencode arch=compute_${arch},code=sm_${arch}")
108+
endforeach(arch)
109+
110+
# Repeat the last one as to ensure the generation of PTX for most
111+
# recent virtual architecture for forward compatibility
112+
list(GET arch_list -1 last_arch)
113+
set(out "${out} -gencode arch=compute_${last_arch},code=compute_${last_arch}")
114+
set(${out_args_string} ${out} PARENT_SCOPE)
115+
endfunction()
116+
117+
if(CMAKE_CUDA_COMPILER)
118+
if (NOT CUDA_TARGET_ARCHS)
119+
# Volta, Ampere, Hopper
120+
set(CUDA_TARGET_ARCHS "70;80;90")
121+
endif()
122+
CUDA_get_gencode_args(CUDA_gencode_flags ${CUDA_TARGET_ARCHS})
123+
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -shared -std=c++17 ${CUDA_gencode_flags} --compiler-options -fPIC")
124+
125+
enable_language(CUDA)
126+
set(CUDA_FOUND TRUE)
127+
set(CMAKE_CUDA_STANDARD 17)
128+
set(CMAKE_CUDA_STANDARD_REQUIRED TRUE)
129+
message(STATUS "Cuda language found.")
130+
endif()
131+
94132
# Directory setup
95133
# ==============================================================================
96134

0 commit comments

Comments
 (0)