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 
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 service {
24  class SystemBounds;
25  }
26 } // namespace edm
27 
28 enum class TritonServerType { Remote = 0, LocalCPU = 1, LocalGPU = 2 };
29 
31 public:
32  //classes and defs
33  struct FallbackOpts {
35  : enable(pset.getUntrackedParameter<bool>("enable")),
36  debug(pset.getUntrackedParameter<bool>("debug")),
37  verbose(pset.getUntrackedParameter<bool>("verbose")),
38  useDocker(pset.getUntrackedParameter<bool>("useDocker")),
39  useGPU(pset.getUntrackedParameter<bool>("useGPU")),
40  retries(pset.getUntrackedParameter<int>("retries")),
41  wait(pset.getUntrackedParameter<int>("wait")),
42  instanceName(pset.getUntrackedParameter<std::string>("instanceName")),
43  tempDir(pset.getUntrackedParameter<std::string>("tempDir")),
44  imageName(pset.getUntrackedParameter<std::string>("imageName")),
45  sandboxName(pset.getUntrackedParameter<std::string>("sandboxName")) {
46  //randomize instance name
47  if (instanceName.empty()) {
48  instanceName =
49  pset.getUntrackedParameter<std::string>("instanceBaseName") + "_" + edm::createGlobalIdentifier();
50  }
51  }
52 
53  bool enable;
54  bool debug;
55  bool verbose;
56  bool useDocker;
57  bool useGPU;
58  int retries;
59  int wait;
65  };
66  struct Server {
68  : url(pset.getUntrackedParameter<std::string>("address") + ":" +
69  std::to_string(pset.getUntrackedParameter<unsigned>("port"))),
70  isFallback(pset.getUntrackedParameter<std::string>("name") == fallbackName),
71  useSsl(pset.getUntrackedParameter<bool>("useSsl")),
73  if (useSsl) {
74  sslOptions.root_certificates = pset.getUntrackedParameter<std::string>("rootCertificates");
75  sslOptions.private_key = pset.getUntrackedParameter<std::string>("privateKey");
76  sslOptions.certificate_chain = pset.getUntrackedParameter<std::string>("certificateChain");
77  }
78  }
79  Server(const std::string& name_, const std::string& url_, TritonServerType type_)
80  : url(url_), isFallback(name_ == fallbackName), useSsl(false), type(type_) {}
81 
82  //members
84  bool isFallback;
85  bool useSsl;
87  triton::client::SslOptions sslOptions;
88  std::unordered_set<std::string> models;
89  static const std::string fallbackName;
91  };
92  struct Model {
93  Model(const std::string& path_ = "") : path(path_) {}
94 
95  //members
97  std::unordered_set<std::string> servers;
98  std::unordered_set<unsigned> modules;
99  };
100  struct Module {
101  //currently assumes that a module can only have one associated model
102  Module(const std::string& model_) : model(model_) {}
103 
104  //members
106  };
107 
109  ~TritonService() = default;
110 
111  //accessors
112  void addModel(const std::string& modelName, const std::string& path);
113  Server serverInfo(const std::string& model, const std::string& preferred = "") const;
114  const std::string& pid() const { return pid_; }
115 
116  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
117 
118 private:
124  void postEndJob();
125 
126  //helper
127  template <typename LOG>
128  void printFallbackServerLog() const;
129 
130  bool verbose_;
136  std::unordered_map<std::string, Model> unservedModels_;
137  //this represents a many:many:many map
138  std::unordered_map<std::string, Server> servers_;
139  std::unordered_map<std::string, Model> models_;
140  std::unordered_map<unsigned, Module> modules_;
142 };
143 
144 #endif
std::unordered_map< std::string, Model > models_
const std::string & pid() const
std::unordered_set< unsigned > modules
Definition: TritonService.h:98
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:79
unsigned currentModuleId_
void preallocate(edm::service::SystemBounds const &)
Model(const std::string &path_="")
Definition: TritonService.h:93
triton::client::SslOptions sslOptions
Definition: TritonService.h:87
std::unordered_set< std::string > servers
Definition: TritonService.h:97
TritonService(const edm::ParameterSet &pset, edm::ActivityRegistry &areg)
static const std::string fallbackAddress
Definition: TritonService.h:90
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:67
FallbackOpts fallbackOpts_
std::unordered_set< std::string > models
Definition: TritonService.h:88
FallbackOpts(const edm::ParameterSet &pset)
Definition: TritonService.h:34
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::string & path_
TritonServerType type
Definition: TritonService.h:86
HLT enums.
Server serverInfo(const std::string &model, const std::string &preferred="") const
TritonServerType
Definition: TritonService.h:28
std::unordered_map< std::string, Server > servers_
static const std::string fallbackName
Definition: TritonService.h:89