OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[TEMPLATE] FixCoverity issues in TEMPLATE plugin (#36918)
Pawel Raasz296f68e3233f
diff --git a/src/plugins/template/backend/int_executable.cpp b/src/plugins/template/backend/int_executable.cppindex 474346f690a..f6be3f8f142 100644--- a/src/plugins/template/backend/int_executable.cpp+++ b/src/plugins/template/backend/int_executable.cpp@@ -42,11 +42,10 @@ public:}};-ov::runtime::interpreter::INTExecutable::INTExecutable(const std::shared_ptr<ov::Model>& 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<ov::Model>& 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::Tensor> ov::runtime::interpreter::INTExecutable::create_input_testd::vector<ov::Tensor> tensors;std::shared_ptr<op::v0::Parameter> 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::Tensor> ov::runtime::interpreter::INTExecutable::create_output_tstd::vector<ov::Tensor> tensors;std::shared_ptr<op::v0::Result> 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.hppindex d3bcf2797a0..ada2f37bde5 100644--- a/src/plugins/template/backend/int_executable.hpp+++ b/src/plugins/template/backend/int_executable.hpp@@ -54,11 +54,11 @@ protected:bool evaluate_node(const std::shared_ptr<Node>& node,ov::TensorVector& outputs,const ov::TensorVector& inputs) const;- bool m_is_compiled = false;- std::shared_ptr<ov::Model> m_model;+ bool m_is_compiled{};+ std::shared_ptr<ov::Model> m_model{};std::vector<std::shared_ptr<Node>> 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;diff --git a/src/plugins/template/backend/ops/convolution.cpp b/src/plugins/template/backend/ops/convolution.cppindex 76b9d0f41e6..258c4852593 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<ov::op::v1::Convolution>(std::shared_ptr<ov::Node> node,ov::TensorVector& outputs,const ov::TensorVector& inputs) {- auto element_type = node->get_output_element_type(0);- if (ov::is_type<ov::op::v1::Select>(node) || ov::is_type<ov::op::util::BinaryElementwiseComparison>(node))- element_type = node->get_input_element_type(1);+ const auto& element_type =+ (ov::is_type<ov::op::v1::Select>(node) || ov::is_type<ov::op::util::BinaryElementwiseComparison>(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.cppindex 6ed12e9e947..931d172ac33 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<ov::op::v7::Einsum>(std::shared_ptr<ov::Node> node,ov::TensorVector& outputs,const ov::TensorVector& inputs) {- auto element_type = node->get_output_element_type(0);- if (ov::is_type<ov::op::v1::Select>(node) || ov::is_type<ov::op::util::BinaryElementwiseComparison>(node))- element_type = node->get_input_element_type(1);+ const auto& element_type =+ (ov::is_type<ov::op::v1::Select>(node) || ov::is_type<ov::op::util::BinaryElementwiseComparison>(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.cppindex 49d3089cc27..3bf0f0b3d74 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_ptr<ov::op::v6::ExperimentalDetectronGenerateProconst auto output_type = op->get_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.cppindex 3f2c548b763..65bacb7d47b 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;}@@ -45,7 +45,7 @@ bool evaluate(const std::shared_ptr<ov::op::v6::ExperimentalDetectronROIFeatureEstd::vector<std::vector<float>> input_data;std::vector<ov::Shape> 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.cppindex 97cedb92bd4..7812bc83935 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<ov::Tensor> 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)) {@@ -137,7 +135,7 @@ void if_reference(const std::vector<std::shared_ptr<ov::Model>>& 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.cppindex f237724ccaa..3a954f01ce5 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<ov::op::v4::Interpolate>& 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<ov::op::v11::Interpolate>& 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/backend/ops/irdft.cpp b/src/plugins/template/backend/ops/irdft.cppindex 9db860b68eb..c17d9cec589 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.cppindex 45957a06c68..40ac15a7d9c 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;}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.hppindex e9d22506d8e..370d217ee4f 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 @@ public:auto pa_pattern = pattern::wrap_type<ov::op::PagedAttentionExtension>();- auto shared_handle = std::make_shared<CacheManagerHandle>();- auto shared_dtype = std::make_shared<ov::element::Type>();-- ov::matcher_pass_callback callback = [shared_handle, shared_dtype](pattern::Matcher& m) -> bool {+ ov::matcher_pass_callback callback = [shared_handle = std::make_shared<CacheManagerHandle>(),+ shared_dtype =+ std::make_shared<ov::element::Type>()](pattern::Matcher& m) -> bool {auto pa = std::dynamic_pointer_cast<ov::op::PagedAttentionExtension>(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.cppindex 454e47f3479..b2e12fa2bc0 100644--- a/src/plugins/template/src/plugin.cpp+++ b/src/plugins/template/src/plugin.cpp@@ -75,7 +75,7 @@ std::shared_ptr<ov::Model> get_ov_model_from_blob(const ov::template_plugin::Plusize_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<ov::Tensor>(); blob) {+ if (const auto& blob = blob_it->second.as<ov::Tensor>(); 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::ICompiledModel> ov::template_plugin::Plugin::import_model(if (auto m = model_hint->second.as<std::shared_ptr<ov::Model>>()) {if (m->has_rt_info("__weights_path")) {AnyMap rt_info;- auto p = m->get_rt_info<std::string>("__weights_path");rt_info[ov::weights_path.name()] = m->get_rt_info<ov::Any>("__weights_path");weights = get_model_weights(rt_info);}