|
1 | 1 | # Known NVIDIA GPU achitectures Gloo can be compiled for. |
2 | 2 | # This list will be used for CUDA_ARCH_NAME = All option |
3 | | -set(gloo_known_gpu_archs "30 35 50 52 60 61 70") |
4 | | -set(gloo_known_gpu_archs7 "30 35 50 52") |
5 | | -set(gloo_known_gpu_archs8 "30 35 50 52 60 61") |
| 3 | +set(gloo_known_gpu_archs "") |
6 | 4 |
|
7 | 5 | ################################################################################ |
8 | 6 | # Function for selecting GPU arch flags for nvcc based on CUDA_ARCH_NAME |
@@ -104,78 +102,88 @@ function(gloo_list_append_if_unique list) |
104 | 102 | endfunction() |
105 | 103 |
|
106 | 104 | ################################################################################ |
107 | | -# Short command for cuda compilation |
108 | | -# Usage: |
109 | | -# gloo_cuda_compile(<objlist_variable> <cuda_files>) |
110 | | -macro(gloo_cuda_compile objlist_variable) |
111 | | - foreach(var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_DEBUG) |
112 | | - set(${var}_backup_in_cuda_compile_ "${${var}}") |
113 | | - endforeach() |
| 105 | +### Non macro section |
| 106 | +################################################################################ |
114 | 107 |
|
115 | | - if(APPLE) |
116 | | - list(APPEND CUDA_NVCC_FLAGS -Xcompiler -Wno-unused-function) |
117 | | - endif() |
| 108 | +if(GLOO_USE_CUDA_TOOLKIT) |
| 109 | + find_package(CUDAToolkit 7.0 REQUIRED) |
| 110 | + set(GLOO_CUDA_VERSION ${CUDAToolkit_VERSION}) |
118 | 111 |
|
119 | | - cuda_compile(cuda_objcs ${ARGN}) |
| 112 | + # Convert -O2 -Xcompiler="-O2 -Wall" to "-O2;-Xcompiler=-O2,-Wall" |
| 113 | + separate_arguments(GLOO_NVCC_FLAGS UNIX_COMMAND "${CMAKE_CUDA_FLAGS}") |
| 114 | + string(REPLACE " " "," GLOO_NVCC_FLAGS "${GLOO_NVCC_FLAGS}") |
120 | 115 |
|
121 | | - foreach(var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_DEBUG) |
122 | | - set(${var} "${${var}_backup_in_cuda_compile_}") |
123 | | - unset(${var}_backup_in_cuda_compile_) |
124 | | - endforeach() |
| 116 | + if(CUDA_USE_STATIC_CUDA_RUNTIME) |
| 117 | + set(GLOO_CUDA_LIBRARIES CUDA::cudart_static) |
| 118 | + else() |
| 119 | + set(GLOO_CUDA_LIBRARIES CUDA::cudart) |
| 120 | + endif() |
| 121 | +else() |
| 122 | + find_package(CUDA 7.0) |
| 123 | + if(NOT CUDA_FOUND) |
| 124 | + return() |
| 125 | + endif() |
| 126 | + set(GLOO_CUDA_VERSION ${CUDA_VERSION}) |
| 127 | + set(GLOO_NVCC_FLAGS "${CUDA_NVCC_FLAGS}") |
125 | 128 |
|
126 | | - set(${objlist_variable} ${cuda_objcs}) |
127 | | -endmacro() |
| 129 | + include_directories(SYSTEM ${CUDA_INCLUDE_DIRS}) |
| 130 | + set(GLOO_CUDA_LIBRARIES ${CUDA_CUDART_LIBRARY}) |
128 | 131 |
|
129 | | -################################################################################ |
130 | | -### Non macro section |
131 | | -################################################################################ |
| 132 | + # If the project including us doesn't set any -std=xxx directly, we set it to C++11 here. |
| 133 | + set(CUDA_PROPAGATE_HOST_FLAGS OFF) |
| 134 | + if((NOT "${GLOO_NVCC_FLAGS}" MATCHES "-std=c\\+\\+") AND (NOT "${GLOO_NVCC_FLAGS}" MATCHES "-std=gnu\\+\\+")) |
| 135 | + if(NOT MSVC) |
| 136 | + gloo_list_append_if_unique(GLOO_NVCC_FLAGS "-std=c++11") |
| 137 | + endif() |
| 138 | + endif() |
132 | 139 |
|
133 | | -find_package(CUDA 7.0) |
134 | | -if(NOT CUDA_FOUND) |
135 | | - return() |
| 140 | + mark_as_advanced(CUDA_BUILD_CUBIN CUDA_BUILD_EMULATION CUDA_VERBOSE_BUILD) |
| 141 | + mark_as_advanced(CUDA_SDK_ROOT_DIR CUDA_SEPARABLE_COMPILATION) |
136 | 142 | endif() |
137 | 143 |
|
138 | 144 | set(HAVE_CUDA TRUE) |
139 | | -message(STATUS "CUDA detected: " ${CUDA_VERSION}) |
140 | | -if (${CUDA_VERSION} LESS 8.0) |
141 | | - set(gloo_known_gpu_archs ${gloo_known_gpu_archs7}) |
142 | | - list(APPEND CUDA_NVCC_FLAGS "-D_MWAITXINTRIN_H_INCLUDED") |
143 | | - list(APPEND CUDA_NVCC_FLAGS "-D__STRICT_ANSI__") |
144 | | -elseif (${CUDA_VERSION} LESS 9.0) |
145 | | - set(gloo_known_gpu_archs ${gloo_known_gpu_archs8}) |
146 | | - list(APPEND CUDA_NVCC_FLAGS "-D_MWAITXINTRIN_H_INCLUDED") |
147 | | - list(APPEND CUDA_NVCC_FLAGS "-D__STRICT_ANSI__") |
| 145 | +message(STATUS "CUDA detected: " ${GLOO_CUDA_VERSION}) |
| 146 | +if (${GLOO_CUDA_VERSION} LESS 9.0) |
| 147 | + list(APPEND GLOO_NVCC_FLAGS "-D_MWAITXINTRIN_H_INCLUDED") |
| 148 | + list(APPEND GLOO_NVCC_FLAGS "-D__STRICT_ANSI__") |
148 | 149 | else() |
149 | | - # CUDA 8 may complain that sm_20 is no longer supported. Suppress the warning for now. |
150 | | - list(APPEND CUDA_NVCC_FLAGS "-Wno-deprecated-gpu-targets") |
| 150 | + # nvcc may complain that sm_xx is no longer supported. Suppress the warning for now. |
| 151 | + list(APPEND GLOO_NVCC_FLAGS "-Wno-deprecated-gpu-targets") |
| 152 | +endif() |
| 153 | + |
| 154 | +if(GLOO_CUDA_VERSION VERSION_LESS 8.0) |
| 155 | + set(gloo_known_gpu_archs "30 35 50 52") |
| 156 | +elseif(GLOO_CUDA_VERSION VERSION_LESS 9.0) |
| 157 | + set(gloo_known_gpu_archs "30 35 50 52 60 61") |
| 158 | +elseif(GLOO_CUDA_VERSION VERSION_LESS 10.0) |
| 159 | + set(gloo_known_gpu_archs "30 35 50 52 60 61 70") |
| 160 | +elseif(GLOO_CUDA_VERSION VERSION_LESS 11.0) |
| 161 | + set(gloo_known_gpu_archs "35 50 52 60 61 70 75") |
| 162 | +elseif(GLOO_CUDA_VERSION VERSION_LESS 12.0) |
| 163 | + set(gloo_known_gpu_archs "35 50 52 60 61 70 75 80 86") |
151 | 164 | endif() |
152 | 165 |
|
153 | | -include_directories(SYSTEM ${CUDA_INCLUDE_DIRS}) |
154 | | -list(APPEND gloo_DEPENDENCY_LIBS ${CUDA_CUDART_LIBRARY}) |
| 166 | +list(APPEND gloo_cuda_DEPENDENCY_LIBS ${GLOO_CUDA_LIBRARIES}) |
155 | 167 |
|
156 | 168 | # Setting nvcc arch flags (or inherit if already set) |
157 | | -if (NOT ";${CUDA_NVCC_FLAGS};" MATCHES ";-gencode;") |
| 169 | +if (NOT ";${GLOO_NVCC_FLAGS};" MATCHES ";-gencode;") |
158 | 170 | gloo_select_nvcc_arch_flags(NVCC_FLAGS_EXTRA) |
159 | | - list(APPEND CUDA_NVCC_FLAGS ${NVCC_FLAGS_EXTRA}) |
| 171 | + list(APPEND GLOO_NVCC_FLAGS ${NVCC_FLAGS_EXTRA}) |
160 | 172 | message(STATUS "Added CUDA NVCC flags for: ${NVCC_FLAGS_EXTRA_readable}") |
161 | 173 | endif() |
162 | 174 |
|
163 | 175 | # Disable some nvcc diagnostic that apears in boost, glog, glags, opencv, etc. |
164 | 176 | foreach(diag cc_clobber_ignored integer_sign_change useless_using_declaration set_but_not_used) |
165 | | - gloo_list_append_if_unique(CUDA_NVCC_FLAGS -Xcudafe --diag_suppress=${diag}) |
| 177 | + gloo_list_append_if_unique(GLOO_NVCC_FLAGS -Xcudafe --diag_suppress=${diag}) |
166 | 178 | endforeach() |
167 | 179 |
|
168 | | -# If the project including us doesn't set any -std=xxx directly, we set it to C++11 here. |
169 | | -set(CUDA_PROPAGATE_HOST_FLAGS OFF) |
170 | | -if((NOT "${CUDA_NVCC_FLAGS}" MATCHES "-std=c\\+\\+") AND (NOT "${CUDA_NVCC_FLAGS}" MATCHES "-std=gnu\\+\\+")) |
171 | | - if(NOT MSVC) |
172 | | - gloo_list_append_if_unique(CUDA_NVCC_FLAGS "-std=c++11") |
173 | | - endif() |
174 | | -endif() |
175 | | - |
176 | 180 | if(NOT MSVC) |
177 | | - gloo_list_append_if_unique(CUDA_NVCC_FLAGS "-Xcompiler" "-fPIC") |
| 181 | + gloo_list_append_if_unique(GLOO_NVCC_FLAGS "-Xcompiler" "-fPIC") |
178 | 182 | endif() |
179 | 183 |
|
180 | | -mark_as_advanced(CUDA_BUILD_CUBIN CUDA_BUILD_EMULATION CUDA_VERBOSE_BUILD) |
181 | | -mark_as_advanced(CUDA_SDK_ROOT_DIR CUDA_SEPARABLE_COMPILATION) |
| 184 | +if(GLOO_USE_CUDA_TOOLKIT) |
| 185 | + # Convert list to space-separated string |
| 186 | + string(REPLACE ";" " " CMAKE_CUDA_FLAGS "${GLOO_NVCC_FLAGS}") |
| 187 | +else() |
| 188 | + set(CUDA_NVCC_FLAGS "${GLOO_NVCC_FLAGS}") |
| 189 | +endif() |
0 commit comments