12 #include "grpc_client.h" 13 #include "grpc_service.pb.h" 31 auto pipe = popen((
cmd +
" 2>&1").c_str(),
"r");
32 int thisErrno = errno;
35 <<
"TritonService: popen() failed with errno " << thisErrno <<
" for command: " <<
cmd;
38 constexpr
static unsigned buffSize = 128;
39 std::array<char, buffSize>
buffer;
45 thisErrno = ferror(
pipe);
48 <<
"TritonService: failed reading command output with errno " << thisErrno;
52 int rv = pclose(
pipe);
53 return std::make_pair(
result, rv);
58 : verbose_(
pset.getUntrackedParameter<
bool>(
"verbose")),
61 allowAddModel_(
false),
62 startedFallback_(
false),
77 #ifdef TRITON_ENABLE_GPU 82 servers_.emplace(std::piecewise_construct,
90 msg =
"List of models for each server:\n";
91 for (
const auto& serverPset :
pset.getUntrackedParameterSetVector(
"servers")) {
97 <<
"TritonService: Not allowed to specify more than one server with same name (" << serverName <<
")";
100 std::unique_ptr<tc::InferenceServerGrpcClient>
client;
103 "TritonService(): unable to create inference context for " + serverName +
" (" +
server.url +
")");
106 inference::ServerMetadataResponse serverMetaResponse;
108 "TritonService(): unable to get metadata for " + serverName +
" (" +
server.url +
")");
110 <<
", version = " << serverMetaResponse.version();
113 inference::RepositoryIndexResponse repoIndexResponse;
115 client->ModelRepositoryIndex(&repoIndexResponse),
116 "TritonService(): unable to get repository index for " + serverName +
" (" +
server.url +
")");
120 msg += serverName +
": ";
121 for (
const auto& modelIndex : repoIndexResponse.models()) {
122 const auto&
modelName = modelIndex.name();
126 auto& modelInfo(mit->second);
127 modelInfo.servers.insert(serverName);
148 <<
"TritonService: Attempt to call addModel() outside of module constructors";
168 const auto& moduleInfo(oit->second);
171 auto& modelInfo(mit->second);
172 modelInfo.modules.erase(
id);
174 if (modelInfo.modules.empty())
185 throw cms::Exception(
"MissingModel") <<
"TritonService: There are no servers that provide model " <<
model;
186 const auto& modelInfo(mit->second);
187 const auto& modelServers = modelInfo.servers;
189 auto msit = modelServers.end();
190 if (!preferred.empty()) {
191 msit = modelServers.find(preferred);
193 if (msit == modelServers.end())
194 edm::LogWarning(
"PreferredServer") <<
"Preferred server " << preferred <<
" for model " <<
model 195 <<
" not available, will choose another server";
197 const auto& serverName(msit == modelServers.end() ? *modelServers.begin() : preferred);
211 msg =
"List of models for fallback server: ";
271 printFallbackServerLog<edm::LogError>();
273 <<
"TritonService: Starting the fallback server failed with exit code " << rv;
277 const std::string& portIndicator(
"CMS_TRITON_GRPC_PORT: ");
280 if (
pos != std::string::npos) {
281 auto pos2 =
pos + portIndicator.size();
282 auto pos3 =
output.find(
'\n', pos2);
283 const auto& portNum =
output.substr(pos2, pos3 - pos2);
284 server.url +=
":" + portNum;
286 throw cms::Exception(
"FallbackFailed") <<
"TritonService: Unknown port for fallback server, log follows:\n" 301 printFallbackServerLog<edm::LogError>();
303 <<
"TritonService: Stopping the fallback server failed with exit code " << rv;
306 printFallbackServerLog<edm::LogInfo>();
310 template <
typename LOG>
316 bool foundLog =
false;
317 for (
const auto&
logName : logNames) {
320 LOG(
"TritonService") <<
"TritonService: server log " <<
logName <<
"\n" <<
infile.rdbuf();
326 LOG(
"TritonService") <<
"TritonService: could not find server log " << logNames[0] <<
" in current directory or " 332 desc.addUntracked<
bool>(
"verbose",
false);
337 validator.addUntracked<
unsigned>(
"port");
338 validator.addUntracked<
bool>(
"useSsl",
false);
339 validator.addUntracked<
std::string>(
"rootCertificates",
"");
340 validator.addUntracked<
std::string>(
"privateKey",
"");
341 validator.addUntracked<
std::string>(
"certificateChain",
"");
343 desc.addVPSetUntracked(
"servers", validator, {});
void watchPostModuleConstruction(PostModuleConstruction::slot_type const &iSlot)
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
std::unordered_map< std::string, Model > models_
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
void watchPostEndJob(PostEndJob::slot_type const &iSlot)
std::unordered_map< std::string, Model > unservedModels_
#define TRITON_THROW_IF_ERROR(X, MSG)
void watchPreModuleConstruction(PreModuleConstruction::slot_type const &iSlot)
void postModuleConstruction(edm::ModuleDescription const &)
void watchPreModuleDestruction(PreModuleDestruction::slot_type const &iSlot)
std::string to_string(const V &value)
unsigned currentModuleId_
Log< level::Error, false > LogError
TritonService(const edm::ParameterSet &pset, edm::ActivityRegistry &areg)
static const std::string fallbackAddress
void addModel(const std::string &modelName, const std::string &path)
FallbackOpts fallbackOpts_
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
def unique(seq, keepstr=True)
void preBeginJob(edm::PathsAndConsumesOfModulesBase const &, edm::ProcessContext const &)
void printFallbackServerLog() const
def pipe(cmdline, input=None)
void preModuleConstruction(edm::ModuleDescription const &)
std::string createGlobalIdentifier(bool binary=false)
Log< level::Info, false > LogInfo
void preModuleDestruction(edm::ModuleDescription const &)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::unordered_map< unsigned, Module > modules_
void watchPreBeginJob(PreBeginJob::slot_type const &iSlot)
convenience function for attaching to signal
ParameterSet const & getParameterSet(ParameterSetID const &id)
Server serverInfo(const std::string &model, const std::string &preferred="") const
std::unordered_map< std::string, Server > servers_
static const std::string fallbackName