Skip to content

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

[LPT] Fix medium static code analyzer issues (#28483)

Vladislav Golubevbb78f44476bb
diff --git a/src/common/low_precision_transformations/include/low_precision/common/fake_quantize_dequantization.hpp b/src/common/low_precision_transformations/include/low_precision/common/fake_quantize_dequantization.hpp
index 1035e88ed1d..0d16dbba891 100644
--- a/src/common/low_precision_transformations/include/low_precision/common/fake_quantize_dequantization.hpp
+++ b/src/common/low_precision_transformations/include/low_precision/common/fake_quantize_dequantization.hpp
@@ -50,7 +50,8 @@ public:
const std::shared_ptr<ov::Node>& elementwise,
std::shared_ptr<ov::opset1::Constant>& constant);
- size_t channelDimIndex;
+ // for most node with layout NC, NCHW, NCDWH, index of channel dimension is 1
+ size_t channelDimIndex = 1ul;
Output<Node> data;
std::shared_ptr<ov::opset1::Convert> convert;
std::shared_ptr<ov::opset1::Subtract> subtract;
diff --git a/src/common/low_precision_transformations/include/low_precision/rt_info/quantization_granularity_attribute.hpp b/src/common/low_precision_transformations/include/low_precision/rt_info/quantization_granularity_attribute.hpp
index e74f601f4bd..c43d061fb45 100644
--- a/src/common/low_precision_transformations/include/low_precision/rt_info/quantization_granularity_attribute.hpp
+++ b/src/common/low_precision_transformations/include/low_precision/rt_info/quantization_granularity_attribute.hpp
@@ -27,7 +27,7 @@ public:
};
QuantizationGranularityAttribute() : granularity(Granularity::PerChannel) {}
- QuantizationGranularityAttribute(const Granularity granularity) : granularity(granularity) {}
+ QuantizationGranularityAttribute(const Granularity& granularity) : granularity(granularity) {}
bool operator==(const QuantizationGranularityAttribute& attribute) const {
return this->granularity == attribute.granularity;
diff --git a/src/common/low_precision_transformations/src/assign_and_read_value.cpp b/src/common/low_precision_transformations/src/assign_and_read_value.cpp
index 27b79e4d347..e65e35890c0 100644
--- a/src/common/low_precision_transformations/src/assign_and_read_value.cpp
+++ b/src/common/low_precision_transformations/src/assign_and_read_value.cpp
@@ -20,31 +20,22 @@ namespace low_precision {
AssignAndReadValueTransformation::AssignAndReadValueTransformation(const std::shared_ptr<ov::Model> model, const Params& params) :
LayerTransformation(params), model(model) {
MATCHER_SCOPE(AssignAndReadValueTransformation);
- auto assign3 = pattern::wrap_type<opset3::Assign>({ pattern::wrap_type<ov::opset1::Multiply>() });
- auto assign6 = pattern::wrap_type<opset6::Assign>({ pattern::wrap_type<ov::opset1::Multiply>() });
+ auto assign_m = pattern::wrap_type<opset3::Assign, opset6::Assign>({ pattern::wrap_type<ov::opset1::Multiply>() });
ov::graph_rewrite_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {
- const auto& opsMap = m.get_pattern_value_map();
- auto op = m.get_match_root();
- auto assignIt = opsMap.find(assign3);
- if (assignIt == opsMap.end()) {
- assignIt = opsMap.find(assign6);
- }
- const auto assign = assignIt->second.get_node_shared_ptr();
+ const auto assign = m.get_match_root();
// check that we have ReadValue as the first dependency
if (assign->get_control_dependencies().empty()) {
return false;
}
- if (transformation_callback(op)) {
+ if (transformation_callback(assign)) {
return false;
}
return transform(*context, m);
};
- auto m = std::make_shared<ov::pass::pattern::Matcher>(
- std::make_shared<pass::pattern::op::Or>(OutputVector{ assign3, assign6 }),
- matcher_name);
+ auto m = std::make_shared<ov::pass::pattern::Matcher>(assign_m, matcher_name);
this->register_matcher(m, callback);
}
diff --git a/src/common/low_precision_transformations/src/clamp.cpp b/src/common/low_precision_transformations/src/clamp.cpp
index 80748f549bf..89150e81470 100644
--- a/src/common/low_precision_transformations/src/clamp.cpp
+++ b/src/common/low_precision_transformations/src/clamp.cpp
@@ -72,7 +72,8 @@ bool ClampTransformation::transform(TransformationContext& context, ov::pass::pa
replace_node_update_name(newClamp, replacement);
- element::Type outputClampType = dequantization.multiply ?
+ OPENVINO_ASSERT(dequantization.multiply != nullptr || dequantization.subtract != nullptr, "incorrect dequantization ops configuration");
+ const auto outputClampType = dequantization.multiply ?
dequantization.multiply->get_output_element_type(0) :
dequantization.subtract->get_output_element_type(0);
ov::pass::low_precision::NetworkHelper::setOutDataPrecision(replacement, outputClampType);
diff --git a/src/common/low_precision_transformations/src/eliminate_fake_quantize.cpp b/src/common/low_precision_transformations/src/eliminate_fake_quantize.cpp
index cb5d9270a43..1a09d9914de 100644
--- a/src/common/low_precision_transformations/src/eliminate_fake_quantize.cpp
+++ b/src/common/low_precision_transformations/src/eliminate_fake_quantize.cpp
@@ -51,7 +51,7 @@ bool check_interval(const std::shared_ptr<ov::opset1::FakeQuantize>& fq,
const std::shared_ptr<ov::opset1::Constant>& constant,
const float value,
const float max_diff,
- const bool exact_comparison) noexcept {
+ const bool exact_comparison) {
bool need_to_check_intervals = false;
const auto& constant_values = constant->cast_vector<float>();
for (const auto constant_value : constant_values) {
diff --git a/src/common/low_precision_transformations/src/fake_quantize_dequantization.cpp b/src/common/low_precision_transformations/src/fake_quantize_dequantization.cpp
index a96a5032b5f..7246c9869ce 100644
--- a/src/common/low_precision_transformations/src/fake_quantize_dequantization.cpp
+++ b/src/common/low_precision_transformations/src/fake_quantize_dequantization.cpp
@@ -32,9 +32,6 @@ FakeQuantizeDequantization::FakeQuantizeDequantization(
subtractConstant(subtractConstant),
multiply(multiply),
multiplyConstant(multiplyConstant) {
- // for most node with layout NC, NCHW, NCDWH, index of channel dimension is 1
- channelDimIndex = 1ul;
-
const auto rank = data.get_partial_shape().rank();
if (rank.is_static()) {
std::string data_src_type = data.get_node()->get_type_name();
diff --git a/src/common/low_precision_transformations/src/markup_quantization_granularity.cpp b/src/common/low_precision_transformations/src/markup_quantization_granularity.cpp
index b9d5ac2ec4d..f59aca3498c 100644
--- a/src/common/low_precision_transformations/src/markup_quantization_granularity.cpp
+++ b/src/common/low_precision_transformations/src/markup_quantization_granularity.cpp
@@ -30,7 +30,7 @@ ov::pass::low_precision::MarkupQuantizationGranularity::MarkupQuantizationGranul
bool ov::pass::low_precision::MarkupQuantizationGranularity::run_on_model(const std::shared_ptr<ov::Model>& f) {
RUN_ON_FUNCTION_SCOPE(MarkupPerTensorQuantization);
auto setRestriction = [](const std::shared_ptr<Node>& node, const std::vector<PortQuantizationGranularityRestriction>& restrictedPorts) {
- auto createAttribute = [](Input<Node>& input, const QuantizationGranularityAttribute::Granularity granularity){
+ auto createAttribute = [](Input<Node>& input, const QuantizationGranularityAttribute::Granularity& granularity){
auto &rt = input.get_rt_info();
rt.emplace(QuantizationGranularityAttribute::get_type_info_static(), QuantizationGranularityAttribute(granularity));
};
@@ -43,14 +43,14 @@ bool ov::pass::low_precision::MarkupQuantizationGranularity::run_on_model(const
}
} else {
// markup specific ports
- for (const auto item : restrictedPorts) {
+ for (const auto& item : restrictedPorts) {
Input<Node> input = node->input(item.port);
createAttribute(input, item.granularity);
}
}
};
- for (const std::shared_ptr<Node>& node : f->get_ordered_ops()) {
+ for (const auto& node : f->get_ordered_ops()) {
if (node->get_input_size() == 0) {
continue;
}
diff --git a/src/common/low_precision_transformations/src/network_helper.cpp b/src/common/low_precision_transformations/src/network_helper.cpp
index e57fdcfb1b8..afb7e19c13e 100644
--- a/src/common/low_precision_transformations/src/network_helper.cpp
+++ b/src/common/low_precision_transformations/src/network_helper.cpp
@@ -622,6 +622,7 @@ std::shared_ptr<ov::Node> NetworkHelper::separateInStandaloneBranch(std::shared_
parent = multiply->output(0);
}
+ OPENVINO_ASSERT(dequantization.multiply != nullptr || dequantization.subtract != nullptr, "incorrect dequantization ops configuration");
const auto originalParent = dequantization.multiply ?
dequantization.multiply->shared_from_this() :
dequantization.subtract->shared_from_this();
diff --git a/src/common/low_precision_transformations/src/pull_reshape_through_dequantization.cpp b/src/common/low_precision_transformations/src/pull_reshape_through_dequantization.cpp
index 157a204af3a..6e33afc0946 100644
--- a/src/common/low_precision_transformations/src/pull_reshape_through_dequantization.cpp
+++ b/src/common/low_precision_transformations/src/pull_reshape_through_dequantization.cpp
@@ -101,7 +101,7 @@ std::shared_ptr<Node> moveThroughConvert(const std::shared_ptr<Node>& reshape, c
void fuseConstant(const std::shared_ptr<Node>& reshape, const std::shared_ptr<Node>& constant) {
ov::OutputVector result(1);
- reshape->constant_fold(result, { constant, reshape->input_value(1) });
+ OPENVINO_ASSERT(reshape->constant_fold(result, { constant, reshape->input_value(1) }), "Reshape constant folding failed");
const auto newConstant = result[0].get_node_shared_ptr();
replace_node(reshape, newConstant);
copy_runtime_info({ constant, reshape }, newConstant);
@@ -139,7 +139,7 @@ ov::pass::low_precision::PullReshapeThroughDequantization::PullReshapeThroughDeq
return false;
}
- while (reshape != nullptr) {
+ do {
const auto parent = reshape->get_input_node_shared_ptr(0);
if (ov::is_type<opset1::Multiply>(parent) || ov::is_type<opset1::Subtract>(parent)) {
reshape = pull_reshape_through_dequantization::moveThroughElementwise(reshape, parent);
@@ -151,7 +151,7 @@ ov::pass::low_precision::PullReshapeThroughDequantization::PullReshapeThroughDeq
} else {
THROW_IE_LPT_EXCEPTION(*parent) << "unexepcted operation type";
}
- }
+ } while (reshape != nullptr);
return true;
};
diff --git a/src/common/low_precision_transformations/src/pull_transpose_through_dequantization.cpp b/src/common/low_precision_transformations/src/pull_transpose_through_dequantization.cpp
index a4557288c74..3f3533f12a7 100644
--- a/src/common/low_precision_transformations/src/pull_transpose_through_dequantization.cpp
+++ b/src/common/low_precision_transformations/src/pull_transpose_through_dequantization.cpp
@@ -110,7 +110,7 @@ ov::pass::low_precision::PullTransposeThroughDequantization::PullTransposeThroug
ov::matcher_pass_callback callback = [=](ov::pass::pattern::Matcher & m) -> bool {
const auto& opsMap = m.get_pattern_value_map();
- auto transpose = opsMap.find(matcherTranspose)->second.get_node()->shared_from_this();
+ auto transpose = opsMap.at(matcherTranspose).get_node_shared_ptr();
while (transpose != nullptr) {
const auto parent = transpose->get_input_node_shared_ptr(0);