Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[Tmpl plugin] Fix coverity issue "Use of auto that causes a copy" (#37163)

Tomasz Jankowski4e600d19897a
diff --git a/src/plugins/template/backend/ops/binary_convolution.cpp b/src/plugins/template/backend/ops/binary_convolution.cpp
index e27f2b32c8a..3bd68e41b98 100644
--- a/src/plugins/template/backend/ops/binary_convolution.cpp
+++ b/src/plugins/template/backend/ops/binary_convolution.cpp
@@ -19,9 +19,9 @@ inline void evaluate(const std::shared_ptr<ov::op::v1::BinaryConvolution>& op,
const auto in_data_ptr = static_cast<const T_IN*>(inputs[0].data());
const auto filter_data_ptr = static_cast<const T_F*>(inputs[1].data());
auto out_data_ptr = static_cast<T_IN*>(outputs[0].data());
- const auto in_shape = inputs[0].get_shape();
- const auto filter_shape = inputs[1].get_shape();
- const auto out_shape = outputs[0].get_shape();
+ const auto& in_shape = inputs[0].get_shape();
+ const auto& filter_shape = inputs[1].get_shape();
+ const auto& out_shape = outputs[0].get_shape();
ov::reference::binary_convolution<T_IN, T_F>(in_data_ptr,
filter_data_ptr,
diff --git a/src/plugins/template/backend/ops/einsum.cpp b/src/plugins/template/backend/ops/einsum.cpp
index 931d172ac33..545206c2fd5 100644
--- a/src/plugins/template/backend/ops/einsum.cpp
+++ b/src/plugins/template/backend/ops/einsum.cpp
@@ -11,7 +11,7 @@ template <ov::element::Type_t ET>
bool evaluate(const std::shared_ptr<ov::op::v7::Einsum>& op,
ov::TensorVector& outputs,
const ov::TensorVector& inputs) {
- const auto equation = op->get_equation();
+ const auto& equation = op->get_equation();
ov::reference::einsum(outputs, inputs, equation);
return true;
}
diff --git a/src/plugins/template/backend/ops/equal.cpp b/src/plugins/template/backend/ops/equal.cpp
index a9a0eb06276..3a936e14a0e 100644
--- a/src/plugins/template/backend/ops/equal.cpp
+++ b/src/plugins/template/backend/ops/equal.cpp
@@ -16,8 +16,8 @@ bool evaluate(const std::shared_ptr<ov::op::v1::Equal>& op, ov::TensorVector& ou
const auto in0_data_ptr = inputs[0].data<ET>();
const auto in1_data_ptr = inputs[1].data<ET>();
const auto out_data_ptr = outputs[0].data<BT>();
- const auto in0_shape = inputs[0].get_shape();
- const auto in1_shape = inputs[1].get_shape();
+ const auto& in0_shape = inputs[0].get_shape();
+ const auto& in1_shape = inputs[1].get_shape();
const auto broadcast_spec = op->get_autob();
ov::reference::equal<ET, BT>(in0_data_ptr, in1_data_ptr, out_data_ptr, in0_shape, in1_shape, broadcast_spec);
return true;
diff --git a/src/plugins/template/backend/ops/experimental_detectron_detection_output.cpp b/src/plugins/template/backend/ops/experimental_detectron_detection_output.cpp
index 55f49a8cfb2..c182daebee5 100644
--- a/src/plugins/template/backend/ops/experimental_detectron_detection_output.cpp
+++ b/src/plugins/template/backend/ops/experimental_detectron_detection_output.cpp
@@ -11,7 +11,7 @@ template <ov::element::Type_t ET>
bool evaluate(const std::shared_ptr<ov::op::v6::ExperimentalDetectronDetectionOutput>& op,
ov::TensorVector& outputs,
const ov::TensorVector& inputs) {
- const auto attrs = op->get_attrs();
+ const auto& attrs = op->get_attrs();
size_t rois_num = attrs.max_detections_per_image;
const ov::Shape output_boxes_shape = ov::Shape{rois_num, 4};
diff --git a/src/plugins/template/backend/ops/experimental_detectron_prior_grid_generator.cpp b/src/plugins/template/backend/ops/experimental_detectron_prior_grid_generator.cpp
index b4a960567e8..f0cdac7539a 100644
--- a/src/plugins/template/backend/ops/experimental_detectron_prior_grid_generator.cpp
+++ b/src/plugins/template/backend/ops/experimental_detectron_prior_grid_generator.cpp
@@ -27,8 +27,8 @@ ov::PartialShape infer_output_shape(const ov::TensorVector& inputs, bool flatten
out_shape = ov::PartialShape{ov::Dimension::dynamic(), 4};
}
- const auto priors_shape = inputs[priors_port].get_shape();
- const auto feature_map_shape = inputs[feature_map_port].get_shape();
+ const auto& priors_shape = inputs[priors_port].get_shape();
+ const auto& feature_map_shape = inputs[feature_map_port].get_shape();
if (!ov::shape_size(priors_shape) || !ov::shape_size(feature_map_shape)) {
return out_shape;
@@ -56,7 +56,7 @@ InfoForEDPriorGrid get_info_for_ed_prior_grid_eval(
const ov::TensorVector& inputs) {
InfoForEDPriorGrid result;
- auto attrs = prior_grid->get_attrs();
+ const auto& attrs = prior_grid->get_attrs();
result.grid_h = attrs.h;
result.grid_w = attrs.w;
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 3bf0f0b3d74..ca470627efe 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
@@ -11,7 +11,7 @@ template <ov::element::Type_t ET>
bool evaluate(const std::shared_ptr<ov::op::v6::ExperimentalDetectronGenerateProposalsSingleImage>& op,
ov::TensorVector& outputs,
const ov::TensorVector& inputs) {
- const auto attrs = op->get_attrs();
+ const auto& attrs = op->get_attrs();
size_t post_nms_count = 0;
if (attrs.post_nms_count < 0) {
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 65bacb7d47b..9cf32814d1e 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
@@ -40,7 +40,7 @@ template <ov::element::Type_t ET>
bool evaluate(const std::shared_ptr<ov::op::v6::ExperimentalDetectronROIFeatureExtractor>& op,
ov::TensorVector& outputs,
const ov::TensorVector& inputs) {
- const auto attrs = op->get_attrs();
+ const auto& attrs = op->get_attrs();
std::vector<std::vector<float>> input_data;
std::vector<ov::Shape> input_shapes;
diff --git a/src/plugins/template/backend/ops/gather_elements.cpp b/src/plugins/template/backend/ops/gather_elements.cpp
index f32f433994e..1f5dfaa0410 100644
--- a/src/plugins/template/backend/ops/gather_elements.cpp
+++ b/src/plugins/template/backend/ops/gather_elements.cpp
@@ -13,8 +13,7 @@ bool evaluate(const std::shared_ptr<ov::op::v6::GatherElements>& op,
ov::TensorVector& outputs,
const ov::TensorVector& inputs) {
using T = typename ov::element_type_traits<ET>::value_type;
- ov::Shape params_shape = inputs[0].get_shape();
- ov::Shape indices_shape = inputs[1].get_shape();
+ const auto& indices_shape = inputs[1].get_shape();
outputs[0].set_shape(indices_shape);
diff --git a/src/plugins/template/backend/ops/greater.cpp b/src/plugins/template/backend/ops/greater.cpp
index 4291ad8ff24..1aa4710cbf9 100644
--- a/src/plugins/template/backend/ops/greater.cpp
+++ b/src/plugins/template/backend/ops/greater.cpp
@@ -17,8 +17,8 @@ bool evaluate(const std::shared_ptr<ov::op::v1::Greater>& op,
const auto in0_data_ptr = inputs[0].data<ET>();
const auto in1_data_ptr = inputs[1].data<ET>();
const auto out_data_ptr = outputs[0].data<BT>();
- const auto in0_shape = inputs[0].get_shape();
- const auto in1_shape = inputs[1].get_shape();
+ const auto& in0_shape = inputs[0].get_shape();
+ const auto& in1_shape = inputs[1].get_shape();
const auto broadcast_spec = op->get_autob();
ov::reference::greater<ET, BT>(in0_data_ptr, in1_data_ptr, out_data_ptr, in0_shape, in1_shape, broadcast_spec);
return true;
diff --git a/src/plugins/template/backend/ops/group_convolution_backprop_data.cpp b/src/plugins/template/backend/ops/group_convolution_backprop_data.cpp
index 20cd7046aab..8733a4cd43c 100644
--- a/src/plugins/template/backend/ops/group_convolution_backprop_data.cpp
+++ b/src/plugins/template/backend/ops/group_convolution_backprop_data.cpp
@@ -16,9 +16,9 @@ bool evaluate(const std::shared_ptr<ov::op::v1::GroupConvolutionBackpropData>& o
const auto in_data_ptr = inputs[0].data<ET>();
const auto filter_data_ptr = inputs[1].data<ET>();
const auto out_data_ptr = outputs[0].data<ET>();
- const auto in_shape = inputs[0].get_shape();
- const auto filter_shape = inputs[1].get_shape();
- const auto out_shape = outputs[0].get_shape();
+ const auto& in_shape = inputs[0].get_shape();
+ const auto& filter_shape = inputs[1].get_shape();
+ const auto& out_shape = outputs[0].get_shape();
ov::reference::group_convolution_backprop_data<ET>(in_data_ptr,
filter_data_ptr,
out_data_ptr,
diff --git a/src/plugins/template/backend/ops/identity.cpp b/src/plugins/template/backend/ops/identity.cpp
index a60e8e9f12b..ddcfbd5418a 100644
--- a/src/plugins/template/backend/ops/identity.cpp
+++ b/src/plugins/template/backend/ops/identity.cpp
@@ -12,7 +12,7 @@ template <>
bool evaluate_node<ov::op::v16::Identity>(std::shared_ptr<ov::Node> node,
ov::TensorVector& outputs,
const ov::TensorVector& inputs) {
- const auto input_shape = inputs[0].get_shape();
+ const auto& input_shape = inputs[0].get_shape();
outputs[0].set_shape(input_shape);
auto element_type = node->get_element_type();
diff --git a/src/plugins/template/backend/ops/matrix_nms.cpp b/src/plugins/template/backend/ops/matrix_nms.cpp
index 3de34d46ac8..f79fda00fe8 100644
--- a/src/plugins/template/backend/ops/matrix_nms.cpp
+++ b/src/plugins/template/backend/ops/matrix_nms.cpp
@@ -27,8 +27,8 @@ constexpr size_t boxes_port = 0;
constexpr size_t scores_port = 1;
ov::PartialShape infer_selected_outputs_shape(const ov::TensorVector& inputs, int nms_top_k, int keep_top_k) {
- const auto boxes_ps = inputs[boxes_port].get_shape();
- const auto scores_ps = inputs[scores_port].get_shape();
+ const auto& boxes_ps = inputs[boxes_port].get_shape();
+ const auto& scores_ps = inputs[scores_port].get_shape();
ov::PartialShape result = {ov::Dimension::dynamic(), 6};
diff --git a/src/plugins/template/backend/ops/multiclass_nms.cpp b/src/plugins/template/backend/ops/multiclass_nms.cpp
index de7e887e432..5b5ccd12447 100644
--- a/src/plugins/template/backend/ops/multiclass_nms.cpp
+++ b/src/plugins/template/backend/ops/multiclass_nms.cpp
@@ -51,11 +51,11 @@ InfoForNMS get_info_for_nms_eval(const std::shared_ptr<op::util::MulticlassNmsBa
const ov::TensorVector& inputs) {
InfoForNMS result;
- const auto boxes_ps = inputs[boxes_port].get_shape();
- const auto scores_ps = inputs[scores_port].get_shape();
+ const auto& boxes_ps = inputs[boxes_port].get_shape();
+ const auto& scores_ps = inputs[scores_port].get_shape();
std::vector<PartialShape> input_shapes = {boxes_ps, scores_ps};
if (nms->get_input_size() == 3) {
- const auto roisnum_ps = inputs[roisnum_port].get_shape();
+ const auto& roisnum_ps = inputs[roisnum_port].get_shape();
input_shapes.push_back(roisnum_ps);
}
diff --git a/src/plugins/template/backend/ops/nms_rotated.cpp b/src/plugins/template/backend/ops/nms_rotated.cpp
index 2149197e3c9..f883600ae49 100644
--- a/src/plugins/template/backend/ops/nms_rotated.cpp
+++ b/src/plugins/template/backend/ops/nms_rotated.cpp
@@ -33,8 +33,8 @@ constexpr size_t boxes_port = 0;
constexpr size_t scores_port = 1;
PartialShape infer_selected_indices_shape(const TensorVector& inputs, size_t max_output_boxes_per_class) {
- const auto boxes_shape = inputs[boxes_port].get_shape();
- const auto scores_shape = inputs[scores_port].get_shape();
+ const auto& boxes_shape = inputs[boxes_port].get_shape();
+ const auto& scores_shape = inputs[scores_port].get_shape();
// NMSRotated produces triplets
// that have the following format: [batch_index, class_index, box_index]
diff --git a/src/plugins/template/backend/ops/non_max_suppression.cpp b/src/plugins/template/backend/ops/non_max_suppression.cpp
index c73ddd32576..dd0e06d061d 100644
--- a/src/plugins/template/backend/ops/non_max_suppression.cpp
+++ b/src/plugins/template/backend/ops/non_max_suppression.cpp
@@ -31,8 +31,8 @@ constexpr size_t boxes_port = 0;
constexpr size_t scores_port = 1;
ov::PartialShape infer_selected_indices_shape(const ov::TensorVector& inputs, size_t max_output_boxes_per_class) {
- const auto boxes_ps = inputs[boxes_port].get_shape();
- const auto scores_ps = inputs[scores_port].get_shape();
+ const auto& boxes_ps = inputs[boxes_port].get_shape();
+ const auto& scores_ps = inputs[scores_port].get_shape();
// NonMaxSuppression produces triplets
// that have the following format: [batch_index, class_index, box_index]
@@ -199,8 +199,8 @@ constexpr size_t boxes_port = 0;
constexpr size_t scores_port = 1;
ov::PartialShape infer_selected_indices_shape(const ov::TensorVector& inputs, size_t max_output_boxes_per_class) {
- const auto boxes_ps = inputs[boxes_port].get_shape();
- const auto scores_ps = inputs[scores_port].get_shape();
+ const auto& boxes_ps = inputs[boxes_port].get_shape();
+ const auto& scores_ps = inputs[scores_port].get_shape();
// NonMaxSuppression produces triplets
// that have the following format: [batch_index, class_index, box_index]
@@ -367,8 +367,8 @@ constexpr size_t boxes_port = 0;
constexpr size_t scores_port = 1;
ov::PartialShape infer_selected_indices_shape(const ov::TensorVector& inputs, size_t max_output_boxes_per_class) {
- const auto boxes_ps = inputs[boxes_port].get_shape();
- const auto scores_ps = inputs[scores_port].get_shape();
+ const auto& boxes_ps = inputs[boxes_port].get_shape();
+ const auto& scores_ps = inputs[scores_port].get_shape();
// NonMaxSuppression produces triplets
// that have the following format: [batch_index, class_index, box_index]
@@ -535,8 +535,8 @@ constexpr size_t boxes_port = 0;
constexpr size_t scores_port = 1;
ov::PartialShape infer_selected_indices_shape(const ov::TensorVector& inputs, size_t max_output_boxes_per_class) {
- const auto boxes_ps = inputs[boxes_port].get_shape();
- const auto scores_ps = inputs[scores_port].get_shape();
+ const auto& boxes_ps = inputs[boxes_port].get_shape();
+ const auto& scores_ps = inputs[scores_port].get_shape();
// NonMaxSuppression produces triplets
// that have the following format: [batch_index, class_index, box_index]
@@ -703,8 +703,8 @@ constexpr size_t boxes_port = 0;
constexpr size_t scores_port = 1;
ov::PartialShape infer_selected_indices_shape(const ov::TensorVector& inputs, size_t max_output_boxes_per_class) {
- const auto boxes_ps = inputs[boxes_port].get_shape();
- const auto scores_ps = inputs[scores_port].get_shape();
+ const auto& boxes_ps = inputs[boxes_port].get_shape();
+ const auto& scores_ps = inputs[scores_port].get_shape();
// NonMaxSuppression produces triplets
// that have the following format: [batch_index, class_index, box_index]
diff --git a/src/plugins/template/backend/ops/scaled_dot_product_attention.cpp b/src/plugins/template/backend/ops/scaled_dot_product_attention.cpp
index 883eb4d09b2..95a1abbcaa3 100644
--- a/src/plugins/template/backend/ops/scaled_dot_product_attention.cpp
+++ b/src/plugins/template/backend/ops/scaled_dot_product_attention.cpp
@@ -17,9 +17,9 @@ bool evaluate(const std::shared_ptr<ov::op::v13::ScaledDotProductAttention>& op,
using TMask = typename ov::element_type_traits<ETMask>::value_type;
const TMask* mask = inputs.size() >= 4 ? inputs[3].data<const TMask>() : nullptr;
const T* scale = inputs.size() >= 5 ? inputs[4].data<const T>() : nullptr;
- auto mask_shape = inputs.size() >= 4 ? inputs[3].get_shape() : ov::Shape{};
+ const auto& mask_shape = inputs.size() >= 4 ? inputs[3].get_shape() : ov::Shape{};
const T* sink = inputs.size() >= 6 ? inputs[5].data<const T>() : nullptr;
- auto sink_shape = inputs.size() >= 6 ? inputs[5].get_shape() : ov::Shape{};
+ const auto& sink_shape = inputs.size() >= 6 ? inputs[5].get_shape() : ov::Shape{};
// Hack below is needed to support dynamic shapes in the reference implementation...
const auto input_shapes = ov::util::get_tensors_partial_shapes(inputs);
@@ -77,4 +77,4 @@ bool evaluate_node<ov::op::v13::ScaledDotProductAttention>(std::shared_ptr<ov::N
}
#undef CASE
-}
\ No newline at end of file
+}
diff --git a/src/plugins/template/src/sync_infer_request.cpp b/src/plugins/template/src/sync_infer_request.cpp
index db422015720..6699970bfa8 100644
--- a/src/plugins/template/src/sync_infer_request.cpp
+++ b/src/plugins/template/src/sync_infer_request.cpp
@@ -191,7 +191,6 @@ void ov::template_plugin::InferRequest::infer_preprocess() {
"Template plugin: Unsupported ROI tensor with element type having ",
std::to_string(tensor->get_element_type().bitwidth()),
" bits size");
- ov::Shape shape = tensor->get_shape();
// Perform manual extraction of ROI tensor
// Basic implementation doesn't take axis order into account `desc.getBlockingDesc().getOrder()`
// Performance of manual extraction is not optimal, but it is ok for template implementation
@@ -291,7 +290,7 @@ std::vector<ov::ProfilingInfo> ov::template_plugin::InferRequest::get_profiling_
info.emplace_back(fill_profiling_info("execution time", m_durations[StartPipeline]));
auto template_model = get_template_model();
for (const auto& op : template_model->get_runtime_model()->get_ops()) {
- auto rt_info = op->get_rt_info();
+ const auto& rt_info = op->get_rt_info();
const auto& it = rt_info.find(ov::runtime::interpreter::PERF_COUNTER_NAME);
OPENVINO_ASSERT(it != rt_info.end(), "Operation ", op, " doesn't contain performance counter");
auto counter = it->second.as<std::shared_ptr<ov::runtime::interpreter::PerfCounter>>();