File: CUDACheckCompute.cmake

package info (click to toggle)
arrayfire 3.3.2%2Bdfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 109,016 kB
  • sloc: cpp: 127,909; lisp: 6,878; python: 3,923; ansic: 1,051; sh: 347; makefile: 338; xml: 175
file content (38 lines) | stat: -rw-r--r-- 1,660 bytes parent folder | download
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
30
31
32
33
34
35
36
37
38
#############################
#Sourced from:
#https://raw.githubusercontent.com/jwetzl/CudaLBFGS/master/CheckComputeCapability.cmake
#############################
# 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)

IF(CUDA_FOUND)
    MESSAGE(STATUS "${CMAKE_MODULE_PATH}/cuda_compute_capability.cpp")

    TRY_RUN(RUN_RESULT_VAR COMPILE_RESULT_VAR
        ${CMAKE_BINARY_DIR}
        ${CMAKE_MODULE_PATH}/cuda_compute_capability.cpp
        CMAKE_FLAGS
        -DINCLUDE_DIRECTORIES:STRING=${CUDA_TOOLKIT_INCLUDE}
        -DLINK_LIBRARIES:STRING=${CUDA_CUDART_LIBRARY}
        COMPILE_OUTPUT_VARIABLE COMPILE_OUTPUT_VAR
        RUN_OUTPUT_VARIABLE RUN_OUTPUT_VAR)

    MESSAGE(STATUS "CUDA Compute Detection Output: ${RUN_OUTPUT_VAR}")
    MESSAGE(STATUS "CUDA Compute Detection Return: ${RUN_RESULT_VAR}")

    # COMPILE_RESULT_VAR is TRUE when compile succeeds
    # Check Return Value of main() from RUN_RESULT_VAR
    # RUN_RESULT_VAR is 0 when a GPU is found
    # RUN_RESULT_VAR is 1 when errors occur

    IF(COMPILE_RESULT_VAR AND RUN_RESULT_VAR EQUAL 0)
        MESSAGE(STATUS "CUDA Compute Detection Worked")
        # Convert output into a list of computes
        STRING(REPLACE " " ";" COMPUTES_DETECTED_LIST ${RUN_OUTPUT_VAR})
        SET(CUDA_HAVE_GPU TRUE CACHE BOOL "Whether CUDA-capable GPU is present")
    ELSE()
        MESSAGE(STATUS "CUDA Compute Detection Failed")
        SET(CUDA_HAVE_GPU FALSE CACHE BOOL "Whether CUDA-capable GPU is present")
    ENDIF()

ENDIF(CUDA_FOUND)