File: check_compute_capability.cmake

package info (click to toggle)
stdgpu 1.3.0%2Bgit20220507.32e0517-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,528 kB
  • sloc: cpp: 7,818; pascal: 1,893; xml: 214; sh: 181; makefile: 50
file content (29 lines) | stat: -rw-r--r-- 1,737 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Check for GPUs present and their compute capability
# based on http://stackoverflow.com/questions/2285185/easiest-way-to-test-for-existence-of-cuda-capable-gpu-from-cmake/2297877#2297877 (Christopher Bruns)

set(STDGPU_CUDA_COMPUTE_CAPABILITIES_SOURCE "${CMAKE_CURRENT_LIST_DIR}/compute_capability.cpp")
message(STATUS "Detecting CCs of GPUs : ${STDGPU_CUDA_COMPUTE_CAPABILITIES_SOURCE}")

find_package(CUDAToolkit REQUIRED QUIET MODULE)

try_run(STDGPU_RUN_RESULT_VAR STDGPU_COMPILE_RESULT_VAR
        ${CMAKE_BINARY_DIR}
        ${STDGPU_CUDA_COMPUTE_CAPABILITIES_SOURCE}
        LINK_LIBRARIES CUDA::cudart
        COMPILE_OUTPUT_VARIABLE STDGPU_COMPILE_OUTPUT_VAR
        RUN_OUTPUT_VARIABLE STDGPU_RUN_OUTPUT_VAR)

# COMPILE_RESULT_VAR is TRUE when compile succeeds
# RUN_RESULT_VAR is zero when a GPU is found
if(STDGPU_COMPILE_RESULT_VAR AND NOT STDGPU_RUN_RESULT_VAR)
    message(STATUS "Detecting CCs of GPUs : ${STDGPU_CUDA_COMPUTE_CAPABILITIES_SOURCE} - Success (found CCs : ${STDGPU_RUN_OUTPUT_VAR})")
    set(STDGPU_CUDA_HAVE_GPUS TRUE CACHE BOOL "Whether CUDA-capable GPUs are present")
    set(STDGPU_CUDA_COMPUTE_CAPABILITIES ${STDGPU_RUN_OUTPUT_VAR} CACHE STRING "Compute capabilities of CUDA-capable GPUs")
    mark_as_advanced(STDGPU_CUDA_COMPUTE_CAPABILITIES)
elseif(NOT STDGPU_COMPILE_RESULT_VAR)
    message(STATUS "Detecting CCs of GPUs : ${STDGPU_CUDA_COMPUTE_CAPABILITIES_SOURCE} - Failed to compile")
    set(STDGPU_CUDA_HAVE_GPUS FALSE CACHE BOOL "Whether CUDA-capable GPUs are present")
else()
    message(STATUS "Detecting CCs of GPUs : ${STDGPU_CUDA_COMPUTE_CAPABILITIES_SOURCE} - No CUDA-capable GPU found")
    set(STDGPU_CUDA_HAVE_GPUS FALSE CACHE BOOL "Whether CUDA-capable GPUs are present")
endif()