Skip to content

Conversation

@jatinwadhwa921
Copy link

Fixed coverity issues

try {
ov::Tensor* tensor = nullptr;
{
std::unique_lock lock(mutex_);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For automatic mutex unlocking you can use lock guards like below, this approach is much safer -

Suggested change
std::unique_lock lock(mutex_);
std::lock_guard<std::mutex> lock(mutex_);

The ov::Tensor* tensor = nullptr; can still be inside the same scope here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Placing the delete operation within the scoped critical section results in a Coverity medium-severity. Additionally, since delete is a relatively time-consuming operation, which can potentially block other threads, so I placed the delete operation outside, which will decrease the time for my critical section.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. can you use the lock_guards instead for both Alloc() & Free() calls like mentioned above as you are removing lock.unlock() in your change ( this might lead to deadlocks, perf degradation, logical errors), this will ensure auto unlocking mechanism. This is much simpler to manage & execute the flow without having to unlock the mutes

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ig, this ca n still go in, we can change this later, this needs to go in today due to some release issues, can you please approve this for now and i can make the change later, may be next week

@jatinwadhwa921 jatinwadhwa921 requested a review from Copilot May 19, 2025 05:39
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses Coverity-reported issues by refining lock scope management and optimizing parameter passing across OpenVINO execution provider components.

  • Simplified lock/unlock logic in OVRTAllocator::Free and clarified scope
  • Standardized loop iteration to use const auto& for efficiency
  • Applied std::move to reduce unnecessary shared_ptr copies in provider factory and execution provider

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
onnxruntime/core/providers/openvino/ov_allocator.cc Simplified locking scope and ensured proper tensor deletion
onnxruntime/core/providers/openvino/openvino_provider_factory.cc Updated loops to use const auto& and moved parameters for efficiency
onnxruntime/core/providers/openvino/openvino_execution_provider.cc Applied std::move to shared_context in constructor init list

Comment on lines +36 to +43
{
std::unique_lock lock(mutex_);
auto it = allocated_.find(p);
if (it != allocated_.end()) {
ov::Tensor* tensor = it->second;
tensor = it->second;
allocated_.erase(it);
lock.unlock();
}
} // lock will be automatically released when it goes out of scope
Copy link

Copilot AI May 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The extra inner scope around the lock is unnecessary and the comment on the closing brace is misleading. Consider removing the extra {} block and scoping the unique_lock directly to simplify control flow and improve readability.

Copilot uses AI. Check for mistakes.
// (potential) SharedContext creation.
auto ov_core = OVCore::Get();
pi.device_type = ParseDeviceType(ov_core, provider_options);
pi.device_type = ParseDeviceType(std::move(ov_core), provider_options);
Copy link

Copilot AI May 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Moving ov_core into ParseDeviceType isn’t necessary since it isn’t reused afterward. Consider passing ov_core by const reference or by value without std::move to preserve clarity of ownership semantics.

Suggested change
pi.device_type = ParseDeviceType(std::move(ov_core), provider_options);
pi.device_type = ParseDeviceType(ov_core, provider_options);

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants