diff --git a/onnxruntime/core/providers/openvino/backend_manager.cc b/onnxruntime/core/providers/openvino/backend_manager.cc index 28804d2f76492..41e5aca08eab5 100644 --- a/onnxruntime/core/providers/openvino/backend_manager.cc +++ b/onnxruntime/core/providers/openvino/backend_manager.cc @@ -183,9 +183,13 @@ BackendManager::BackendManager(SessionContext& session_context, } if (session_context_.so_context_enable && (subgraph_context_.is_ep_ctx_ovir_encapsulated || !subgraph_context_.is_ep_ctx_graph)) { - auto status = onnxruntime::openvino_ep::BackendManager::ExportCompiledBlobAsEPCtxNode(subgraph); - if (!status.IsOK()) { - ORT_THROW(status); + if (concrete_backend_) { + auto status = onnxruntime::openvino_ep::BackendManager::ExportCompiledBlobAsEPCtxNode(subgraph); + if (!status.IsOK()) { + ORT_THROW(status); + } + } else { + ORT_THROW("[OpenVINO-EP] Cannot export compiled blob as EPCtx Node: Backend not initialized."); } } } @@ -660,6 +664,7 @@ void BackendManager::Compute(OrtKernelContext* context) { } void BackendManager::ShutdownBackendManager() { + std::unique_lock lock(mutex_); backend_map_.clear(); concrete_backend_.reset(); } diff --git a/onnxruntime/core/providers/openvino/backend_utils.h b/onnxruntime/core/providers/openvino/backend_utils.h index ec3df94c2d1d2..15145df651fa2 100644 --- a/onnxruntime/core/providers/openvino/backend_utils.h +++ b/onnxruntime/core/providers/openvino/backend_utils.h @@ -37,7 +37,7 @@ struct ParameterShape { std::transform(ort_shape.begin(), ort_shape.end(), ov_shape.begin(), [](int64_t dim) { return dim == -1 ? ov::Dimension::dynamic() : ov::Dimension(dim); }); - return ov::PartialShape(ov_shape); + return ov::PartialShape(std::move(ov_shape)); } static ort_shape_t ToOrtShape(const ov::PartialShape& ov_shape) { diff --git a/onnxruntime/core/providers/openvino/backends/basic_backend.cc b/onnxruntime/core/providers/openvino/backends/basic_backend.cc index 61235ef2138b5..8b7309e6a5a98 100644 --- a/onnxruntime/core/providers/openvino/backends/basic_backend.cc +++ b/onnxruntime/core/providers/openvino/backends/basic_backend.cc @@ -44,7 +44,7 @@ BasicBackend::BasicBackend(std::unique_ptr& model_pr // model_file_path will use so_context_file_path if the onnx_model_path_name is not available, // especially in case of CreateSessionFormArray() where user must explicitly // specify absolute path for so_context_file_path. - auto model_file_path = [this]() { + auto model_file_path = [this]() -> const std::filesystem::path& { if (!session_context_.onnx_model_path_name.empty() && std::filesystem::exists(session_context_.onnx_model_path_name)) return session_context_.onnx_model_path_name; diff --git a/onnxruntime/core/providers/openvino/openvino_execution_provider.cc b/onnxruntime/core/providers/openvino/openvino_execution_provider.cc index a0aa04293ac37..1b19517b07363 100644 --- a/onnxruntime/core/providers/openvino/openvino_execution_provider.cc +++ b/onnxruntime/core/providers/openvino/openvino_execution_provider.cc @@ -118,7 +118,7 @@ common::Status OpenVINOExecutionProvider::Compile( fs::path metadata_file_path = context_model_file_path.parent_path() / metadata_filename; std::ifstream file(metadata_file_path, std::ios::binary); ORT_RETURN_IF_NOT(file, "Metadata file was not found: " + metadata_file_path.string()); - shared_context_->shared_weights.metadata_filepath = metadata_file_path; + shared_context_->shared_weights.metadata_filepath = std::move(metadata_file_path); file >> metadata; } diff --git a/onnxruntime/core/providers/openvino/openvino_parser_utils.cc b/onnxruntime/core/providers/openvino/openvino_parser_utils.cc index a78bd1fe2effc..21fc7f935da23 100644 --- a/onnxruntime/core/providers/openvino/openvino_parser_utils.cc +++ b/onnxruntime/core/providers/openvino/openvino_parser_utils.cc @@ -142,7 +142,7 @@ reshape_t OpenVINOParserUtils::ParseInputShape(const std::string& reshape_input_ } // Process each tensor definition e.g. "input_1[1..5, 2, 3..4],data[1,2,3]" - for (std::sregex_iterator i = tensor_begin; i != tensor_end; ++i) { + for (std::sregex_iterator i = std::move(tensor_begin); i != tensor_end; ++i) { std::smatch tensor_match = *i; // Extract tensor name and trim whitespace @@ -165,7 +165,7 @@ reshape_t OpenVINOParserUtils::ParseInputShape(const std::string& reshape_input_ auto dim_end = std::sregex_iterator(); // Process each dimension - for (std::sregex_iterator j = dim_begin; j != dim_end; ++j) { + for (std::sregex_iterator j = std::move(dim_begin); j != dim_end; ++j) { std::smatch dim_match = *j; std::string dim_value = dim_match[1].str(); @@ -190,7 +190,7 @@ reshape_t OpenVINOParserUtils::ParseInputShape(const std::string& reshape_input_ } // Store parsed shape in result map - parsed_shape_map[tensor_name] = ov::PartialShape(dimensions); + parsed_shape_map[tensor_name] = ov::PartialShape(std::move(dimensions)); } return parsed_shape_map; diff --git a/onnxruntime/core/providers/openvino/ov_interface.cc b/onnxruntime/core/providers/openvino/ov_interface.cc index c59cc92d6cfa9..2d29df8eb4197 100644 --- a/onnxruntime/core/providers/openvino/ov_interface.cc +++ b/onnxruntime/core/providers/openvino/ov_interface.cc @@ -331,7 +331,7 @@ OVTensorPtr OVInferRequest::GetTensor(const std::string& input_name) { } std::string OVInferRequest::GetInputTensorName(uint32_t index) { - return OvExceptionBoundary([&]() { + return OvExceptionBoundary([&]() -> const std::string& { const auto& model = ovInfReq.get_compiled_model(); return *model.input(index).get_names().begin(); }, diff --git a/onnxruntime/core/providers/openvino/ov_interface.h b/onnxruntime/core/providers/openvino/ov_interface.h index f6bc5ad599e18..ee35a3ebef7cb 100644 --- a/onnxruntime/core/providers/openvino/ov_interface.h +++ b/onnxruntime/core/providers/openvino/ov_interface.h @@ -105,8 +105,8 @@ class OVExeNetwork { public: explicit OVExeNetwork(ov::CompiledModel compiled_model, std::string device, bool stateful_causallm = false) - : compiled_model_obj(compiled_model), target_device(device), is_stateful_causallm(stateful_causallm) {} - OVExeNetwork() : compiled_model_obj(ov::CompiledModel()) {} + : compiled_model_obj(std::move(compiled_model)), target_device(std::move(device)), is_stateful_causallm(stateful_causallm) {} + OVExeNetwork() : compiled_model_obj(ov::CompiledModel()), is_stateful_causallm(false) {} ov::CompiledModel& Get() { return compiled_model_obj; } std::shared_ptr CreateInferRequest(); }; diff --git a/onnxruntime/core/providers/openvino/ov_stateful_patch_utils.cc b/onnxruntime/core/providers/openvino/ov_stateful_patch_utils.cc index 67ba42884e4f0..b48b0efde7ab6 100644 --- a/onnxruntime/core/providers/openvino/ov_stateful_patch_utils.cc +++ b/onnxruntime/core/providers/openvino/ov_stateful_patch_utils.cc @@ -74,7 +74,7 @@ void FuseCacheReorder(std::shared_ptr ov_model, auto input_batch = ov_model->input(main_input_name).get_partial_shape()[0]; - auto beam_idx = std::make_shared(ov::element::i32, ov::PartialShape({input_batch})); + auto beam_idx = std::make_shared(ov::element::i32, ov::PartialShape({std::move(input_batch)})); beam_idx->set_friendly_name("beam_idx"); beam_idx->output(0).get_tensor().add_names({"beam_idx"}); ov_model->add_parameters({beam_idx}); diff --git a/onnxruntime/core/providers/openvino/qdq_transformations/qdq_scales_fix.cpp b/onnxruntime/core/providers/openvino/qdq_transformations/qdq_scales_fix.cpp index c1e4815c206a2..d159930d52845 100644 --- a/onnxruntime/core/providers/openvino/qdq_transformations/qdq_scales_fix.cpp +++ b/onnxruntime/core/providers/openvino/qdq_transformations/qdq_scales_fix.cpp @@ -512,7 +512,7 @@ struct CustomGraph { continue; } - auto scale_name = node->node_input_name[1]; // Scale + const auto& scale_name = node->node_input_name[1]; // Scale auto scale_value = get_initializer_value(original_graph, scale_name); if (scale_value / node->scale_factor < threshold) { remove_qdq_pair(*node, removed); @@ -699,7 +699,7 @@ bool scale_graph(CustomGraph& gen_graph, if (cur_node->op_type == "QuantizeLinear" && cur_node->to_node[0]->op_type == "DequantizeLinear") { needs_second_run = true; - auto scale_name = *std::next(cur_node->node_input_name.begin()); + const auto& scale_name = *std::next(cur_node->node_input_name.begin()); auto scale_value = get_initializer_value(gen_graph.original_graph, scale_name); // QDQ pair with scale over 1