Skip to content

Commit

Permalink
[CS Issue][Batch Plugin] Fix CS issue in Batch Plugin (openvinotoolki…
Browse files Browse the repository at this point in the history
…t#25683)

### Details:
- the issue the static analyzer is complaining about is wait_for() not
being in the loop
 - *...*

### Tickets:
 - CVS-145094

---------

Signed-off-by: Zhai, Xuejun <[email protected]>
Co-authored-by: Chen Peter <[email protected]>
  • Loading branch information
zhaixuejun1993 and peterchen-intel authored Sep 26, 2024
1 parent cc4cf68 commit 8e2dc85
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/plugins/auto_batch/src/async_infer_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ AsyncInferRequest::AsyncInferRequest(const std::shared_ptr<SyncInferRequest>& re
// it is ok to call size() here as the queue only grows (and the bulk removal happens under the mutex)
const int sz = static_cast<int>(workerInferRequest->_tasks.size());
if (sz == workerInferRequest->_batch_size) {
workerInferRequest->_is_wakeup = true;
workerInferRequest->_cond.notify_one();
}
};
Expand Down
5 changes: 5 additions & 0 deletions src/plugins/auto_batch/src/compiled_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ CompiledModel::GetWorkerInferRequest() const {
workerRequestPtr->_infer_request_batched._so = m_compiled_model_with_batch._so;
workerRequestPtr->_batch_size = m_device_info.device_batch_size;
workerRequestPtr->_completion_tasks.resize(workerRequestPtr->_batch_size);
workerRequestPtr->_is_wakeup = false;
workerRequestPtr->_infer_request_batched->set_callback(
[workerRequestPtr](std::exception_ptr exceptionPtr) mutable {
if (exceptionPtr)
Expand All @@ -74,6 +75,7 @@ CompiledModel::GetWorkerInferRequest() const {
workerRequestPtr->_completion_tasks[c]();
}
// reset the timeout
workerRequestPtr->_is_wakeup = true;
workerRequestPtr->_cond.notify_one();
});

Expand All @@ -83,6 +85,9 @@ CompiledModel::GetWorkerInferRequest() const {
{
std::unique_lock<std::mutex> lock(workerRequestPtr->_mutex);
status = workerRequestPtr->_cond.wait_for(lock, std::chrono::milliseconds(m_time_out));
if ((status != std::cv_status::timeout) && (workerRequestPtr->_is_wakeup == false))
continue;
workerRequestPtr->_is_wakeup = false;
}
if (m_terminate) {
break;
Expand Down
1 change: 1 addition & 0 deletions src/plugins/auto_batch/src/compiled_model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class CompiledModel : public ov::ICompiledModel {
std::condition_variable _cond;
std::mutex _mutex;
std::exception_ptr _exception_ptr;
bool _is_wakeup;
};

CompiledModel(const std::shared_ptr<ov::Model>& model,
Expand Down

0 comments on commit 8e2dc85

Please sign in to comment.