7 #include "cetlib_except/exception.h" 10 #include "larrecodnn/ImagePatternAlgs/ToolInterfaces/IPointIdAlg.h" 13 #include "grpc_client.h" 15 namespace nic = triton::client;
28 std::vector<float>
Run(
std::vector<std::vector<float>>
const& inp2d)
const override;
30 int samples = -1)
const override;
50 fNNetOutputs = table().NNetOutputs();
51 fPatchSizeW = table().PatchSizeW();
52 fPatchSizeD = table().PatchSizeD();
53 fCurrentWireIdx = 99999;
54 fCurrentScaledDrift = 99999;
66 <<
"error: unable to create client for inference: " << err << std::endl;
73 <<
"error: failed to get model metadata: " << err << std::endl;
78 <<
"error: failed to get model config: " << err << std::endl;
96 mf::LogInfo(
"PointIdAlgTriton") <<
"tensorRT inference context created.";
104 size_t nrows = inp2d.size(),
ncols = inp2d.front().size();
110 nic::InferInput* triton_input;
111 auto err = nic::InferInput::Create(&triton_input,
116 throw cet::exception(
"PointIdAlgTriton") <<
"unable to get input: " << err << std::endl;
118 std::shared_ptr<nic::InferInput> triton_input_ptr(triton_input);
119 std::vector<nic::InferInput*> triton_inputs = {triton_input_ptr.get()};
123 err = triton_input_ptr->Reset();
126 <<
"failed resetting Triton model input: " << err << std::endl;
129 size_t sbuff_byte_size = (nrows *
ncols) *
sizeof(
float);
130 std::vector<float>
fa(sbuff_byte_size);
133 for (
size_t ir = 0; ir < nrows; ++ir) {
134 std::copy(inp2d[ir].
begin(), inp2d[ir].
end(), fa.begin() + (ir *
ncols));
136 err = triton_input_ptr->AppendRaw(reinterpret_cast<uint8_t*>(fa.data()), sbuff_byte_size);
139 <<
"failed setting Triton input: " << err << std::endl;
144 nic::InferResult* results;
149 <<
"failed sending Triton synchronous infer request: " << err << std::endl;
151 std::shared_ptr<nic::InferResult> results_ptr;
152 results_ptr.reset(results);
156 std::vector<float> out;
159 size_t rbuff0_byte_size;
160 results_ptr->RawData(
161 triton_modmet.outputs(0).name(), (
const uint8_t**)&prb0, &rbuff0_byte_size);
162 size_t ncat0 = rbuff0_byte_size /
sizeof(float);
165 size_t rbuff1_byte_size;
166 results_ptr->RawData(
167 triton_modmet.outputs(1).name(), (
const uint8_t**)&prb1, &rbuff1_byte_size);
168 size_t ncat1 = rbuff1_byte_size /
sizeof(float);
170 for (
unsigned j = 0; j < ncat0; j++)
171 out.push_back(*(prb0 + j));
172 for (
unsigned j = 0; j < ncat1; j++)
173 out.push_back(*(prb1 + j));
183 if ((samples == 0) || inps.empty() || inps.front().empty() || inps.front().front().empty()) {
184 return std::vector<std::vector<float>>();
187 if ((samples == -1) || (samples > (
long long int)inps.size())) { samples = inps.size(); }
189 size_t usamples = samples;
190 size_t nrows = inps.front().size(),
ncols = inps.front().front().size();
196 nic::InferInput* triton_input;
197 auto err = nic::InferInput::Create(&triton_input,
202 throw cet::exception(
"PointIdAlgTriton") <<
"unable to get input: " << err << std::endl;
204 std::shared_ptr<nic::InferInput> triton_input_ptr(triton_input);
205 std::vector<nic::InferInput*> triton_inputs = {triton_input_ptr.get()};
208 err = triton_input_ptr->Reset();
211 <<
"failed resetting Triton model input: " << err << std::endl;
214 size_t sbuff_byte_size = (nrows *
ncols) *
sizeof(
float);
215 std::vector<std::vector<float>>
fa(usamples, std::vector<float>(sbuff_byte_size));
217 for (
size_t idx = 0; idx < usamples; ++idx) {
219 for (
size_t ir = 0; ir < nrows; ++ir) {
220 std::copy(inps[idx][ir].
begin(), inps[idx][ir].
end(), fa[idx].
begin() + (ir *
ncols));
223 triton_input_ptr->AppendRaw(reinterpret_cast<uint8_t*>(fa[idx].data()), sbuff_byte_size);
226 <<
"failed setting Triton input: " << err << std::endl;
232 nic::InferResult* results;
237 <<
"failed sending Triton synchronous infer request: " << err << std::endl;
239 std::shared_ptr<nic::InferResult> results_ptr;
240 results_ptr.reset(results);
244 std::vector<std::vector<float>> out;
247 size_t rbuff0_byte_size;
248 results_ptr->RawData(
249 triton_modmet.outputs(0).name(), (
const uint8_t**)&prb0, &rbuff0_byte_size);
250 size_t ncat0 = rbuff0_byte_size / (usamples *
sizeof(float));
253 size_t rbuff1_byte_size;
254 results_ptr->RawData(
255 triton_modmet.outputs(1).name(), (
const uint8_t**)&prb1, &rbuff1_byte_size);
256 size_t ncat1 = rbuff1_byte_size / (usamples *
sizeof(float));
258 for (
unsigned i = 0; i < usamples; i++) {
259 std::vector<float> vprb;
260 for (
unsigned j = 0; j < ncat0; j++)
261 vprb.push_back(*(prb0 + i * ncat0 + j));
262 for (
unsigned j = 0; j < ncat1; j++)
263 vprb.push_back(*(prb1 + i * ncat1 + j));
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
cet::coded_exception< error, detail::translate > exception