| 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 | { |
nothing calls this directly
no test coverage detected