Caffe2 - C++ API
A deep learning, cross platform ML framework
inspect_gpu.cc
1 
17 #include <cuda_runtime.h>
18 
19 #include <sstream>
20 #include <vector>
21 
22 #include "c10/util/Flags.h"
23 #include "caffe2/core/common_gpu.h"
24 #include "caffe2/core/init.h"
25 #include "caffe2/core/logging.h"
26 
27 using std::vector;
28 
29 C10_DECLARE_int(caffe2_log_level);
30 
31 int main(int argc, char** argv) {
32  caffe2::GlobalInit(&argc, &argv);
34  "Inspects the GPUs on the current machine and prints out their details "
35  "provided by cuda.");
36 
37  int gpu_count;
38  CUDA_ENFORCE(cudaGetDeviceCount(&gpu_count));
39  for (int i = 0; i < gpu_count; ++i) {
40  LOG(INFO) << "Querying device ID = " << i;
42  }
43 
44  vector<vector<bool> > access_pattern;
45  CAFFE_ENFORCE(caffe2::GetCudaPeerAccessPattern(&access_pattern));
46 
47  std::stringstream sstream;
48  // Find topology
49  for (int i = 0; i < gpu_count; ++i) {
50  for (int j = 0; j < gpu_count; ++j) {
51  sstream << (access_pattern[i][j] ? "+" : "-") << " ";
52  }
53  sstream << std::endl;
54  }
55  LOG(INFO) << "Access pattern: " << std::endl << sstream.str();
56 
57  return 0;
58 }
C10_API void SetUsageMessage(const std::string &str)
Sets the usage message when a commandline tool is called with "--help".
bool GlobalInit(int *pargc, char ***pargv)
Initialize the global environment of caffe2.
Definition: init.cc:44
void DeviceQuery(const int device)
Runs a device query function and prints out the results to LOG(INFO).
Definition: common_gpu.cc:156