Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:05:44

0001 #include "FWCore/ServiceRegistry/interface/Service.h"
0002 #include "FWCore/Utilities/interface/Exception.h"
0003 #include "HeterogeneousCore/CUDAServices/interface/CUDAInterface.h"
0004 
0005 #include "chooseDevice.h"
0006 
0007 namespace cms::cuda {
0008   int chooseDevice(edm::StreamID id) {
0009     edm::Service<CUDAInterface> cuda;
0010     if (not cuda or not cuda->enabled()) {
0011       cms::Exception ex("CUDAError");
0012       ex << "Unable to choose current device because CUDAService is not preset or disabled.\n"
0013          << "If CUDAService was not explicitly disabled in the configuration, the probable\n"
0014          << "cause is that there is no GPU or there is some problem in the CUDA runtime or\n"
0015          << "drivers.";
0016       ex.addContext("Calling cms::cuda::chooseDevice()");
0017       throw ex;
0018     }
0019 
0020     // For startes we "statically" assign the device based on
0021     // edm::Stream number. This is suboptimal if the number of
0022     // edm::Streams is not a multiple of the number of CUDA devices
0023     // (and even then there is no load balancing).
0024     //
0025     // TODO: improve the "assignment" logic
0026     return id % cuda->numberOfDevices();
0027   }
0028 }  // namespace cms::cuda