OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
get_nvidia_compute_capability.h File Reference
#include <cassert>
#include <stdexcept>
#include <string>
#include <vector>
#include <cuda_runtime.h>
+ Include dependency graph for get_nvidia_compute_capability.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

std::vector< size_t > get_nvidia_compute_capability ()
 

Function Documentation

std::vector<size_t> get_nvidia_compute_capability ( )
inline

Definition at line 26 of file get_nvidia_compute_capability.h.

References to_string().

Referenced by main().

26  {
27  using namespace std::string_literals;
28  std::vector<size_t> ret;
29 
30  int deviceCount = 0;
31  cudaError_t error_id = cudaGetDeviceCount(&deviceCount);
32 
33  if (error_id != cudaSuccess) {
34  throw std::runtime_error("cudaGetDeviceCount failed: "s + std::to_string(error_id) +
35  ": "s + cudaGetErrorString(error_id));
36  }
37 
38  for (int dev = 0; dev < deviceCount; ++dev) {
39  cudaSetDevice(dev);
40  cudaDeviceProp deviceProp;
41  cudaGetDeviceProperties(&deviceProp, dev);
42 
43  if (deviceProp.major <= 0) {
44  throw std::runtime_error("unexpected cuda compute capability: major "s +
45  std::to_string(deviceProp.major));
46  }
47  if (deviceProp.minor < 0) {
48  throw std::runtime_error("unexpected cuda compute capability: minor "s +
49  std::to_string(deviceProp.minor));
50  }
51 
52  if (deviceProp.major >= 10) {
53  throw std::runtime_error("unexpected cuda compute capability: major "s +
54  std::to_string(deviceProp.major));
55  }
56  if (deviceProp.minor >= 10) {
57  throw std::runtime_error("unexpected cuda compute capability: minor "s +
58  std::to_string(deviceProp.minor));
59  }
60 
61  ret.push_back((deviceProp.major * 10U) + deviceProp.minor);
62  }
63 
64  return ret;
65 }
std::string to_string(char const *&&v)

+ Here is the call graph for this function:

+ Here is the caller graph for this function: