MCPcopy Create free account
hub / github.com/NVIDIA/TensorRT / infer

Method infer

samples/sampleOnnxMNIST/sampleOnnxMNIST.cpp:221–258  ·  view source on GitHub ↗

\brief Runs the TensorRT inference engine for this sample \details This function is the main execution function of the sample. It allocates the buffer, sets inputs and executes the engine.

Source from the content-addressed store, hash-verified

219//! sets inputs and executes the engine.
220//!
221bool SampleOnnxMNIST::infer()
222{
223 // Create RAII buffer manager object
224 samplesCommon::BufferManager buffers(mEngine);
225
226 auto context = SampleUniquePtr<nvinfer1::IExecutionContext>(mEngine->createExecutionContext());
227 if (!context)
228 {
229 return false;
230 }
231
232 // Read the input data into the managed buffers
233 ASSERT(mParams.inputTensorNames.size() == 1);
234 if (!processInput(buffers))
235 {
236 return false;
237 }
238
239 // Memcpy from host input buffers to device input buffers
240 buffers.copyInputToDevice();
241
242 bool status = context->executeV2(buffers.getDeviceBindings().data());
243 if (!status)
244 {
245 return false;
246 }
247
248 // Memcpy from device output buffers to host output buffers
249 buffers.copyOutputToHost();
250
251 // Verify results
252 if (!verifyOutput(buffers))
253 {
254 return false;
255 }
256
257 return true;
258}
259
260//!
261//! \brief Reads the input and stores the result in a managed buffer

Callers 1

mainFunction · 0.45

Calls 6

copyInputToDeviceMethod · 0.80
executeV2Method · 0.80
copyOutputToHostMethod · 0.80
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected