@@ -2866,6 +2866,14 @@ Status NvExecutionProvider::CreateNodeComputeInfoFromGraph(const GraphViewer& gr
28662866 trt_runtime_config = std::unique_ptr<nvinfer1::IRuntimeConfig>(trt_engine->createRuntimeConfig ());
28672867 if (trt_runtime_config && cuda_graph_enable_) {
28682868 trt_runtime_config->setDynamicShapesKernelSpecializationStrategy (nvinfer1::DynamicShapesKernelSpecializationStrategy::kEAGER );
2869+ #if TRT_MAJOR_RTX > 1 || (TRT_MAJOR_RTX == 1 && TRT_MINOR_RTX >= 3)
2870+ auto cuda_strategy_flag = trt_runtime_config->setCudaGraphStrategy (nvinfer1::CudaGraphStrategy::kWHOLE_GRAPH_CAPTURE );
2871+ LOGS_DEFAULT (INFO ) << " [NvTensorRTRTX EP] CUDA graph strategy with RTX Graph capture enabled : " << cuda_strategy_flag;
2872+ #else
2873+ LOGS_DEFAULT (WARNING ) << " [NvTensorRTRTX EP] CUDA graph is enabled but RTX Graph capture is not available. "
2874+ << " The current TRT RTX version does not support RTX Graph. "
2875+ << " Please upgrade to TRT RTX >= 1.3 to use RTX Graph capture feature for optimal CUDA graph performance." ;
2876+ #endif
28692877 }
28702878 trt_runtime_config->setExecutionContextAllocationStrategy (nvinfer1::ExecutionContextAllocationStrategy::kUSER_MANAGED );
28712879 if (!runtime_cache_.empty ()) {
@@ -3148,22 +3156,8 @@ Status NvExecutionProvider::CreateNodeComputeInfoFromGraph(const GraphViewer& gr
31483156 }
31493157 }
31503158
3151- // Start CUDA graph capture with the correct stream
3152- // Note: We need to set the stream and start capture here because this is where we have access to the actual compute stream
3153- // Get the graph annotation ID that was stored during OnRunStart
3154- CudaGraphAnnotation_t cuda_graph_annotation_id = GetPerThreadContext ().GetCurrentGraphAnnotationId ();
3155- bool graph_replay_on_this_run = false ;
3156- bool should_start_capture = false ;
3157-
3158- HandleCudaGraphStart (stream, require_io_binding, cuda_graph_annotation_id,
3159- graph_replay_on_this_run, should_start_capture);
3160-
3161- if (!graph_replay_on_this_run) {
3162- if (!trt_context->enqueueV3 (stream)) {
3163- return ORT_MAKE_STATUS (ONNXRUNTIME , FAIL , " NvTensorRTRTX EP execution context enqueue failed." );
3164- }
3165- } else {
3166- ORT_RETURN_IF_ERROR (GetPerThreadContext ().ReplayGraph (cuda_graph_annotation_id, sync_stream_after_enqueue_));
3159+ if (!trt_context->enqueueV3 (stream)) {
3160+ return ORT_MAKE_STATUS (ONNXRUNTIME , FAIL , " NvTensorRTRTX EP execution context enqueue failed." );
31673161 }
31683162
31693163 /*
@@ -3181,11 +3175,6 @@ Status NvExecutionProvider::CreateNodeComputeInfoFromGraph(const GraphViewer& gr
31813175 * However, if cuda graph is enabled, TRT EP won't call cudaStreamSynchronize() since it's not allowed during graph capture.
31823176 */
31833177
3184- if (cuda_graph_enable_ && should_start_capture) {
3185- GetPerThreadContext ().CaptureEnd (cuda_graph_annotation_id);
3186- ORT_RETURN_IF_ERROR (GetPerThreadContext ().ReplayGraph (cuda_graph_annotation_id, sync_stream_after_enqueue_));
3187- }
3188-
31893178 if (sync_stream_after_enqueue_) {
31903179 CUDA_RETURN_IF_ERROR (cudaStreamSynchronize (stream));
31913180 }
@@ -3474,22 +3463,8 @@ Status NvExecutionProvider::CreateNodeComputeInfoFromPrecompiledEngine(const Gra
34743463 trt_context->setAuxStreams (aux_streams_, (int32_t )auxiliary_streams_);
34753464 }
34763465
3477- // Start CUDA graph capture with the correct stream
3478- // Note: We need to set the stream and start capture here because this is where we have access to the actual compute stream
3479- // Get the graph annotation ID that was stored during OnRunStart
3480- CudaGraphAnnotation_t cuda_graph_annotation_id = GetPerThreadContext ().GetCurrentGraphAnnotationId ();
3481- bool graph_replay_on_this_run = false ;
3482- bool should_start_capture = false ;
3483-
3484- HandleCudaGraphStart (stream, require_io_binding, cuda_graph_annotation_id,
3485- graph_replay_on_this_run, should_start_capture);
3486-
3487- if (!graph_replay_on_this_run) {
3488- if (!trt_context->enqueueV3 (stream)) {
3489- return ORT_MAKE_STATUS (ONNXRUNTIME , FAIL , " NvTensorRTRTX EP execution context enqueue failed." );
3490- }
3491- } else {
3492- ORT_RETURN_IF_ERROR (GetPerThreadContext ().ReplayGraph (cuda_graph_annotation_id, sync_stream_after_enqueue_));
3466+ if (!trt_context->enqueueV3 (stream)) {
3467+ return ORT_MAKE_STATUS (ONNXRUNTIME , FAIL , " NvTensorRTRTX EP execution context enqueue failed." );
34933468 }
34943469
34953470 /*
@@ -3507,11 +3482,6 @@ Status NvExecutionProvider::CreateNodeComputeInfoFromPrecompiledEngine(const Gra
35073482 * However, if cuda graph is enabled, TRT EP won't call cudaStreamSynchronize() since it's not allowed during graph capture.
35083483 */
35093484
3510- if (cuda_graph_enable_ && should_start_capture) {
3511- GetPerThreadContext ().CaptureEnd (cuda_graph_annotation_id);
3512- ORT_RETURN_IF_ERROR (GetPerThreadContext ().ReplayGraph (cuda_graph_annotation_id, sync_stream_after_enqueue_));
3513- }
3514-
35153485 if (sync_stream_after_enqueue_) {
35163486 CUDA_RETURN_IF_ERROR (cudaStreamSynchronize (stream));
35173487 }
0 commit comments