Skip to content

Commit 78e437c

Browse files
committed
chore: changed Mutex scope
1 parent d1f1651 commit 78e437c

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

core/runtime/execute_engine.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ std::vector<at::Tensor> execute_engine(std::vector<at::Tensor> inputs, c10::intr
9898
LOG_DEBUG(
9999
"Attempting to run engine (ID: " << compiled_engine->name
100100
<< "); Hardware Compatible: " << compiled_engine->hardware_compatible);
101-
101+
// nvinfer1::IExecutionContext::enqueue is not thread safe and we need a mutex for it.
102+
// Other IExecutionContext methods and runtime states should be in same scope as well
103+
std::unique_lock<std::mutex> lock(compiled_engine->mu);
102104
if (compiled_engine->profile_execution) {
103105
std::stringstream ss;
104106
ss << "Execution profiling is enabled, find results here:" << std::endl;
@@ -176,10 +178,6 @@ std::vector<at::Tensor> execute_engine(std::vector<at::Tensor> inputs, c10::intr
176178
}
177179
}
178180

179-
// nvinfer1::IExecutionContext::enqueue is not thread safe and we need a mutex for it.
180-
// setTensorAddress should be in same scope to prevent inconsistent state.
181-
std::unique_lock<std::mutex> lock(compiled_engine->mu);
182-
183181
{ // Input Setup
184182
std::unique_ptr<torch::autograd::profiler::RecordProfile> input_profiler_guard;
185183
if (compiled_engine->profile_execution) {

0 commit comments

Comments
 (0)