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 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;
62  };
63  struct Server {
65  : url(pset.getUntrackedParameter<std::string>("address") + ":" +
66  std::to_string(pset.getUntrackedParameter<unsigned>("port"))),
67  isFallback(pset.getUntrackedParameter<std::string>("name") == fallbackName),
68  useSsl(pset.getUntrackedParameter<bool>("useSsl")),
70  if (useSsl) {
71  sslOptions.root_certificates = pset.getUntrackedParameter<std::string>("rootCertificates");
72  sslOptions.private_key = pset.getUntrackedParameter<std::string>("privateKey");
73  sslOptions.certificate_chain = pset.getUntrackedParameter<std::string>("certificateChain");
74  }
75  }
76  Server(const std::string& name_, const std::string& url_, TritonServerType type_)
77  : url(url_), isFallback(name_ == fallbackName), useSsl(false), type(type_) {}
78 
79  //members
81  bool isFallback;
82  bool useSsl;
84  triton::client::SslOptions sslOptions;
85  std::unordered_set<std::string> models;
86  static const std::string fallbackName;
88  };
89  struct Model {
90  Model(const std::string& path_ = "") : path(path_) {}
91 
92  //members
94  std::unordered_set<std::string> servers;
95  std::unordered_set<unsigned> modules;
96  };
97  struct Module {
98  //currently assumes that a module can only have one associated model
99  Module(const std::string& model_) : model(model_) {}
100 
101  //members
103  };
104 
106  ~TritonService() = default;
107 
108  //accessors
109  void addModel(const std::string& modelName, const std::string& path);
110  Server serverInfo(const std::string& model, const std::string& preferred = "") const;
111  const std::string& pid() const { return pid_; }
112 
113  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
114 
115 private:
120  void postEndJob();
121 
122  //helper
123  template <typename LOG>
124  void printFallbackServerLog() const;
125 
126  bool verbose_;
132  std::unordered_map<std::string, Model> unservedModels_;
133  //this represents a many:many:many map
134  std::unordered_map<std::string, Server> servers_;
135  std::unordered_map<std::string, Model> models_;
136  std::unordered_map<unsigned, Module> modules_;
137 };
138 
139 #endif
std::unordered_map< std::string, Model > models_
const std::string & pid() const
std::unordered_set< unsigned > modules
Definition: TritonService.h:95
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:76
unsigned currentModuleId_
Model(const std::string &path_="")
Definition: TritonService.h:90
triton::client::SslOptions sslOptions
Definition: TritonService.h:84
std::unordered_set< std::string > servers
Definition: TritonService.h:94
TritonService(const edm::ParameterSet &pset, edm::ActivityRegistry &areg)
static const std::string fallbackAddress
Definition: TritonService.h:87
Module(const std::string &model_)
Definition: TritonService.h:99
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:64
FallbackOpts fallbackOpts_
std::unordered_set< std::string > models
Definition: TritonService.h:85
FallbackOpts(const edm::ParameterSet &pset)
Definition: TritonService.h:31
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:83
HLT enums.
Server serverInfo(const std::string &model, const std::string &preferred="") const
TritonServerType
Definition: TritonService.h:25
std::unordered_map< std::string, Server > servers_
static const std::string fallbackName
Definition: TritonService.h:86