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 
22 #ifdef ALPAKA_ACC_GPU_HIP_ENABLED
25 #endif // ALPAKA_ACC_GPU_HIP_ENABLED
26 
28 
30  : enabled_(config.getUntrackedParameter<bool>("enabled")),
31  verbose_(config.getUntrackedParameter<bool>("verbose")) {
32 #ifdef ALPAKA_ACC_GPU_CUDA_ENABLED
33  // rely on the CUDAService to initialise the CUDA devices
35 #endif // ALPAKA_ACC_GPU_CUDA_ENABLED
36 #ifdef ALPAKA_ACC_GPU_HIP_ENABLED
37  // rely on the ROCmService to initialise the ROCm devices
39 #endif // ALPAKA_ACC_GPU_HIP_ENABLED
40 
41  // TODO from Andrea Bocci:
42  // - handle alpaka caching allocators ?
43  // - extract and print more information about the platform and devices
44 
45  if (not enabled_) {
46  edm::LogInfo("AlpakaService") << ALPAKA_TYPE_ALIAS_NAME(AlpakaService) << " disabled by configuration";
47  return;
48  }
49 
50 #ifdef ALPAKA_ACC_GPU_CUDA_ENABLED
51  if (not cuda or not cuda->enabled()) {
52  enabled_ = false;
53  edm::LogInfo("AlpakaService") << ALPAKA_TYPE_ALIAS_NAME(AlpakaService) << " disabled by CUDAService";
54  return;
55  }
56 #endif // ALPAKA_ACC_GPU_CUDA_ENABLED
57 #ifdef ALPAKA_ACC_GPU_HIP_ENABLED
58  if (not rocm or not rocm->enabled()) {
59  enabled_ = false;
60  edm::LogInfo("AlpakaService") << ALPAKA_TYPE_ALIAS_NAME(AlpakaService) << " disabled by ROCmService";
61  return;
62  }
63 #endif // ALPAKA_ACC_GPU_HIP_ENABLED
64 
65  // enumerate all devices on this platform
66  auto const& devices = cms::alpakatools::devices<Platform>();
67  if (devices.empty()) {
68  const std::string platform = boost::core::demangle(typeid(Platform).name());
69  edm::LogWarning("AlpakaService") << "Could not find any devices on platform " << platform << ".\n"
70  << "Disabling " << ALPAKA_TYPE_ALIAS_NAME(AlpakaService) << ".";
71  enabled_ = false;
72  return;
73  }
74 
75  {
76  const char* suffix[] = {"s.", ":", "s:"};
77  const auto n = devices.size();
78  edm::LogInfo out("AlpakaService");
79  out << ALPAKA_TYPE_ALIAS_NAME(AlpakaService) << " succesfully initialised.\n";
80  out << "Found " << n << " device" << suffix[n < 2 ? n : 2];
81  for (auto const& device : devices) {
82  out << "\n - " << alpaka::getName(device);
83  }
84  }
85 
86  // initialise the queue and event caches
87  cms::alpakatools::getQueueCache<Queue>().clear();
88  cms::alpakatools::getEventCache<Event>().clear();
89 
90  // initialise the caching memory allocators
91  cms::alpakatools::getHostCachingAllocator<Queue>();
92  for (auto const& device : devices)
93  cms::alpakatools::getDeviceCachingAllocator<Device, Queue>(device);
94  }
95 
97  // clean up the caching memory allocators
98  cms::alpakatools::getHostCachingAllocator<Queue>().freeAllCached();
99  for (auto const& device : cms::alpakatools::devices<Platform>())
100  cms::alpakatools::getDeviceCachingAllocator<Device, Queue>(device).freeAllCached();
101 
102  // clean up the queue and event caches
103  cms::alpakatools::getQueueCache<Queue>().clear();
104  cms::alpakatools::getEventCache<Event>().clear();
105  }
106 
109  desc.addUntracked<bool>("enabled", true);
110  desc.addUntracked<bool>("verbose", false);
111 
112  descriptions.add(ALPAKA_TYPE_ALIAS_NAME(AlpakaService), desc);
113  }
114 
115 } // namespace ALPAKA_ACCELERATOR_NAMESPACE
AlpakaService(edm::ParameterSet const &config, edm::ActivityRegistry &)
Definition: config.py:1
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
Log< level::Info, false > LogInfo
void add(std::string const &label, ParameterSetDescription const &psetDescription)
virtual bool enabled() const =0
std::vector< alpaka::Dev< TPlatform > > const & devices()
Definition: devices.h:35
std::string getName(const G4String &)
Definition: ForwardName.cc:3
void clear(EGIsoObj &c)
Definition: egamma.h:82
Log< level::Warning, false > LogWarning