CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
14 #include "grpc_client.h"
15 
16 //forward declarations
17 namespace edm {
18  class ActivityRegistry;
20  class PathsAndConsumesOfModulesBase;
21  class ProcessContext;
22  class ModuleDescription;
23 } // namespace edm
24 
25 enum class TritonServerType { Remote = 0, LocalCPU = 1, LocalGPU = 2 };
26 
28 public:
29  //classes and defs
30  struct FallbackOpts {
32  : enable(pset.getUntrackedParameter<bool>("enable")),
33  debug(pset.getUntrackedParameter<bool>("debug")),
34  verbose(pset.getUntrackedParameter<bool>("verbose")),
35  useDocker(pset.getUntrackedParameter<bool>("useDocker")),
36  useGPU(pset.getUntrackedParameter<bool>("useGPU")),
37  retries(pset.getUntrackedParameter<int>("retries")),
38  wait(pset.getUntrackedParameter<int>("wait")),
39  instanceName(pset.getUntrackedParameter<std::string>("instanceName")),
40  tempDir(pset.getUntrackedParameter<std::string>("tempDir")),
41  imageName(pset.getUntrackedParameter<std::string>("imageName")),
42  sandboxName(pset.getUntrackedParameter<std::string>("sandboxName")) {
43  //randomize instance name
44  if (instanceName.empty()) {
45  instanceName =
46  pset.getUntrackedParameter<std::string>("instanceBaseName") + "_" + edm::createGlobalIdentifier();
47  }
48  }
49 
50  bool enable;
51  bool debug;
52  bool verbose;
53  bool useDocker;
54  bool useGPU;
55  int retries;
56  int wait;
61  };
62  struct Server {
64  : url(pset.getUntrackedParameter<std::string>("address") + ":" +
65  std::to_string(pset.getUntrackedParameter<unsigned>("port"))),
66  isFallback(pset.getUntrackedParameter<std::string>("name") == fallbackName),
67  useSsl(pset.getUntrackedParameter<bool>("useSsl")),
69  if (useSsl) {
70  sslOptions.root_certificates = pset.getUntrackedParameter<std::string>("rootCertificates");
71  sslOptions.private_key = pset.getUntrackedParameter<std::string>("privateKey");
72  sslOptions.certificate_chain = pset.getUntrackedParameter<std::string>("certificateChain");
73  }
74  }
75  Server(const std::string& name_, const std::string& url_, TritonServerType type_)
76  : url(url_), isFallback(name_ == fallbackName), useSsl(false), type(type_) {}
77 
78  //members
80  bool isFallback;
81  bool useSsl;
83  triton::client::SslOptions sslOptions;
84  std::unordered_set<std::string> models;
85  static const std::string fallbackName;
87  };
88  struct Model {
89  Model(const std::string& path_ = "") : path(path_) {}
90 
91  //members
93  std::unordered_set<std::string> servers;
94  std::unordered_set<unsigned> modules;
95  };
96  struct Module {
97  //currently assumes that a module can only have one associated model
98  Module(const std::string& model_) : model(model_) {}
99 
100  //members
102  };
103 
105  ~TritonService() = default;
106 
107  //accessors
108  void addModel(const std::string& modelName, const std::string& path);
109  Server serverInfo(const std::string& model, const std::string& preferred = "") const;
110  const std::string& pid() const { return pid_; }
111 
112  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
113 
114 private:
119 
120  bool verbose_;
126  std::unordered_map<std::string, Model> unservedModels_;
127  //this represents a many:many:many map
128  std::unordered_map<std::string, Server> servers_;
129  std::unordered_map<std::string, Model> models_;
130  std::unordered_map<unsigned, Module> modules_;
131 };
132 
133 #endif
T getUntrackedParameter(std::string const &, T const &) const
std::unordered_map< std::string, Model > models_
std::unordered_set< unsigned > modules
Definition: TritonService.h:94
Server serverInfo(const std::string &model, const std::string &preferred="") 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:75
unsigned currentModuleId_
Model(const std::string &path_="")
Definition: TritonService.h:89
triton::client::SslOptions sslOptions
Definition: TritonService.h:83
std::unordered_set< std::string > servers
Definition: TritonService.h:93
TritonService(const edm::ParameterSet &pset, edm::ActivityRegistry &areg)
static const std::string fallbackAddress
Definition: TritonService.h:86
Module(const std::string &model_)
Definition: TritonService.h:98
void addModel(const std::string &modelName, const std::string &path)
Server(const edm::ParameterSet &pset)
Definition: TritonService.h:63
FallbackOpts fallbackOpts_
std::unordered_set< std::string > models
Definition: TritonService.h:84
FallbackOpts(const edm::ParameterSet &pset)
Definition: TritonService.h:31
std::string pid_
void preBeginJob(edm::PathsAndConsumesOfModulesBase const &, edm::ProcessContext const &)
void preModuleConstruction(edm::ModuleDescription const &)
areg
Definition: Schedule.cc:687
std::string createGlobalIdentifier(bool binary=false)
void preModuleDestruction(edm::ModuleDescription const &)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::unordered_map< unsigned, Module > modules_
std::string & path_
TritonServerType type
Definition: TritonService.h:82
TritonServerType
Definition: TritonService.h:25
const std::string & pid() const
std::unordered_map< std::string, Server > servers_
static const std::string fallbackName
Definition: TritonService.h:85