File indexing completed on 2024-04-20 02:31:58
0001 #ifndef HeterogeneousCore_AlpakaCore_interface_chooseDevice_h
0002 #define HeterogeneousCore_AlpakaCore_interface_chooseDevice_h
0003
0004 #include <alpaka/alpaka.hpp>
0005
0006 #include "FWCore/ServiceRegistry/interface/Service.h"
0007 #include "FWCore/Utilities/interface/StreamID.h"
0008 #include "HeterogeneousCore/AlpakaInterface/interface/config.h"
0009 #include "HeterogeneousCore/AlpakaInterface/interface/devices.h"
0010 #include "HeterogeneousCore/AlpakaServices/interface/alpaka/AlpakaService.h"
0011
0012 namespace cms::alpakatools {
0013
0014 template <typename TPlatform, typename = std::enable_if_t<alpaka::isPlatform<TPlatform>>>
0015 alpaka::Dev<TPlatform> const& chooseDevice(edm::StreamID id) {
0016 edm::Service<ALPAKA_TYPE_ALIAS(AlpakaService)> service;
0017 if (not service->enabled()) {
0018 cms::Exception ex("RuntimeError");
0019 ex << "Unable to choose current device because " << ALPAKA_TYPE_ALIAS_NAME(AlpakaService) << " is disabled.\n"
0020 << "If " << ALPAKA_TYPE_ALIAS_NAME(AlpakaService) << " was not explicitly disabled in the configuration,\n"
0021 << "the probable cause is that there is no accelerator or there is some problem\n"
0022 << "with the accelerator runtime or drivers.";
0023 ex.addContext("Calling cms::alpakatools::chooseDevice()");
0024 throw ex;
0025 }
0026
0027
0028
0029
0030
0031
0032
0033 auto const& devices = cms::alpakatools::devices<TPlatform>();
0034 return devices[id % devices.size()];
0035 }
0036
0037 }
0038
0039 #endif