CMS 3D CMS Logo

chooseDevice.cc
Go to the documentation of this file.
4 
5 #include "chooseDevice.h"
6 
7 namespace cms::cuda {
9  edm::Service<CUDAService> cudaService;
10  if (not cudaService->enabled()) {
11  cms::Exception ex("CUDAError");
12  ex << "Unable to choose current device because CUDAService is disabled. If CUDAService was not explicitly\n"
13  "disabled in the configuration, the probable cause is that there is no GPU or there is some problem\n"
14  "in the CUDA runtime or drivers.";
15  ex.addContext("Calling cms::cuda::chooseDevice()");
16  throw ex;
17  }
18 
19  // For startes we "statically" assign the device based on
20  // edm::Stream number. This is suboptimal if the number of
21  // edm::Streams is not a multiple of the number of CUDA devices
22  // (and even then there is no load balancing).
23  //
24  // TODO: improve the "assignment" logic
25  return id % cudaService->numberOfDevices();
26  }
27 } // namespace cms::cuda
int numberOfDevices() const
Definition: CUDAService.h:24
int chooseDevice(edm::StreamID id)
Definition: chooseDevice.cc:8
void addContext(std::string const &context)
Definition: Exception.cc:165
bool enabled() const
Definition: CUDAService.h:22