OmniSciDB  a667adc9c8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 24 of file get_nvidia_compute_capability.h.

References to_string().

Referenced by main().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function: