Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-11-24 00:02:23

0001 #include "FWCore/ServiceRegistry/interface/Service.h"
0002 #include "FWCore/Utilities/interface/Exception.h"
0003 #include "FWCore/Utilities/interface/stringize.h"
0004 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/chooseDevice.h"
0005 #include "HeterogeneousCore/AlpakaInterface/interface/devices.h"
0006 #include "HeterogeneousCore/AlpakaServices/interface/alpaka/AlpakaService.h"
0007 
0008 namespace ALPAKA_ACCELERATOR_NAMESPACE::detail {
0009   Device const& chooseDevice(edm::StreamID id) {
0010     // The idea of checking the AlpakaService status here is that
0011     // regardless of process.options.accelerators setting the
0012     // configuration may contain an EDModule for a specific Alpaka
0013     // backend. Checking the AlpakaService status here ensures that an
0014     // explanatory error messages even in that case. The information
0015     // on the intended accelerators is (eventually) communicated from
0016     // process.options.accelerators to AlpakaServices via
0017     // ProcessAcceleratorAlpaka.
0018     edm::Service<ALPAKA_ACCELERATOR_NAMESPACE::AlpakaService> alpakaService;
0019     if (not alpakaService->enabled()) {
0020       cms::Exception ex("AlpakaError");
0021       ex << "Unable to choose current device because AlpakaService is disabled. If AlpakaService was not explicitly\n"
0022             "disabled in the configuration, the probable cause is that there is no GPU or there is some problem\n"
0023             "in the platform runtime or drivers.";
0024       ex.addContext("Calling " EDM_STRINGIZE(ALPAKA_ACCELERATOR_NAMESPACE) "::detail::chooseDevice()");
0025       throw ex;
0026     };
0027 
0028     // For startes we "statically" assign the device based on
0029     // edm::Stream number. This is suboptimal if the number of
0030     // edm::Streams is not a multiple of the number of devices
0031     // (and even then there is no load balancing).
0032 
0033     // TODO: improve the "assignment" logic
0034     auto const& devices = cms::alpakatools::devices<Platform>();
0035     return devices[id % devices.size()];
0036   }
0037 }  // namespace ALPAKA_ACCELERATOR_NAMESPACE::detail