10 #include "trtis_clients/model_config.pb.h" 11 #include "trtis_clients/request_grpc.h" 12 #include "trtis_clients/request_http.h" 14 namespace ni = nvidia::inferenceserver;
15 namespace nic = nvidia::inferenceserver::client;
23 std::vector<float>
Run(
std::vector<std::vector<float>>
const& inp2d)
const override;
25 int samples = -1)
const override;
33 std::unique_ptr<nic::InferContext>
ctx;
56 if (table().TrtisURL(s_cfgvr)) {
fTrtisURL = s_cfgvr; }
60 if (table().TrtisVerbose(b_cfgvr)) {
fTrtisVerbose = b_cfgvr; }
70 auto err = nic::InferGrpcContext::Create(
74 <<
"unable to create tRTis inference context: " <<
err <<
std::endl;
88 mf::LogInfo(
"PointIdAlgTrtis") <<
"tensorRT inference context created.";
97 size_t nrows = inp2d.size(), ncols = inp2d.front().size();
101 std::unique_ptr<nic::InferContext::Options>
options;
102 auto err = nic::InferContext::Options::Create(&options);
105 <<
"failed initializing tRTis infer options: " <<
err <<
std::endl;
108 options->SetBatchSize(1);
109 for (
const auto& output :
ctx->Outputs()) {
110 options->AddRawResult(output);
113 err =
ctx->SetRunOptions(*options);
116 <<
"unable to set tRTis infer options: " <<
err <<
std::endl;
124 <<
"failed resetting tRTis model input: " <<
err <<
std::endl;
127 size_t sbuff_byte_size = (nrows * ncols) *
sizeof(
float);
128 std::vector<float> fa(sbuff_byte_size);
131 for (
size_t ir = 0; ir <
nrows; ++ir) {
134 err =
model_input->SetRaw(reinterpret_cast<uint8_t*>(fa.data()), sbuff_byte_size);
141 std::map<std::string, std::unique_ptr<nic::InferContext::Result>> results;
146 <<
"failed sending tRTis synchronous infer request: " <<
err <<
std::endl;
151 std::vector<float> out;
152 std::map<std::string, std::unique_ptr<nic::InferContext::Result>>
::iterator itRes =
156 while (itRes != results.end()) {
157 const std::unique_ptr<nic::InferContext::Result>&
result = itRes->second;
159 size_t rbuff_byte_size;
160 result->GetRaw(0, &rbuff, &rbuff_byte_size);
161 const float* prb =
reinterpret_cast<const float*
>(rbuff);
164 size_t ncat = rbuff_byte_size /
sizeof(float);
165 for (
unsigned int j = 0; j < ncat; j++) {
166 out.push_back(prb[j]);
175 std::vector<std::vector<float>>
178 if ((samples == 0) || inps.empty() || inps.front().empty() || inps.front().front().empty()) {
179 return std::vector<std::vector<float>>();
182 if ((samples == -1) || (samples > (
long long int)inps.size())) { samples = inps.size(); }
184 size_t usamples = samples;
185 size_t nrows = inps.front().size(), ncols = inps.front().front().size();
189 std::unique_ptr<nic::InferContext::Options>
options;
190 auto err = nic::InferContext::Options::Create(&options);
193 <<
"failed initializing tRTis infer options: " <<
err <<
std::endl;
196 options->SetBatchSize(usamples);
197 for (
const auto& output :
ctx->Outputs()) {
198 options->AddRawResult(output);
201 err =
ctx->SetRunOptions(*options);
204 <<
"unable to set tRTis inference options: " <<
err <<
std::endl;
212 <<
"failed resetting tRTis model input: " <<
err <<
std::endl;
215 size_t sbuff_byte_size = (nrows * ncols) *
sizeof(
float);
216 std::vector<std::vector<float>> fa(usamples, std::vector<float>(sbuff_byte_size));
218 for (
size_t idx = 0; idx < usamples; ++idx) {
220 for (
size_t ir = 0; ir <
nrows; ++ir) {
223 err =
model_input->SetRaw(reinterpret_cast<uint8_t*>(fa[idx].
data()), sbuff_byte_size);
232 std::map<std::string, std::unique_ptr<nic::InferContext::Result>> results;
237 <<
"failed sending tRTis synchronous infer request: " <<
err <<
std::endl;
242 std::vector<std::vector<float>> out;
244 for (
unsigned int i = 0; i < usamples; i++) {
245 std::map<std::string, std::unique_ptr<nic::InferContext::Result>>
::iterator itRes =
249 std::vector<float> vprb;
250 while (itRes != results.end()) {
251 const std::unique_ptr<nic::InferContext::Result>&
result = itRes->second;
253 size_t rbuff_byte_size;
254 result->GetRaw(i, &rbuff, &rbuff_byte_size);
255 const float* prb =
reinterpret_cast<const float*
>(rbuff);
258 size_t ncat = rbuff_byte_size /
sizeof(float);
259 for (
unsigned int j = 0; j < ncat; j++) {
260 vprb.push_back(prb[j]);
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
DataProviderAlg(const fhicl::ParameterSet &pset)
void err(const char *fmt,...)
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
unsigned nrows(sqlite3 *db, std::string const &tablename)
cet::coded_exception< error, detail::translate > exception
QTextStream & endl(QTextStream &s)