CMS 3D CMS Logo

Classes | Functions
ALPAKA_ACCELERATOR_NAMESPACE::detail Namespace Reference

Classes

struct  DeviceProductType
 
class  EDMetadataAcquireSentry
 
class  EDMetadataSentry
 
class  ESDeviceProductWithStorage
 

Functions

Device const & chooseDevice (edm::StreamID id)
 

Function Documentation

◆ chooseDevice()

Device const & ALPAKA_ACCELERATOR_NAMESPACE::detail::chooseDevice ( edm::StreamID  id)

Definition at line 9 of file chooseDevice.cc.

References cms::Exception::addContext(), cms::alpakatools::devices(), EDM_STRINGIZE, and ALPAKA_ACCELERATOR_NAMESPACE::AlpakaService::enabled().

Referenced by ALPAKA_ACCELERATOR_NAMESPACE::detail::EDMetadataSentry::EDMetadataSentry().

9  {
10  // The idea of checking the AlpakaService status here is that
11  // regardless of process.options.accelerators setting the
12  // configuration may contain an EDModule for a specific Alpaka
13  // backend. Checking the AlpakaService status here ensures that an
14  // explanatory error messages even in that case. The information
15  // on the intended accelerators is (eventually) communicated from
16  // process.options.accelerators to AlpakaServices via
17  // ProcessAcceleratorAlpaka.
19  if (not alpakaService->enabled()) {
20  cms::Exception ex("AlpakaError");
21  ex << "Unable to choose current device because AlpakaService is disabled. If AlpakaService was not explicitly\n"
22  "disabled in the configuration, the probable cause is that there is no GPU or there is some problem\n"
23  "in the platform runtime or drivers.";
24  ex.addContext("Calling " EDM_STRINGIZE(ALPAKA_ACCELERATOR_NAMESPACE) "::detail::chooseDevice()");
25  throw ex;
26  };
27 
28  // For startes we "statically" assign the device based on
29  // edm::Stream number. This is suboptimal if the number of
30  // edm::Streams is not a multiple of the number of devices
31  // (and even then there is no load balancing).
32 
33  // TODO: improve the "assignment" logic
34  auto const& devices = cms::alpakatools::devices<Platform>();
35  return devices[id % devices.size()];
36  }
#define EDM_STRINGIZE(token)
Definition: stringize.h:6
std::vector< alpaka::Dev< TPlatform > > const & devices()
Definition: devices.h:36