From bed5d37f7ca33ece4cd6b2867462d85974619904 Mon Sep 17 00:00:00 2001 From: keehyun Date: Tue, 17 Dec 2024 05:15:12 +0900 Subject: [PATCH] fix: Correct mutex scope in execute_engine() (#3310) --- core/runtime/execute_engine.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/core/runtime/execute_engine.cpp b/core/runtime/execute_engine.cpp index a7908468f4..280c805295 100644 --- a/core/runtime/execute_engine.cpp +++ b/core/runtime/execute_engine.cpp @@ -98,7 +98,9 @@ std::vector execute_engine(std::vector inputs, c10::intr LOG_DEBUG( "Attempting to run engine (ID: " << compiled_engine->name << "); Hardware Compatible: " << compiled_engine->hardware_compatible); - + // nvinfer1::IExecutionContext::enqueue is not thread safe and we need a mutex for it. + // Other IExecutionContext methods and runtime states should be in same scope as well + std::unique_lock lock(compiled_engine->mu); if (compiled_engine->profile_execution) { std::stringstream ss; ss << "Execution profiling is enabled, find results here:" << std::endl; @@ -307,9 +309,6 @@ std::vector execute_engine(std::vector inputs, c10::intr compiled_engine->engine_stream = c10::cuda::getStreamFromPool(false, current_device_id); } - // nvinfer1::IExecutionContext::enqueue is not thread safe and we need a mutex for it. - std::unique_lock lock(compiled_engine->mu); - { // Engine Execution (execute on engine stream) c10::cuda::CUDAStreamGuard stream_guard(compiled_engine->engine_stream);