CMS 3D CMS Logo

TritonService.h
Go to the documentation of this file.
1 #ifndef HeterogeneousCore_SonicTriton_TritonService
2 #define HeterogeneousCore_SonicTriton_TritonService
3 
6 
7 #include <vector>
8 #include <unordered_set>
9 #include <unordered_map>
10 #include <string>
11 #include <functional>
12 #include <utility>
13 #include <atomic>
14 
15 #include "grpc_client.h"
16 
17 //forward declarations
18 namespace edm {
19  class ActivityRegistry;
21  class PathsAndConsumesOfModulesBase;
22  class ProcessContext;
23  class ModuleDescription;
24  namespace service {
25  class SystemBounds;
26  }
27 } // namespace edm
28 
29 enum class TritonServerType { Remote = 0, LocalCPU = 1, LocalGPU = 2 };
30 
32 public:
33  //classes and defs
34  struct FallbackOpts {
36  : enable(pset.getUntrackedParameter<bool>("enable")),
37  debug(pset.getUntrackedParameter<bool>("debug")),
38  verbose(pset.getUntrackedParameter<bool>("verbose")),
39  container(pset.getUntrackedParameter<std::string>("container")),
40  device(pset.getUntrackedParameter<std::string>("device")),
41  retries(pset.getUntrackedParameter<int>("retries")),
42  wait(pset.getUntrackedParameter<int>("wait")),
43  instanceName(pset.getUntrackedParameter<std::string>("instanceName")),
44  tempDir(pset.getUntrackedParameter<std::string>("tempDir")),
45  imageName(pset.getUntrackedParameter<std::string>("imageName")),
46  sandboxName(pset.getUntrackedParameter<std::string>("sandboxName")) {
47  //randomize instance name
48  if (instanceName.empty()) {
49  instanceName =
50  pset.getUntrackedParameter<std::string>("instanceBaseName") + "_" + edm::createGlobalIdentifier();
51  }
52  }
53 
54  bool enable;
55  bool debug;
56  bool verbose;
59  int retries;
60  int wait;
66  };
67  struct Server {
69  : url(pset.getUntrackedParameter<std::string>("address") + ":" +
70  std::to_string(pset.getUntrackedParameter<unsigned>("port"))),
71  isFallback(pset.getUntrackedParameter<std::string>("name") == fallbackName),
72  useSsl(pset.getUntrackedParameter<bool>("useSsl")),
74  if (useSsl) {
75  sslOptions.root_certificates = pset.getUntrackedParameter<std::string>("rootCertificates");
76  sslOptions.private_key = pset.getUntrackedParameter<std::string>("privateKey");
77  sslOptions.certificate_chain = pset.getUntrackedParameter<std::string>("certificateChain");
78  }
79  }
80  Server(const std::string& name_, const std::string& url_, TritonServerType type_)
81  : url(url_), isFallback(name_ == fallbackName), useSsl(false), type(type_) {}
82 
83  //members
85  bool isFallback;
86  bool useSsl;
88  triton::client::SslOptions sslOptions;
89  std::unordered_set<std::string> models;
90  static const std::string fallbackName;
92  static const std::string siteconfName;
93  };
94  struct Model {
95  Model(const std::string& path_ = "") : path(path_) {}
96 
97  //members
99  std::unordered_set<std::string> servers;
100  std::unordered_set<unsigned> modules;
101  };
102  struct Module {
103  //currently assumes that a module can only have one associated model
104  Module(const std::string& model_) : model(model_) {}
105 
106  //members
108  };
109 
111  ~TritonService() = default;
112 
113  //accessors
114  void addModel(const std::string& modelName, const std::string& path);
115  Server serverInfo(const std::string& model, const std::string& preferred = "") const;
116  const std::string& pid() const { return pid_; }
117  void notifyCallStatus(bool status) const;
118 
119  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
120 
121 private:
127  void postEndJob();
128 
129  //helper
130  template <typename LOG>
131  void printFallbackServerLog() const;
132 
133  bool verbose_;
138  mutable std::atomic<int> callFails_;
140  std::unordered_map<std::string, Model> unservedModels_;
141  //this represents a many:many:many map
142  std::unordered_map<std::string, Server> servers_;
143  std::unordered_map<std::string, Model> models_;
144  std::unordered_map<unsigned, Module> modules_;
146 };
147 
148 #endif
std::unordered_map< std::string, Model > models_
const std::string & pid() const
std::unordered_set< unsigned > modules
static const std::string siteconfName
Definition: TritonService.h:92
void notifyCallStatus(bool status) const
std::unordered_map< std::string, Model > unservedModels_
~TritonService()=default
void postModuleConstruction(edm::ModuleDescription const &)
Server(const std::string &name_, const std::string &url_, TritonServerType type_)
Definition: TritonService.h:80
unsigned currentModuleId_
void preallocate(edm::service::SystemBounds const &)
Model(const std::string &path_="")
Definition: TritonService.h:95
triton::client::SslOptions sslOptions
Definition: TritonService.h:88
std::unordered_set< std::string > servers
Definition: TritonService.h:99
TritonService(const edm::ParameterSet &pset, edm::ActivityRegistry &areg)
static const std::string fallbackAddress
Definition: TritonService.h:91
Module(const std::string &model_)
static std::string to_string(const XMLCh *ch)
void addModel(const std::string &modelName, const std::string &path)
Server(const edm::ParameterSet &pset)
Definition: TritonService.h:68
FallbackOpts fallbackOpts_
std::unordered_set< std::string > models
Definition: TritonService.h:89
FallbackOpts(const edm::ParameterSet &pset)
Definition: TritonService.h:35
std::string pid_
void preBeginJob(edm::PathsAndConsumesOfModulesBase const &, edm::ProcessContext const &)
void printFallbackServerLog() const
void preModuleConstruction(edm::ModuleDescription const &)
std::string createGlobalIdentifier(bool binary=false)
void preModuleDestruction(edm::ModuleDescription const &)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::unordered_map< unsigned, Module > modules_
std::atomic< int > callFails_
std::string & path_
TritonServerType type
Definition: TritonService.h:87
HLT enums.
Server serverInfo(const std::string &model, const std::string &preferred="") const
TritonServerType
Definition: TritonService.h:29
std::unordered_map< std::string, Server > servers_
static const std::string fallbackName
Definition: TritonService.h:90