From 302a81b108da4d328d9acea8c3f48a0c654434bd Mon Sep 17 00:00:00 2001 From: "Raasz, Pawel" Date: Tue, 14 Jul 2026 15:40:10 +0200 Subject: [PATCH 1/4] Refactor INTExecutable constructor and member variable initializations, avoid copy --- src/plugins/template/backend/int_executable.cpp | 17 ++++++----------- src/plugins/template/backend/int_executable.hpp | 8 ++++---- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/plugins/template/backend/int_executable.cpp b/src/plugins/template/backend/int_executable.cpp index 474346f690acc9..f6be3f8f14225c 100644 --- a/src/plugins/template/backend/int_executable.cpp +++ b/src/plugins/template/backend/int_executable.cpp @@ -42,11 +42,10 @@ class TemporaryOverrideOutputs { } }; -ov::runtime::interpreter::INTExecutable::INTExecutable(const std::shared_ptr& model) : m_is_compiled{true} { - m_model = model->clone(); - for (auto node : m_model->get_ordered_ops()) { - m_nodes.push_back(node); - } +ov::runtime::interpreter::INTExecutable::INTExecutable(const std::shared_ptr& model) + : m_is_compiled{true}, + m_model{model->clone()}, + m_nodes{m_model->get_ordered_ops()} { set_parameters_and_results(*m_model); } @@ -195,9 +194,7 @@ std::vector ov::runtime::interpreter::INTExecutable::create_input_te std::vector tensors; std::shared_ptr parameter = get_parameter(input_index); for (size_t i = 0; i < pipeline_depth; i++) { - ov::Tensor tensor; - auto t = ov::Tensor(parameter->get_element_type(), parameter->get_shape()); - tensors.push_back(t); + tensors.emplace_back(parameter->get_element_type(), parameter->get_shape()); } return tensors; } @@ -207,9 +204,7 @@ std::vector ov::runtime::interpreter::INTExecutable::create_output_t std::vector tensors; std::shared_ptr result = get_result(output_index); for (size_t i = 0; i < pipeline_depth; i++) { - ov::Tensor tensor; - auto t = ov::Tensor(result->get_element_type(), result->get_shape()); - tensors.push_back(t); + tensors.emplace_back(result->get_element_type(), result->get_shape()); } return tensors; } diff --git a/src/plugins/template/backend/int_executable.hpp b/src/plugins/template/backend/int_executable.hpp index d3bcf2797a05a8..ada2f37bde5932 100644 --- a/src/plugins/template/backend/int_executable.hpp +++ b/src/plugins/template/backend/int_executable.hpp @@ -54,11 +54,11 @@ class INTExecutable : public Executable { bool evaluate_node(const std::shared_ptr& node, ov::TensorVector& outputs, const ov::TensorVector& inputs) const; - bool m_is_compiled = false; - std::shared_ptr m_model; + bool m_is_compiled{}; + std::shared_ptr m_model{}; std::vector> m_nodes; - std::atomic_bool m_cancel_execution{false}; - std::mutex m_mutex; + std::atomic_bool m_cancel_execution{}; + std::mutex m_mutex{}; struct InfoForNMS5 { int64_t max_output_boxes_per_class; From e34eb38a8c41cf4cefa0f87cec20ff4a2cc8e61f Mon Sep 17 00:00:00 2001 From: "Raasz, Pawel" Date: Tue, 14 Jul 2026 15:41:50 +0200 Subject: [PATCH 2/4] Use std::move for efficiency in output shape assignments in multiple ops --- .../experimental_detectron_roi_feature_extractor.cpp | 4 ++-- src/plugins/template/backend/ops/if.cpp | 10 ++++------ src/plugins/template/backend/ops/irdft.cpp | 2 +- src/plugins/template/backend/ops/rdft.cpp | 2 +- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/plugins/template/backend/ops/experimental_detectron_roi_feature_extractor.cpp b/src/plugins/template/backend/ops/experimental_detectron_roi_feature_extractor.cpp index 3f2c548b763772..74e5207b033e8b 100644 --- a/src/plugins/template/backend/ops/experimental_detectron_roi_feature_extractor.cpp +++ b/src/plugins/template/backend/ops/experimental_detectron_roi_feature_extractor.cpp @@ -29,8 +29,8 @@ InfoForEDROIFeature get_info_for_ed_roi_feature( out_shape[1] = input_shapes[1][1]; - result.output_rois_features_shape = out_shape; - result.output_rois_shape = out_rois_shape; + result.output_rois_features_shape = std::move(out_shape); + result.output_rois_shape = std::move(out_rois_shape); return result; } diff --git a/src/plugins/template/backend/ops/if.cpp b/src/plugins/template/backend/ops/if.cpp index 97cedb92bd4f54..628aae1d0e5e63 100644 --- a/src/plugins/template/backend/ops/if.cpp +++ b/src/plugins/template/backend/ops/if.cpp @@ -48,17 +48,15 @@ bool call(ov::TensorVector& func_outputs, std::vector op_outputs; for (size_t i = 0; i < op->get_output_size(); ++i) { ov::descriptor::Tensor* tensor = &op->output(i).get_tensor(); - ov::Tensor host_tensor; auto it = tensor_map.find(tensor); if (ov::op::util::is_output(op)) { - host_tensor = func_outputs[results_map[op]]; + op_outputs.push_back(func_outputs[results_map[op]]); } else if (it == tensor_map.end()) { - host_tensor = ov::Tensor(op->output(i)); - tensor_map.insert({tensor, host_tensor}); + const auto& h_tensor = op_outputs.emplace_back(op->output(i)); + tensor_map.insert({tensor, h_tensor}); } else { - host_tensor = it->second; + op_outputs.push_back(it->second); } - op_outputs.push_back(host_tensor); } op->validate_and_infer_types(); if (!op->evaluate(op_outputs, op_inputs)) { diff --git a/src/plugins/template/backend/ops/irdft.cpp b/src/plugins/template/backend/ops/irdft.cpp index 9db860b68ebbd3..c17d9cec589d8f 100644 --- a/src/plugins/template/backend/ops/irdft.cpp +++ b/src/plugins/template/backend/ops/irdft.cpp @@ -59,7 +59,7 @@ InfoForIRFFT9 get_info_for_irfft9_eval(const ov::TensorVector& inputs) { result.fft_output_shape = fft_output_shape; result.output_shape = output_shape; - result.axes_data = canonicalized_axes; + result.axes_data = std::move(canonicalized_axes); return result; } diff --git a/src/plugins/template/backend/ops/rdft.cpp b/src/plugins/template/backend/ops/rdft.cpp index 45957a06c681d7..40ac15a7d9cefe 100644 --- a/src/plugins/template/backend/ops/rdft.cpp +++ b/src/plugins/template/backend/ops/rdft.cpp @@ -54,7 +54,7 @@ InfoForRFFT9 get_info_for_rfft9_eval(const ov::TensorVector& inputs) { result.fft_output_shape = fft_output_shape; result.output_shape = output_shape; - result.axes_data = canonicalized_axes; + result.axes_data = std::move(canonicalized_axes); return result; } From ce44ab396742b49cc84c3a939e0d421ed7e29939 Mon Sep 17 00:00:00 2001 From: "Raasz, Pawel" Date: Thu, 16 Jul 2026 10:52:21 +0200 Subject: [PATCH 3/4] Fix Coverity issues related with not required copy --- src/plugins/template/backend/ops/convolution.cpp | 7 ++++--- src/plugins/template/backend/ops/einsum.cpp | 7 ++++--- .../experimental_detectron_proposal_single_image.cpp | 8 ++++---- .../experimental_detectron_roi_feature_extractor.cpp | 2 +- src/plugins/template/backend/ops/if.cpp | 2 +- src/plugins/template/backend/ops/interpolate.cpp | 10 ++++++---- .../src/attach_cache_manager_to_paged_attention.hpp | 7 +++---- src/plugins/template/src/plugin.cpp | 3 +-- 8 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/plugins/template/backend/ops/convolution.cpp b/src/plugins/template/backend/ops/convolution.cpp index 76b9d0f41e6a04..258c48525936c9 100644 --- a/src/plugins/template/backend/ops/convolution.cpp +++ b/src/plugins/template/backend/ops/convolution.cpp @@ -44,9 +44,10 @@ template <> bool evaluate_node(std::shared_ptr node, ov::TensorVector& outputs, const ov::TensorVector& inputs) { - auto element_type = node->get_output_element_type(0); - if (ov::is_type(node) || ov::is_type(node)) - element_type = node->get_input_element_type(1); + const auto& element_type = + (ov::is_type(node) || ov::is_type(node)) + ? node->get_input_element_type(1) + : node->get_output_element_type(0); switch (element_type) { case ov::element::boolean: diff --git a/src/plugins/template/backend/ops/einsum.cpp b/src/plugins/template/backend/ops/einsum.cpp index 6ed12e9e947069..931d172ac33578 100644 --- a/src/plugins/template/backend/ops/einsum.cpp +++ b/src/plugins/template/backend/ops/einsum.cpp @@ -20,9 +20,10 @@ template <> bool evaluate_node(std::shared_ptr node, ov::TensorVector& outputs, const ov::TensorVector& inputs) { - auto element_type = node->get_output_element_type(0); - if (ov::is_type(node) || ov::is_type(node)) - element_type = node->get_input_element_type(1); + const auto& element_type = + (ov::is_type(node) || ov::is_type(node)) + ? node->get_input_element_type(1) + : node->get_output_element_type(0); switch (element_type) { case ov::element::boolean: diff --git a/src/plugins/template/backend/ops/experimental_detectron_proposal_single_image.cpp b/src/plugins/template/backend/ops/experimental_detectron_proposal_single_image.cpp index 49d3089cc27d34..3bf0f0b3d747bc 100644 --- a/src/plugins/template/backend/ops/experimental_detectron_proposal_single_image.cpp +++ b/src/plugins/template/backend/ops/experimental_detectron_proposal_single_image.cpp @@ -27,10 +27,10 @@ bool evaluate(const std::shared_ptrget_input_element_type(0); - const auto im_info_shape = inputs[0].get_shape(); - const auto anchors_shape = inputs[1].get_shape(); - const auto deltas_shape = inputs[2].get_shape(); - const auto scores_shape = inputs[3].get_shape(); + const auto& im_info_shape = inputs[0].get_shape(); + const auto& anchors_shape = inputs[1].get_shape(); + const auto& deltas_shape = inputs[2].get_shape(); + const auto& scores_shape = inputs[3].get_shape(); const auto im_info_data = get_floats(inputs[0], im_info_shape); const auto anchors_data = get_floats(inputs[1], anchors_shape); diff --git a/src/plugins/template/backend/ops/experimental_detectron_roi_feature_extractor.cpp b/src/plugins/template/backend/ops/experimental_detectron_roi_feature_extractor.cpp index 74e5207b033e8b..65bacb7d47b541 100644 --- a/src/plugins/template/backend/ops/experimental_detectron_roi_feature_extractor.cpp +++ b/src/plugins/template/backend/ops/experimental_detectron_roi_feature_extractor.cpp @@ -45,7 +45,7 @@ bool evaluate(const std::shared_ptr> input_data; std::vector input_shapes; for (const auto& input : inputs) { - const auto current_shape = input.get_shape(); + const auto& current_shape = input.get_shape(); input_data.push_back(get_floats(input, current_shape)); input_shapes.push_back(current_shape); } diff --git a/src/plugins/template/backend/ops/if.cpp b/src/plugins/template/backend/ops/if.cpp index 628aae1d0e5e63..7812bc83935d2b 100644 --- a/src/plugins/template/backend/ops/if.cpp +++ b/src/plugins/template/backend/ops/if.cpp @@ -135,7 +135,7 @@ void if_reference(const std::vector>& bodies, OPENVINO_ASSERT(output_size > out_descr->m_output_index, "Incorrect associating! If has not output with id ", out_descr->m_output_index); - auto res = outs_from_body[out_descr->m_body_value_index]; + const auto& res = outs_from_body[out_descr->m_body_value_index]; res.copy_to(out[out_descr->m_output_index]); } diff --git a/src/plugins/template/backend/ops/interpolate.cpp b/src/plugins/template/backend/ops/interpolate.cpp index f237724ccaa7a2..3a954f01ce5814 100644 --- a/src/plugins/template/backend/ops/interpolate.cpp +++ b/src/plugins/template/backend/ops/interpolate.cpp @@ -194,8 +194,9 @@ bool evaluate_interpolate(const std::shared_ptr& op, }); // Use v4 shape inference - const auto output_shape = - ov::op::v4::shape_infer(op.get(), input_shapes, m_attrs.pads_begin, m_attrs.pads_end, ta).front(); + const auto output_shapes = + ov::op::v4::shape_infer(op.get(), input_shapes, m_attrs.pads_begin, m_attrs.pads_end, ta); + const auto& output_shape = output_shapes.front(); Shape padded_input_shape; for (size_t i = 0; i < input_shape.size(); ++i) { @@ -306,8 +307,9 @@ bool evaluate_interpolate(const std::shared_ptr& op, std::transform(inputs.cbegin(), inputs.cend(), std::back_inserter(input_shapes), [](const ov::Tensor& ht) { return ht.get_shape(); }); - const auto output_shape = - ov::op::v11::shape_infer(op.get(), input_shapes, m_attrs.pads_begin, m_attrs.pads_end, ta).front(); + const auto output_shapes = + ov::op::v11::shape_infer(op.get(), input_shapes, m_attrs.pads_begin, m_attrs.pads_end, ta); + const auto& output_shape = output_shapes.front(); Shape padded_input_shape; for (size_t i = 0; i < input_shape.size(); ++i) { diff --git a/src/plugins/template/src/attach_cache_manager_to_paged_attention.hpp b/src/plugins/template/src/attach_cache_manager_to_paged_attention.hpp index e9d22506d8e21f..4dd0b9bc938525 100644 --- a/src/plugins/template/src/attach_cache_manager_to_paged_attention.hpp +++ b/src/plugins/template/src/attach_cache_manager_to_paged_attention.hpp @@ -22,10 +22,9 @@ class AttachCacheManagerToPagedAttention : public ov::pass::MatcherPass { auto pa_pattern = pattern::wrap_type(); - auto shared_handle = std::make_shared(); - auto shared_dtype = std::make_shared(); - - ov::matcher_pass_callback callback = [shared_handle, shared_dtype](pattern::Matcher& m) -> bool { + ov::matcher_pass_callback callback = + [shared_handle = std::make_shared(), + shared_dtype = std::make_shared()](pattern::Matcher& m) -> bool { auto pa = std::dynamic_pointer_cast(m.get_match_root()); if (!pa || get_cache_manager(pa.get()) != nullptr) return false; diff --git a/src/plugins/template/src/plugin.cpp b/src/plugins/template/src/plugin.cpp index 454e47f347971c..b2e12fa2bc0160 100644 --- a/src/plugins/template/src/plugin.cpp +++ b/src/plugins/template/src/plugin.cpp @@ -75,7 +75,7 @@ std::shared_ptr get_ov_model_from_blob(const ov::template_plugin::Plu size_t offset, const ov::AnyMap& properties) { if (auto blob_it = properties.find(ov::hint::compiled_blob.name()); blob_it != properties.end()) { - if (auto blob = blob_it->second.as(); blob) { + if (const auto& blob = blob_it->second.as(); blob) { ov::SharedStreamBuffer shared_buffer(blob.data(), blob.get_byte_size()); std::istream blob_stream(&shared_buffer); blob_stream.seekg(offset, std::ios::beg); @@ -260,7 +260,6 @@ std::shared_ptr ov::template_plugin::Plugin::import_model( if (auto m = model_hint->second.as>()) { if (m->has_rt_info("__weights_path")) { AnyMap rt_info; - auto p = m->get_rt_info("__weights_path"); rt_info[ov::weights_path.name()] = m->get_rt_info("__weights_path"); weights = get_model_weights(rt_info); } From bcb6c93478877fe7738e37092afaf129bfb95958 Mon Sep 17 00:00:00 2001 From: "Raasz, Pawel" Date: Thu, 16 Jul 2026 11:12:06 +0200 Subject: [PATCH 4/4] Apply code style --- .../src/attach_cache_manager_to_paged_attention.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/plugins/template/src/attach_cache_manager_to_paged_attention.hpp b/src/plugins/template/src/attach_cache_manager_to_paged_attention.hpp index 4dd0b9bc938525..370d217ee4f0f5 100644 --- a/src/plugins/template/src/attach_cache_manager_to_paged_attention.hpp +++ b/src/plugins/template/src/attach_cache_manager_to_paged_attention.hpp @@ -22,9 +22,9 @@ class AttachCacheManagerToPagedAttention : public ov::pass::MatcherPass { auto pa_pattern = pattern::wrap_type(); - ov::matcher_pass_callback callback = - [shared_handle = std::make_shared(), - shared_dtype = std::make_shared()](pattern::Matcher& m) -> bool { + ov::matcher_pass_callback callback = [shared_handle = std::make_shared(), + shared_dtype = + std::make_shared()](pattern::Matcher& m) -> bool { auto pa = std::dynamic_pointer_cast(m.get_match_root()); if (!pa || get_cache_manager(pa.get()) != nullptr) return false;