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

Method createEnqueueFunction

samples/common/sampleInference.cpp:866–910  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

864 }
865
866 void createEnqueueFunction(
867 InferenceOptions const& inference, nvinfer1::IExecutionContext& context, Bindings& bindings)
868 {
869 if (context.getEngine().hasImplicitBatchDimension())
870 {
871 mEnqueue = EnqueueFunction(EnqueueImplicit(context, mBindings.getDeviceBuffers(), inference.batch));
872 }
873 else
874 {
875 mEnqueue = EnqueueFunction(EnqueueExplicit(context, mBindings));
876 }
877 if (inference.graph)
878 {
879 TrtCudaStream& stream = getStream(StreamType::kCOMPUTE);
880 // Avoid capturing initialization calls by executing the enqueue function at least
881 // once before starting CUDA graph capture.
882 auto const ret = mEnqueue(stream);
883 if (!ret)
884 {
885 throw std::runtime_error("Inference enqueue failed.");
886 }
887 stream.synchronize();
888
889 mGraph.beginCapture(stream);
890 // The built TRT engine may contain operations that are not permitted under CUDA graph capture mode.
891 // When the stream is capturing, the enqueue call may return false if the current CUDA graph capture fails.
892 if (mEnqueue(stream))
893 {
894 mGraph.endCapture(stream);
895 mEnqueue = EnqueueFunction(EnqueueGraph(context, mGraph));
896 }
897 else
898 {
899 mGraph.endCaptureOnError(stream);
900 // Ensure any CUDA error has been cleaned up.
901 cudaCheck(cudaGetLastError());
902 sample::gLogWarning << "The built TensorRT engine contains operations that are not permitted under "
903 "CUDA graph capture mode."
904 << std::endl;
905 sample::gLogWarning << "The specified --useCudaGraph flag has been ignored. The inference will be "
906 "launched without using CUDA graph launch."
907 << std::endl;
908 }
909 }
910 }
911
912 void createEnqueueFunction(InferenceOptions const& inference, nvinfer1::safe::IExecutionContext& context, Bindings&)
913 {

Callers

nothing calls this directly

Calls 12

EnqueueImplicitClass · 0.85
EnqueueExplicitClass · 0.85
EnqueueGraphClass · 0.85
cudaCheckFunction · 0.85
EnqueueSafeClass · 0.85
EnqueueGraphSafeClass · 0.85
getDeviceBuffersMethod · 0.80
synchronizeMethod · 0.45
beginCaptureMethod · 0.45
endCaptureMethod · 0.45
endCaptureOnErrorMethod · 0.45

Tested by

no test coverage detected