From cba82d94d72867fab082b8a755f8950579c5c174 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Thu, 28 Feb 2019 02:12:22 +0100 Subject: [PATCH] Detect CUDA compute capability --- .../cuda_compute_capability.cu | 30 ++++++++++++++++ cmake/configure/configure_1_cuda.cmake | 34 +++++++++++++++++++ doc/external-libs/cuda.html | 4 +-- 3 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 cmake/configure/CUDAComputeCapability/cuda_compute_capability.cu diff --git a/cmake/configure/CUDAComputeCapability/cuda_compute_capability.cu b/cmake/configure/CUDAComputeCapability/cuda_compute_capability.cu new file mode 100644 index 0000000000..23225d4632 --- /dev/null +++ b/cmake/configure/CUDAComputeCapability/cuda_compute_capability.cu @@ -0,0 +1,30 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2019 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + +#include + +int main() +{ + cudaDeviceProp device_properties; + const cudaError_t error = cudaGetDeviceProperties(&device_properties, + /*device*/0); + if( error != cudaSuccess) + { + std::cout << "CUDA error: " << cudaGetErrorString(error) << '\n'; + return error; + } + std::cout << device_properties.major << device_properties.minor; + return 0; +} diff --git a/cmake/configure/configure_1_cuda.cmake b/cmake/configure/configure_1_cuda.cmake index ce01a3b95a..9001a94165 100644 --- a/cmake/configure/configure_1_cuda.cmake +++ b/cmake/configure/configure_1_cuda.cmake @@ -85,6 +85,40 @@ MACRO(FEATURE_CUDA_FIND_EXTERNAL var) SET(CUDA_COMPUTE_CAPABILITY "${CMAKE_MATCH_1}") ELSEIF("${DEAL_II_CUDA_FLAGS_SAVED}" MATCHES "-arch=sm_([0-9]*)") SET(CUDA_COMPUTE_CAPABILITY "${CMAKE_MATCH_1}") + ELSEIF(DEAL_II_ALLOW_PLATFORM_INTROSPECTION) + # + # Try to autodetect the CUDA Compute Capability by asking the device + # + SET(_binary_test_dir ${CMAKE_CURRENT_BINARY_DIR}/cmake/configure/CUDAComputeCapabilityWorkdir) + FILE(REMOVE_RECURSE ${_binary_test_dir}) + FILE(MAKE_DIRECTORY ${_binary_test_dir}) + + EXECUTE_PROCESS( + COMMAND ${CUDA_NVCC_EXECUTABLE} + -ccbin=${CMAKE_CXX_COMPILER} + ${CMAKE_CURRENT_SOURCE_DIR}/cmake/configure/CUDAComputeCapability/cuda_compute_capability.cu + -o cuda_compute_capability + WORKING_DIRECTORY ${_binary_test_dir} + OUTPUT_QUIET + ERROR_QUIET + ) + EXECUTE_PROCESS(COMMAND ${_binary_test_dir}/cuda_compute_capability + RESULT_VARIABLE _result + OUTPUT_VARIABLE CUDA_COMPUTE_CAPABILITY) + IF(${_result} EQUAL 0) + ADD_FLAGS(DEAL_II_CUDA_FLAGS "-arch=sm_${CUDA_COMPUTE_CAPABILITY}") + MESSAGE(STATUS "Detected CUDA Compute Capability ${CUDA_COMPUTE_CAPABILITY}") + ELSE() + MESSAGE(STATUS "Couldn't detect CUDA Compute Capability! " + "The error message was: ${CUDA_COMPUTE_CAPABILITY}") + SET(CUDA_ADDITIONAL_ERROR_STRING + ${CUDA_ADDITIONAL_ERROR_STRING} + "Couldn't detect CUDA Compute Capability! " + "The error message was: ${CUDA_COMPUTE_CAPABILITY}\n" + "Please check the return value of ${_binary_test_dir}/cuda_compute_capability." + ) + SET(${var} FALSE) + ENDIF() ELSE() # # Assume a cuda compute capability of 35 diff --git a/doc/external-libs/cuda.html b/doc/external-libs/cuda.html index 8ba33ae33a..345865b6a9 100644 --- a/doc/external-libs/cuda.html +++ b/doc/external-libs/cuda.html @@ -39,8 +39,8 @@ If you are using CUDA 9 or CUDA 10, you will need to turn off support for C++17 similarly. - By default, we assume that your GPU has compute capability 3.5 but you - can easily set your own CUDA flags: + By default, we try to detect the compute capability of your device + but you can easily set your own CUDA flags:
 
         -DDEAL_II_CUDA_FLAGS="-arch=sm_60"
-- 
2.39.5