Skip to content

Commit 99a61ac

Browse files
griwesbrycelelbach
authored andcommitted
Thrust CMake conversion:
* Add support for -gencode and selecting CUDA compute versions to generate code for. * Fix a bug when handing -Wnoexcept-type.
1 parent cb2aa06 commit 99a61ac

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

CMakeLists.txt

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,36 @@ if ("CUDA" STREQUAL "${THRUST_DEVICE_SYSTEM}")
9090
# in case this gives You, dear user, any trouble, please escalate the above CMake bug, so we can support reality properly.
9191
unset (CMAKE_CUDA_STANDARD CACHE)
9292
set (CMAKE_CUDA_STANDARD ${CMAKE_CXX_STANDARD})
93+
94+
set(THRUST_HIGHEST_COMPUTE_ARCH 75)
95+
set(THRUST_KNOWN_COMPUTE_ARCHS 30 32 35 50 52 53 60 61 62 70 72 75)
96+
97+
option(THRUST_DISABLE_ARCH_BY_DEFAULT "If ON, then all CUDA architectures are disabled on the initial CMake run." OFF)
98+
set(OPTION_INIT ON)
99+
if (THRUST_DISABLE_ARCH_BY_DEFAULT)
100+
set(OPTION_INIT OFF)
101+
endif ()
102+
103+
if (NOT ${THRUST_HIGHEST_COMPUTE_ARCH} IN_LIST THRUST_KNOWN_COMPUTE_ARCHS)
104+
message(FATAL_ERROR "When changing the highest compute version, don't forget to add it to the list!")
105+
endif ()
106+
107+
foreach (COMPUTE_ARCH IN LISTS THRUST_KNOWN_COMPUTE_ARCHS)
108+
option(THRUST_ENABLE_COMPUTE_${COMPUTE_ARCH} "Enable code generation for tests for sm_${COMPUTE_ARCH}" ${OPTION_INIT})
109+
if (THRUST_ENABLE_COMPUTE_${COMPUTE_ARCH})
110+
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -gencode arch=compute_${COMPUTE_ARCH},code=sm_${COMPUTE_ARCH}")
111+
set(COMPUTE_MESSAGE "${COMPUTE_MESSAGE} sm_${COMPUTE_ARCH}")
112+
endif ()
113+
endforeach ()
114+
115+
option(THRUST_ENABLE_COMPUTE_FUTURE "Enable code generation for tests for compute_${THRUST_HIGHEST_COMPUTE_ARCH}" ${OPTION_INIT})
116+
if (THRUST_ENABLE_COMPUTE_FUTURE)
117+
set(CMAKE_CUDA_FLAGS
118+
"${CMAKE_CUDA_FLAGS} -gencode arch=compute_${THRUST_HIGHEST_COMPUTE_ARCH},code=compute_${THRUST_HIGHEST_COMPUTE_ARCH}")
119+
set(COMPUTE_MESSAGE "${COMPUTE_MESSAGE} compute_${THRUST_HIGHEST_COMPUTE_ARCH}")
120+
endif ()
121+
122+
message("-- Enabled CUDA architectures:${COMPUTE_MESSAGE}")
93123
endif ()
94124

95125
if ("OMP" STREQUAL "${THRUST_DEVICE_SYSTEM}")
@@ -178,7 +208,7 @@ if ("GNU" STREQUAL "${CMAKE_CXX_COMPILER_ID}")
178208
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 7.3)
179209
# GCC 7.3 complains about name mangling changes due to `noexcept`
180210
# becoming part of the type system; we don't care.
181-
append_option_if_available("-Wnoexcept-type" THRUST_CXX_WARNINGS)
211+
append_option_if_available("-Wno-noexcept-type" THRUST_CXX_WARNINGS)
182212
endif ()
183213

184214
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8.1 AND CMAKE_CXX_STANDARD EQUAL 98)

0 commit comments

Comments
 (0)