Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:50:23

0001 #include "FWCore/Utilities/interface/Exception.h"
0002 #include "HeterogeneousCore/AlpakaInterface/interface/Backend.h"
0003 
0004 #include <algorithm>
0005 #include <array>
0006 
0007 namespace {
0008   constexpr const std::array<std::string_view, static_cast<short>(cms::alpakatools::Backend::size)> backendNames = {
0009       {"SerialSync", "CudaAsync", "ROCmAsync", "TbbAsync"}};
0010 }
0011 
0012 namespace cms::alpakatools {
0013   Backend toBackend(std::string_view name) {
0014     auto found = std::find(backendNames.begin(), backendNames.end(), name);
0015     if (found == backendNames.end()) {
0016       cms::Exception ex("EnumNotFound");
0017       ex << "Invalid backend name '" << name << "'";
0018       ex.addContext("Calling cms::alpakatools::toBackend()");
0019       throw ex;
0020     }
0021     return static_cast<Backend>(std::distance(backendNames.begin(), found));
0022   }
0023 
0024   std::string_view toString(Backend backend) {
0025     auto val = static_cast<unsigned short>(backend);
0026     if (val >= static_cast<unsigned short>(Backend::size)) {
0027       cms::Exception ex("InvalidEnumValue");
0028       ex << "Invalid backend enum value " << val;
0029       ex.addContext("Calling cms::alpakatools::toString()");
0030       throw ex;
0031     }
0032     return backendNames[val];
0033   }
0034 }  // namespace cms::alpakatools