1- # CMake below 3.4 does not work with CUDA separable compilation at all
2- cmake_minimum_required (VERSION 3.12 )
1+ # First-order language CUDA requires at least CMake 3.18
2+ cmake_minimum_required (VERSION 3.24 )
33
4- project (PopSift VERSION 1.0.0 LANGUAGES CXX)
4+ project (PopSift VERSION 1.0.0 LANGUAGES CXX CUDA)
5+
6+ # Policy to support CUDA as a first-order language for CMake.
7+ # Since CMake 3.18. See https://cmake.org/cmake/help/latest/policy/CMP0104.html
8+ cmake_policy (SET CMP0104 NEW)
9+
10+ set (CMAKE_CUDA_ARCHITECTURES "all-major"
11+ CACHE
12+ STRING "Which CUDA CCs to support: native, all, all-major or an explicit list delimited by semicolons"
13+ FORCE)
514
615# Set build path as a folder named as the platform (linux, windows, darwin...) plus the processor type
716set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR} /${CMAKE_SYSTEM_NAME} -${CMAKE_SYSTEM_PROCESSOR} " )
@@ -16,7 +25,6 @@ option(PopSift_USE_GRID_FILTER "Switch off grid filtering to massively reduce co
1625option (PopSift_USE_NORMF "The __normf function computes Euclidean distance on large arrays. Fast but stability is uncertain." OFF )
1726option (PopSift_NVCC_WARNINGS "Switch on several additional warning for CUDA nvcc" OFF )
1827option (PopSift_USE_TEST_CMD "Add testing step for functional verification" OFF )
19- option (PopSift_NO_DEPRECATED_CUDA_SM_WARNINGS "Suppress warnings about soon to be deprecated cuda SM" ON )
2028option (BUILD_SHARED_LIBS "Build shared libraries" ON )
2129
2230if (PopSift_USE_POSITION_INDEPENDENT_CODE AND NOT MSVC )
@@ -55,17 +63,15 @@ include(GNUInstallDirs)
5563
5664if (BUILD_SHARED_LIBS )
5765 message (STATUS "BUILD_SHARED_LIBS ON" )
58- # Need to declare CUDA_USE_STATIC_CUDA_RUNTIME as an option to ensure that it is not overwritten in FindCUDA.
59- option (CUDA_USE_STATIC_CUDA_RUNTIME "Use the static version of the CUDA runtime library if available" OFF )
60- set (CUDA_USE_STATIC_CUDA_RUNTIME OFF )
61- # Workaround to force deactivation of cuda static runtime for cmake < 3.10
62- set (CUDA_cudart_static_LIBRARY 0)
66+
6367 # Auto-build dll exports on Windows
6468 set (CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON )
69+
70+ set (CMAKE_CUDA_RUNTIME_LIBRARY Shared)
6571else ()
6672 message (STATUS "BUILD_SHARED_LIBS OFF" )
67- option (CUDA_USE_STATIC_CUDA_RUNTIME "Use the static version of the CUDA runtime library if available" ON )
68- set (CUDA_USE_STATIC_CUDA_RUNTIME ON )
73+
74+ set (CMAKE_CUDA_RUNTIME_LIBRARY Static )
6975endif ()
7076
7177# Require threads because of std::thread.
@@ -74,26 +80,15 @@ find_package(Threads REQUIRED)
7480###################
7581# CUDA
7682###################
77- find_package (CUDA 7.0 REQUIRED)
83+ include (CheckLanguage)
84+ check_language(CUDA)
7885
79- if ( NOT CUDA_FOUND)
80- message (FATAL_ERROR "Could not find CUDA >= 7.0" )
81- endif ( )
86+ # Use this if necessary: "cmake -DCUDAToolkit_ROOT=/some/path"
87+ # target_link_libraries(binary_linking_to_cudart PRIVATE CUDA::cudart )
88+ find_package (CUDAToolkit )
8289
83- message (STATUS "CUDA Version is ${CUDA_VERSION} " )
84-
85- include (ChooseCudaCC)
86- if (NOT DEFINED PopSift_CUDA_CC_LIST)
87- chooseCudaCC(PopSift_CUDA_CC_LIST_BASIC
88- PopSift_CUDA_GENCODE_FLAGS
89- MIN_CC 30
90- MIN_CUDA_VERSION 7.0)
91- set (PopSift_CUDA_CC_LIST ${PopSift_CUDA_CC_LIST_BASIC} CACHE STRING "CUDA CC versions to compile" )
92- else ()
93- getFlagsForCudaCCList(PopSift_CUDA_CC_LIST
94- PopSift_CUDA_GENCODE_FLAGS)
95- endif ()
96- list (APPEND CUDA_NVCC_FLAGS "${PopSift_CUDA_GENCODE_FLAGS} " )
90+ message (STATUS "CUDA Version is ${CUDAToolkit_VERSION} " )
91+ set (CUDA_VERSION ${CUDAToolkit_VERSION} )
9792
9893if (PopSift_USE_NVTX_PROFILING)
9994 message (STATUS "PROFILING CPU CODE: NVTX is in use" )
@@ -104,46 +99,8 @@ if(PopSift_ERRCHK_AFTER_KERNEL)
10499 list (APPEND CUDA_NVCC_FLAGS "-DERRCHK_AFTER_KERNEL" )
105100endif ()
106101
107- set (CUDA_SEPARABLE_COMPILATION ON )
108-
109- if (PopSift_NO_DEPRECATED_CUDA_SM_WARNINGS)
110- list (APPEND CUDA_NVCC_FLAGS "-Wno-deprecated-gpu-targets" )
111- endif ()
112-
113- if (UNIX AND NOT APPLE )
114- list (APPEND CUDA_NVCC_FLAGS "-Xcompiler;-rdynamic" )
115- # set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS};-Xptxas;-v")
116- # set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS};-Xptxas;-warn-double-usage")
117- list (APPEND CUDA_NVCC_FLAGS_DEBUG "--keep" )
118- list (APPEND CUDA_NVCC_FLAGS_DEBUG "--source-in-ptx" )
119- endif ()
120-
121- # The following if should not be necessary, but apparently there is a bug in FindCUDA.cmake that
122- # generate an empty string in the nvcc command line causing the compilation to fail.
123- # see https://gitlab.kitware.com/cmake/cmake/issues/16411
124- if (CMAKE_BUILD_TYPE STREQUAL "Debug" )
125- message (STATUS "Building in debug mode" )
126- list (APPEND CUDA_NVCC_FLAGS_DEBUG "-G" )
127- endif ()
128- list (APPEND CUDA_NVCC_FLAGS_RELEASE "-O3" )
129-
130- if (PopSift_USE_POSITION_INDEPENDENT_CODE AND NOT MSVC )
131- list (APPEND CUDA_NVCC_FLAGS "-Xcompiler;-fPIC" )
132- endif ()
133-
134- # this is to ensure that on MSVC the flags for the linker are properly propagate even to the intermediate
135- # linking step. This seems not the case e.g. on vcpkg using ninja build.
136- if (MSVC )
137- if (BUILD_SHARED_LIBS )
138- set (PopSift_MVSC_LINKER "/MD" )
139- else ()
140- set (PopSift_MVSC_LINKER "/MT" )
141- endif ()
142- if (CMAKE_BUILD_TYPE STREQUAL "Debug" )
143- set (PopSift_MVSC_LINKER "${PopSift_MVSC_LINKER} d" )
144- endif ()
145- list (APPEND CUDA_NVCC_FLAGS -Xcompiler ${PopSift_MVSC_LINKER} )
146- endif ()
102+ # This may not be required any more.
103+ set (CMAKE_CUDA_SEPARABLE_COMPILATION ON )
147104
148105# default stream per-thread implies that each host thread has one non-synchronizing 0-stream
149106# currently, the code requires legacy mode
@@ -159,7 +116,7 @@ if(CUDA_VERSION VERSION_GREATER_EQUAL "7.5")
159116 endif ()
160117endif ()
161118
162- set (PopSift_CXX_STANDARD 14 ) # Thrust/CUB requires C++14 starting with CUDA SDK 11
119+ set (PopSift_CXX_STANDARD 17 ) # Thrust/CUB requires C++14 starting with CUDA SDK 11
163120if (CUDA_VERSION_MAJOR LESS_EQUAL 8)
164121 set (PopSift_CXX_STANDARD 11)
165122endif ()
@@ -181,9 +138,9 @@ else()
181138endif ()
182139
183140if (CUDA_VERSION VERSION_GREATER_EQUAL "9.0" )
184- set (HAVE_SHFL_DOWN_SYNC 1)
141+ set (PopSift_HAVE_SHFL_DOWN_SYNC 1)
185142else ()
186- set (HAVE_SHFL_DOWN_SYNC 0)
143+ set (PopSift_HAVE_SHFL_DOWN_SYNC 0)
187144endif ()
188145
189146if (NOT PopSift_USE_GRID_FILTER)
@@ -193,12 +150,8 @@ else()
193150 set (DISABLE_GRID_FILTER 0)
194151endif ()
195152
196- # library required for CUDA dynamic parallelism, forgotten by CMake 3.4
197- cuda_find_library_local_first(CUDA_CUDADEVRT_LIBRARY cudadevrt "\" cudadevrt\" library" )
198-
199153if (PopSift_USE_NVTX_PROFILING)
200154 # library required for NVTX profiling of the CPU
201- cuda_find_library_local_first(CUDA_NVTX_LIBRARY nvToolsExt "NVTX library" )
202155 set (PopSift_USE_NVTX 1)
203156else ()
204157 set (PopSift_USE_NVTX 0)
@@ -245,9 +198,14 @@ message(STATUS "Use CUDA NVTX for profiling: " ${PopSift_USE_NVTX_PROFILING})
245198message (STATUS "Synchronize and check CUDA error after every kernel: " ${PopSift_ERRCHK_AFTER_KERNEL} )
246199message (STATUS "Grid filtering: " ${PopSift_USE_GRID_FILTER} )
247200message (STATUS "Additional warning for CUDA nvcc: " ${PopSift_NVCC_WARNINGS} )
248- message (STATUS "Compiling for CUDA CCs: ${PopSift_CUDA_CC_LIST} " )
249201message (STATUS "Install path: " ${CMAKE_INSTALL_PREFIX} )
250202message (STATUS "Testing step: " ${PopSift_USE_TEST_CMD} )
203+
204+ message (STATUS "CMAKE_CUDA_COMPILER = ${CMAKE_CUDA_COMPILER} " )
205+ message (STATUS "CMAKE_CUDA_COMPILER_ID = ${CMAKE_CUDA_COMPILER_ID} " )
206+ message (STATUS "CMAKE_CUDA_COMPILER_VERSION = ${CMAKE_CUDA_COMPILER_VERSION} " )
207+ message (STATUS "CMAKE_CUDA_ARCHITECTURES = ${CMAKE_CUDA_ARCHITECTURES} " )
208+
251209if (PopSift_USE_TEST_CMD)
252210 message (STATUS "Path for test input: " ${PopSift_TESTFILE_PATH} )
253211endif ()
0 commit comments