Skip to content

Commit a674b3f

Browse files
committed
Auto detect nvidia CC in CMake
1 parent a13cd73 commit a674b3f

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

CMakeLists.txt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ set (HOST ${hostValue} CACHE BOOL "Build Executables for GPU Platform (OFF) or C
237237

238238

239239
#[[
240-
!!/ **-DGPU_LANG (gpu_lang) = OPENACC** (experimental, in progress)
240+
!!/ **-DGPU_LANG (gpu_lang) = OPENACC**
241241
!!/
242242
!!/ If set to *CUDA*, the GPU code will only use the cuda source files.
243243
!!/ And the program will crash at runtime if it falls into an OpenACC code path.
@@ -255,14 +255,17 @@ set (GPU_LANG ${gpuLangValue} CACHE STRING
255255

256256

257257
#[[
258-
!!/ **-DCOMPUTE_CAPABILITY (compute_capability) = 60,70**
258+
!!/ **-DCOMPUTE_CAPABILITY (compute_capability) = AUTO**
259259
!!/
260260
!!/ GPU code only.
261261
!!/
262262
!!/ CUDA compute capability (multiplied by 10) of GPU.
263-
!!/ Valid values (noninclusive) are 35, 50, 60, 70, 75 etc., and can be
263+
!!/ Valid values (noninclusive) are 35, 50, 60, 70, 75, etc., and can be
264264
!!/ comma-separated, e.g. 35,60.
265265
!!/ Multiple compute capabilites will increase the size of executables.
266+
!!/ If left unspecified, the script will attempt to detect the GPU,
267+
!!/ although the detection may fail due to different reasons, which would
268+
!!/ then require this option to be specified explicitly.
266269
!!/
267270
!!/ If new cards are released but the newer compute capabilities
268271
!!/ are not supported, please inform us.
@@ -274,11 +277,20 @@ set (GPU_LANG ${gpuLangValue} CACHE STRING
274277
if (DEFINED ENV{compute_capability})
275278
set (compCapValue $ENV{compute_capability})
276279
else ()
277-
set (compCapValue 60,70)
280+
set (compCapValue AUTO)
278281
endif ()
279282
set (COMPUTE_CAPABILITY ${compCapValue} CACHE STRING
280283
"[GPU ONLY] CUDA Compute Capability Multiplied by 10 (Comma-Separated)"
281284
)
285+
if ("${COMPUTE_CAPABILITY}" STREQUAL AUTO)
286+
find_package (Python3 COMPONENTS Interpreter)
287+
if (Python3_FOUND)
288+
execute_process (
289+
COMMAND ${Python3_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/nvidiacc.py"
290+
OUTPUT_VARIABLE COMPUTE_CAPABILITY
291+
)
292+
endif ()
293+
endif ()
282294
## Compute Capability 60,70 -> 60;70
283295
string (REPLACE "," ";" T9_CUCCLIST ${COMPUTE_CAPABILITY}) # 60;70
284296

cmake/nvidiacc.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python3
21
# -*- coding: utf-8 -*-
32

43
'''

doc/manual/m/install/buildwithcmake.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,22 @@ cost of slightly slower simulation speed, a more "deterministic" force
122122
Flag to compile to GPU (with value 0 or OFF) or CPU (with value 1 or ON)
123123
version.
124124

125-
**-DGPU_LANG (gpu_lang) = OPENACC** (experimental, in progress)
125+
**-DGPU_LANG (gpu_lang) = OPENACC**
126126

127127
If set to *CUDA*, the GPU code will only use the cuda source files.
128128
And the program will crash at runtime if it falls into an OpenACC code path.
129129

130-
**-DCOMPUTE_CAPABILITY (compute_capability) = 60,70**
130+
**-DCOMPUTE_CAPABILITY (compute_capability) = AUTO**
131131

132132
GPU code only.
133133

134134
CUDA compute capability (multiplied by 10) of GPU.
135-
Valid values (noninclusive) are 35, 50, 60, 70, 75 etc., and can be
135+
Valid values (noninclusive) are 35, 50, 60, 70, 75, etc., and can be
136136
comma-separated, e.g. 35,60.
137137
Multiple compute capabilites will increase the size of executables.
138+
If left unspecified, the script will attempt to detect the GPU,
139+
although the detection may fail due to different reasons, which would
140+
then require this option to be specified explicitly.
138141

139142
If new cards are released but the newer compute capabilities
140143
are not supported, please inform us.

0 commit comments

Comments
 (0)