GENIE
init.cu
Go to the documentation of this file.
1 #include "init.h"
4 
5 using namespace genie;
6 
8 {
9  static bool initialized = false;
10  static uint32_t current_gpu_id = 0;
11  uint32_t new_gpu_id = config.GetGpuId();
12  if (!initialized || new_gpu_id != current_gpu_id)
13  {
14  int device_count;
15 
16  CUDA_CHECK_ERROR(cudaGetDeviceCount(&device_count));
17  if (device_count == 0)
18  {
19  throw genie::exception::cpu_runtime_error("Nvidia CUDA-supported GPU not found.");
20  }
21  else if (device_count <= new_gpu_id)
22  {
23  Logger::log(Logger::INFO,
24  "[Info] Device %d not found! Changing to %d...",
25  new_gpu_id, 0);
26  new_gpu_id = 0;
27  config.SetGpuId(0);
28  }
29  CUDA_CHECK_ERROR(cudaSetDevice(new_gpu_id));
30  current_gpu_id = new_gpu_id;
31 
32  initialized = true;
33  }
34 }
Config & SetGpuId(const uint8_t gpu_id)
Set the ID of the GPU used.
Definition: config.cc:62
uint8_t GetGpuId() const
Return the ID of the GPU used.
Definition: config.cc:30
This is the top-level namespace of the project.
void Init(genie::Config &config)
Definition: init.cu:7
Config class holds all user configurable settings of GENIE.
Definition: config.h:20
#define CUDA_CHECK_ERROR(err)
Definition: cuda_macros.h:24