CMS 3D CMS Logo

Backend.cc
Go to the documentation of this file.
3 
4 #include <algorithm>
5 #include <array>
6 
7 namespace {
8  constexpr const std::array<std::string_view, static_cast<short>(cms::alpakatools::Backend::size)> backendNames = {
9  {"SerialSync", "CudaAsync", "ROCmAsync", "TbbAsync"}};
10 }
11 
12 namespace cms::alpakatools {
13  Backend toBackend(std::string_view name) {
14  auto found = std::find(backendNames.begin(), backendNames.end(), name);
15  if (found == backendNames.end()) {
16  cms::Exception ex("EnumNotFound");
17  ex << "Invalid backend name '" << name << "'";
18  ex.addContext("Calling cms::alpakatools::toBackend()");
19  throw ex;
20  }
21  return static_cast<Backend>(std::distance(backendNames.begin(), found));
22  }
23 
24  std::string_view toString(Backend backend) {
25  auto val = static_cast<unsigned short>(backend);
26  if (val >= static_cast<unsigned short>(Backend::size)) {
27  cms::Exception ex("InvalidEnumValue");
28  ex << "Invalid backend enum value " << val;
29  ex.addContext("Calling cms::alpakatools::toString()");
30  throw ex;
31  }
32  return backendNames[val];
33  }
34 } // namespace cms::alpakatools
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
std::string_view toString(Backend backend)
Definition: Backend.cc:24
Backend toBackend(std::string_view name)
Definition: Backend.cc:13
void addContext(std::string const &context)
Definition: Exception.cc:169