Skip to content

Commit

Permalink
chore: changed Mutex scope
Browse files Browse the repository at this point in the history
  • Loading branch information
keehyuna committed Dec 13, 2024
1 parent 57a5adf commit c17f054
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 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 @@ -176,10 +178,6 @@ std::vector<at::Tensor> execute_engine(std::vector<at::Tensor> inputs, c10::intr
}
}

// nvinfer1::IExecutionContext::enqueue is not thread safe and we need a mutex for it.
// setTensorAddress should be in same scope to prevent inconsistent state.
std::unique_lock<std::mutex> lock(compiled_engine->mu);

{ // Input Setup
std::unique_ptr<torch::autograd::profiler::RecordProfile> input_profiler_guard;
if (compiled_engine->profile_execution) {
Expand Down

0 comments on commit c17f054

Please sign in to comment.