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  useDocker(pset.getUntrackedParameter<bool>("useDocker")),
40  useGPU(pset.getUntrackedParameter<bool>("useGPU")),
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;
57  bool useDocker;
58  bool useGPU;
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  };
93  struct Model {
94  Model(const std::string& path_ = "") : path(path_) {}
95 
96  //members
98  std::unordered_set<std::string> servers;
99  std::unordered_set<unsigned> modules;
100  };
101  struct Module {
102  //currently assumes that a module can only have one associated model
103  Module(const std::string& model_) : model(model_) {}
104 
105  //members
107  };
108 
110  ~TritonService() = default;
111 
112  //accessors
113  void addModel(const std::string& modelName, const std::string& path);
114  Server serverInfo(const std::string& model, const std::string& preferred = "") const;
115  const std::string& pid() const { return pid_; }
116  void notifyCallStatus(bool status) const;
117 
118  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
119 
120 private:
126  void postEndJob();
127 
128  //helper
129  template <typename LOG>
130  void printFallbackServerLog() const;
131 
132  bool verbose_;
137  mutable std::atomic<int> callFails_;
139  std::unordered_map<std::string, Model> unservedModels_;
140  //this represents a many:many:many map
141  std::unordered_map<std::string, Server> servers_;
142  std::unordered_map<std::string, Model> models_;
143  std::unordered_map<unsigned, Module> modules_;
145 };
146 
147 #endif
std::unordered_map< std::string, Model > models_
const std::string & pid() const
std::unordered_set< unsigned > modules
Definition: TritonService.h:99
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:94
triton::client::SslOptions sslOptions
Definition: TritonService.h:88
std::unordered_set< std::string > servers
Definition: TritonService.h:98
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