Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static std::vector<std::string> parseDevices(const std::string& device_string,
OpenVINOExecutionProvider::OpenVINOExecutionProvider(const ProviderInfo& info, std::shared_ptr<SharedContext> shared_context)
: IExecutionProvider{onnxruntime::kOpenVINOExecutionProvider},
session_context_(info),
shared_context_{shared_context},
shared_context_{std::move(shared_context)},
ep_ctx_handle_{session_context_.openvino_sdk_version, *GetLogger()} {
InitProviderOrtApi();
}
Expand Down
14 changes: 7 additions & 7 deletions onnxruntime/core/providers/openvino/openvino_provider_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ std::string ParseDeviceType(std::shared_ptr<OVCore> ov_core, const ProviderOptio
if (std::find(std::begin(available_devices), std::end(available_devices), device) != std::end(available_devices))
device_found = true;
if (device_prefix != "CPU" && luid_list.size() > 0) {
for (auto dev : available_devices) {
for (const auto& dev : available_devices) {
ov::device::LUID ov_luid = OVCore::Get()->core.get_property(dev, ov::device::luid);
std::stringstream ov_luid_str;
ov_luid_str << ov_luid;
Expand All @@ -153,7 +153,7 @@ std::string ParseDeviceType(std::shared_ptr<OVCore> ov_core, const ProviderOptio
}
if (luid_list.size() > 0) {
std::string ov_luid_devices;
for (auto luid_str : luid_list) {
for (const auto& luid_str : luid_list) {
if (ov_luid_map.contains(luid_str)) {
std::string ov_dev = ov_luid_map.at(luid_str);
std::string ov_dev_strip = split(ov_dev, '.')[0];
Expand All @@ -170,14 +170,14 @@ std::string ParseDeviceType(std::shared_ptr<OVCore> ov_core, const ProviderOptio
}
if (!device_mode.empty()) {
selected_device = device_mode + ":" + ov_luid_devices;
for (auto dev_str : devices_to_check) {
auto default_dev = split(dev_str, '.')[0];
for (const auto& dev_str : devices_to_check) {
const auto default_dev = split(dev_str, '.')[0];

if (ov_luid_devices.find(default_dev) == std::string::npos)
selected_device = selected_device + "," + dev_str;
}
} else {
selected_device = ov_luid_devices;
selected_device = std::move(ov_luid_devices);
}
}
// If invalid device is chosen error is thrown
Expand Down Expand Up @@ -215,7 +215,7 @@ static void ParseProviderInfo(const ProviderOptions& provider_options,
// Minor optimization: we'll hold an OVCore reference to ensure we don't create a new core between ParseDeviceType and
// (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.

if (provider_options.contains("device_id")) {
std::string dev_id = provider_options.at("device_id").data();
Expand Down Expand Up @@ -355,7 +355,7 @@ static void ParseProviderInfo(const ProviderOptions& provider_options,

struct OpenVINOProviderFactory : IExecutionProviderFactory {
OpenVINOProviderFactory(ProviderInfo provider_info, std::shared_ptr<SharedContext> shared_context)
: provider_info_(std::move(provider_info)), shared_context_(shared_context) {}
: provider_info_(std::move(provider_info)), shared_context_(std::move(shared_context)) {}

~OpenVINOProviderFactory() override {}

Expand Down
8 changes: 6 additions & 2 deletions onnxruntime/core/providers/openvino/ov_allocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,16 @@ void* OVRTAllocator::Alloc(size_t size) {

void OVRTAllocator::Free(void* p) {
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

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
Comment on lines +36 to +43
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.
if (tensor) {
delete tensor;
}
} catch (const ov::Exception& e) {
Expand Down
Loading