Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Correct mutex scope in execute_engine() #3310

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions core/runtime/execute_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ std::vector<at::Tensor> execute_engine(std::vector<at::Tensor> 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<std::mutex> lock(compiled_engine->mu);
if (compiled_engine->profile_execution) {
std::stringstream ss;
ss << "Execution profiling is enabled, find results here:" << std::endl;
Expand Down Expand Up @@ -307,9 +309,6 @@ std::vector<at::Tensor> execute_engine(std::vector<at::Tensor> 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<std::mutex> lock(compiled_engine->mu);

{ // Engine Execution (execute on engine stream)
c10::cuda::CUDAStreamGuard stream_guard(compiled_engine->engine_stream);

Expand Down
Loading