\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.
| 219 | //! sets inputs and executes the engine. |
| 220 | //! |
| 221 | bool 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 |
no test coverage detected