]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Detect CUDA compute capability
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Thu, 28 Feb 2019 01:12:22 +0000 (02:12 +0100)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Thu, 28 Feb 2019 08:39:59 +0000 (09:39 +0100)
cmake/configure/CUDAComputeCapability/cuda_compute_capability.cu [new file with mode: 0644]
cmake/configure/configure_1_cuda.cmake
doc/external-libs/cuda.html

diff --git a/cmake/configure/CUDAComputeCapability/cuda_compute_capability.cu b/cmake/configure/CUDAComputeCapability/cuda_compute_capability.cu
new file mode 100644 (file)
index 0000000..23225d4
--- /dev/null
@@ -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 <iostream>
+
+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;
+}
index ce01a3b95a340abff4f838f05a1f56de82990160..9001a941658659344458d6ab552c2e7d6a126747 100644 (file)
@@ -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
index 8ba33ae33a8836a62785a8d57100c68b749643e2..345865b6a90388007269aeffc0504952b72a7b77 100644 (file)
@@ -39,8 +39,8 @@
       </pre>
       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:
       <pre>
 
         -DDEAL_II_CUDA_FLAGS="-arch=sm_60"

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.