CMS 3D CMS Logo

AlpakaService.cc
Go to the documentation of this file.
1 #include <boost/core/demangle.hpp>
2 
3 #include <alpaka/alpaka.hpp>
4 
16 
17 #ifdef ALPAKA_ACC_GPU_CUDA_ENABLED
20 #endif // ALPAKA_ACC_GPU_CUDA_ENABLED
21 
23 
25  : enabled_(config.getUntrackedParameter<bool>("enabled")),
26  verbose_(config.getUntrackedParameter<bool>("verbose")) {
27 #ifdef ALPAKA_ACC_GPU_CUDA_ENABLED
28  // rely on the CUDAService to initialise the CUDA devices
29  edm::Service<CUDAService> cudaService;
30 #endif // ALPAKA_ACC_GPU_CUDA_ENABLED
31 
32  // TODO from Andrea Bocci:
33  // - handle alpaka caching allocators ?
34  // - extract and print more information about the platform and devices
35 
36  if (not enabled_) {
37  edm::LogInfo("AlpakaService") << ALPAKA_TYPE_ALIAS_NAME(AlpakaService) << " disabled by configuration";
38  return;
39  }
40 
41 #ifdef ALPAKA_ACC_GPU_CUDA_ENABLED
42  if (not cudaService->enabled()) {
43  enabled_ = false;
44  edm::LogInfo("AlpakaService") << ALPAKA_TYPE_ALIAS_NAME(AlpakaService) << " disabled by CUDAService";
45  return;
46  }
47 #endif // ALPAKA_ACC_GPU_CUDA_ENABLED
48 
49  // enumerate all devices on this platform
50  auto const& devices = cms::alpakatools::devices<Platform>();
51  if (devices.empty()) {
52  const std::string platform = boost::core::demangle(typeid(Platform).name());
53  edm::LogWarning("AlpakaService") << "Could not find any devices on platform " << platform << ".\n"
54  << "Disabling " << ALPAKA_TYPE_ALIAS_NAME(AlpakaService) << ".";
55  enabled_ = false;
56  return;
57  }
58 
59  {
60  const char* suffix[] = {"s.", ":", "s:"};
61  const auto n = devices.size();
62  edm::LogInfo out("AlpakaService");
63  out << ALPAKA_TYPE_ALIAS_NAME(AlpakaService) << " succesfully initialised.\n";
64  out << "Found " << n << " device" << suffix[n < 2 ? n : 2];
65  for (auto const& device : devices) {
66  out << "\n - " << alpaka::getName(device);
67  }
68  }
69 
70  // initialise the queue and event caches
71  cms::alpakatools::getQueueCache<Queue>().clear();
72  cms::alpakatools::getEventCache<Event>().clear();
73 
74  // initialise the caching memory allocators
75  cms::alpakatools::getHostCachingAllocator<Queue>();
76  for (auto const& device : devices)
77  cms::alpakatools::getDeviceCachingAllocator<Device, Queue>(device);
78  }
79 
81  // clean up the caching memory allocators
82  cms::alpakatools::getHostCachingAllocator<Queue>().freeAllCached();
83  for (auto const& device : cms::alpakatools::devices<Platform>())
84  cms::alpakatools::getDeviceCachingAllocator<Device, Queue>(device).freeAllCached();
85 
86  // clean up the queue and event caches
87  cms::alpakatools::getQueueCache<Queue>().clear();
88  cms::alpakatools::getEventCache<Event>().clear();
89  }
90 
93  desc.addUntracked<bool>("enabled", true);
94  desc.addUntracked<bool>("verbose", false);
95 
96  descriptions.add(ALPAKA_TYPE_ALIAS_NAME(AlpakaService), desc);
97  }
98 
99 } // namespace ALPAKA_ACCELERATOR_NAMESPACE
AlpakaService(edm::ParameterSet const &config, edm::ActivityRegistry &)
Definition: config.py:1
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Log< level::Info, false > LogInfo
TString getName(TString structure, int layer, TString geometry)
Definition: DMRtrends.cc:236
void add(std::string const &label, ParameterSetDescription const &psetDescription)
bool enabled() const
Definition: CUDAService.h:22
std::vector< alpaka::Dev< TPlatform > > const & devices()
Definition: devices.h:36
void clear(EGIsoObj &c)
Definition: egamma.h:82
Log< level::Warning, false > LogWarning