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

Method infer

samples/sampleINT8API/sampleINT8API.cpp:618–661  ·  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, executes the engine, and verifies the output

Source from the content-addressed store, hash-verified

616//! the buffer, sets inputs, executes the engine, and verifies the output
617//!
618sample::Logger::TestResult SampleINT8API::infer()
619{
620 // Create RAII buffer manager object
621 samplesCommon::BufferManager buffers(mEngine);
622
623 auto context = SampleUniquePtr<nvinfer1::IExecutionContext>(mEngine->createExecutionContext());
624 if (!context)
625 {
626 return sample::Logger::TestResult::kFAILED;
627 }
628
629 // Read the input data into the managed buffers
630 // There should be just 1 input tensor
631
632 if (!prepareInput(buffers))
633 {
634 return sample::Logger::TestResult::kFAILED;
635 }
636
637 // Create CUDA stream for the execution of this inference
638 cudaStream_t stream;
639 CHECK(cudaStreamCreate(&stream));
640
641 // Asynchronously copy data from host input buffers to device input buffers
642 buffers.copyInputToDeviceAsync(stream);
643
644 // Asynchronously enqueue the inference work
645 if (!context->enqueueV2(buffers.getDeviceBindings().data(), stream, nullptr))
646 {
647 return sample::Logger::TestResult::kFAILED;
648 }
649
650 // Asynchronously copy data from device output buffers to host output buffers
651 buffers.copyOutputToHostAsync(stream);
652
653 // Wait for the work in the stream to complete
654 CHECK(cudaStreamSynchronize(stream));
655
656 // Release stream
657 CHECK(cudaStreamDestroy(stream));
658
659 // Check and print the output of the inference
660 return verifyOutput(buffers) ? sample::Logger::TestResult::kRUNNING : sample::Logger::TestResult::kFAILED;
661}
662
663//!
664//! \brief Used to clean up any state created in the sample class

Callers 1

mainFunction · 0.45

Calls 5

enqueueV2Method · 0.80
copyOutputToHostAsyncMethod · 0.80
dataMethod · 0.45

Tested by

no test coverage detected