Skip to content

Commit 217f285

Browse files
[OVEP] Fix coverity issues (#753)
1 parent a616aba commit 217f285

File tree

9 files changed

+20
-15
lines changed

9 files changed

+20
-15
lines changed

onnxruntime/core/providers/openvino/backend_manager.cc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,13 @@ BackendManager::BackendManager(SessionContext& session_context,
183183
}
184184
if (session_context_.so_context_enable &&
185185
(subgraph_context_.is_ep_ctx_ovir_encapsulated || !subgraph_context_.is_ep_ctx_graph)) {
186-
auto status = onnxruntime::openvino_ep::BackendManager::ExportCompiledBlobAsEPCtxNode(subgraph);
187-
if (!status.IsOK()) {
188-
ORT_THROW(status);
186+
if (concrete_backend_) {
187+
auto status = onnxruntime::openvino_ep::BackendManager::ExportCompiledBlobAsEPCtxNode(subgraph);
188+
if (!status.IsOK()) {
189+
ORT_THROW(status);
190+
}
191+
} else {
192+
ORT_THROW("[OpenVINO-EP] Cannot export compiled blob as EPCtx Node: Backend not initialized.");
189193
}
190194
}
191195
}
@@ -660,6 +664,7 @@ void BackendManager::Compute(OrtKernelContext* context) {
660664
}
661665

662666
void BackendManager::ShutdownBackendManager() {
667+
std::unique_lock<std::mutex> lock(mutex_);
663668
backend_map_.clear();
664669
concrete_backend_.reset();
665670
}

onnxruntime/core/providers/openvino/backend_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ struct ParameterShape {
3737
std::transform(ort_shape.begin(), ort_shape.end(), ov_shape.begin(), [](int64_t dim) {
3838
return dim == -1 ? ov::Dimension::dynamic() : ov::Dimension(dim);
3939
});
40-
return ov::PartialShape(ov_shape);
40+
return ov::PartialShape(std::move(ov_shape));
4141
}
4242

4343
static ort_shape_t ToOrtShape(const ov::PartialShape& ov_shape) {

onnxruntime/core/providers/openvino/backends/basic_backend.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ BasicBackend::BasicBackend(std::unique_ptr<ONNX_NAMESPACE::ModelProto>& model_pr
4444
// model_file_path will use so_context_file_path if the onnx_model_path_name is not available,
4545
// especially in case of CreateSessionFormArray() where user must explicitly
4646
// specify absolute path for so_context_file_path.
47-
auto model_file_path = [this]() {
47+
auto model_file_path = [this]() -> const std::filesystem::path& {
4848
if (!session_context_.onnx_model_path_name.empty() &&
4949
std::filesystem::exists(session_context_.onnx_model_path_name)) return session_context_.onnx_model_path_name;
5050

onnxruntime/core/providers/openvino/openvino_execution_provider.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ common::Status OpenVINOExecutionProvider::Compile(
118118
fs::path metadata_file_path = context_model_file_path.parent_path() / metadata_filename;
119119
std::ifstream file(metadata_file_path, std::ios::binary);
120120
ORT_RETURN_IF_NOT(file, "Metadata file was not found: " + metadata_file_path.string());
121-
shared_context_->shared_weights.metadata_filepath = metadata_file_path;
121+
shared_context_->shared_weights.metadata_filepath = std::move(metadata_file_path);
122122
file >> metadata;
123123
}
124124

onnxruntime/core/providers/openvino/openvino_parser_utils.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ reshape_t OpenVINOParserUtils::ParseInputShape(const std::string& reshape_input_
142142
}
143143

144144
// Process each tensor definition e.g. "input_1[1..5, 2, 3..4],data[1,2,3]"
145-
for (std::sregex_iterator i = tensor_begin; i != tensor_end; ++i) {
145+
for (std::sregex_iterator i = std::move(tensor_begin); i != tensor_end; ++i) {
146146
std::smatch tensor_match = *i;
147147

148148
// Extract tensor name and trim whitespace
@@ -165,7 +165,7 @@ reshape_t OpenVINOParserUtils::ParseInputShape(const std::string& reshape_input_
165165
auto dim_end = std::sregex_iterator();
166166

167167
// Process each dimension
168-
for (std::sregex_iterator j = dim_begin; j != dim_end; ++j) {
168+
for (std::sregex_iterator j = std::move(dim_begin); j != dim_end; ++j) {
169169
std::smatch dim_match = *j;
170170
std::string dim_value = dim_match[1].str();
171171

@@ -190,7 +190,7 @@ reshape_t OpenVINOParserUtils::ParseInputShape(const std::string& reshape_input_
190190
}
191191

192192
// Store parsed shape in result map
193-
parsed_shape_map[tensor_name] = ov::PartialShape(dimensions);
193+
parsed_shape_map[tensor_name] = ov::PartialShape(std::move(dimensions));
194194
}
195195

196196
return parsed_shape_map;

onnxruntime/core/providers/openvino/ov_interface.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ OVTensorPtr OVInferRequest::GetTensor(const std::string& input_name) {
331331
}
332332

333333
std::string OVInferRequest::GetInputTensorName(uint32_t index) {
334-
return OvExceptionBoundary([&]() {
334+
return OvExceptionBoundary([&]() -> const std::string& {
335335
const auto& model = ovInfReq.get_compiled_model();
336336
return *model.input(index).get_names().begin();
337337
},

onnxruntime/core/providers/openvino/ov_interface.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ class OVExeNetwork {
105105

106106
public:
107107
explicit OVExeNetwork(ov::CompiledModel compiled_model, std::string device, bool stateful_causallm = false)
108-
: compiled_model_obj(compiled_model), target_device(device), is_stateful_causallm(stateful_causallm) {}
109-
OVExeNetwork() : compiled_model_obj(ov::CompiledModel()) {}
108+
: compiled_model_obj(std::move(compiled_model)), target_device(std::move(device)), is_stateful_causallm(stateful_causallm) {}
109+
OVExeNetwork() : compiled_model_obj(ov::CompiledModel()), is_stateful_causallm(false) {}
110110
ov::CompiledModel& Get() { return compiled_model_obj; }
111111
std::shared_ptr<OVInferRequest> CreateInferRequest();
112112
};

onnxruntime/core/providers/openvino/ov_stateful_patch_utils.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void FuseCacheReorder(std::shared_ptr<ov::Model> ov_model,
7474

7575
auto input_batch = ov_model->input(main_input_name).get_partial_shape()[0];
7676

77-
auto beam_idx = std::make_shared<ov::opset13::Parameter>(ov::element::i32, ov::PartialShape({input_batch}));
77+
auto beam_idx = std::make_shared<ov::opset13::Parameter>(ov::element::i32, ov::PartialShape({std::move(input_batch)}));
7878
beam_idx->set_friendly_name("beam_idx");
7979
beam_idx->output(0).get_tensor().add_names({"beam_idx"});
8080
ov_model->add_parameters({beam_idx});

onnxruntime/core/providers/openvino/qdq_transformations/qdq_scales_fix.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ struct CustomGraph {
512512
continue;
513513
}
514514

515-
auto scale_name = node->node_input_name[1]; // Scale
515+
const auto& scale_name = node->node_input_name[1]; // Scale
516516
auto scale_value = get_initializer_value(original_graph, scale_name);
517517
if (scale_value / node->scale_factor < threshold) {
518518
remove_qdq_pair(*node, removed);
@@ -699,7 +699,7 @@ bool scale_graph(CustomGraph& gen_graph,
699699
if (cur_node->op_type == "QuantizeLinear" &&
700700
cur_node->to_node[0]->op_type == "DequantizeLinear") {
701701
needs_second_run = true;
702-
auto scale_name = *std::next(cur_node->node_input_name.begin());
702+
const auto& scale_name = *std::next(cur_node->node_input_name.begin());
703703
auto scale_value = get_initializer_value(gen_graph.original_graph, scale_name);
704704

705705
// QDQ pair with scale over 1

0 commit comments

Comments
 (0)