Skip to content

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

[CPU][ARM] ACL-specific int8 AvgPool cases handling (#36117)

Aleksandr Voron0bee8708cac9
diff --git a/src/plugins/intel_cpu/src/transformations/transformation_pipeline.cpp b/src/plugins/intel_cpu/src/transformations/transformation_pipeline.cpp
index cc64d155070..3f3625248b5 100644
--- a/src/plugins/intel_cpu/src/transformations/transformation_pipeline.cpp
+++ b/src/plugins/intel_cpu/src/transformations/transformation_pipeline.cpp
@@ -221,6 +221,7 @@
#endif
#if defined(OPENVINO_ARCH_ARM) || defined(OPENVINO_ARCH_ARM64)
+# include "low_precision/avg_pool.hpp"
# include "low_precision/convolution.hpp"
# include "low_precision/convolution_backprop_data.hpp"
# include "low_precision/fake_quantize.hpp"
@@ -980,6 +981,12 @@ void Transformations::runLptPasses(const std::vector<ov::element::Type>& default
return ov::marked_as_bias(node);
},
AddTransformation);
+ CPU_SET_CALLBACK_ARM(
+ lptManager,
+ [&defaultPrecisions](const_node_ptr& node) -> bool {
+ return is_acl_int8_avg_pool_lpt_skipped(node, defaultPrecisions);
+ },
+ AvgPoolTransformation);
CPU_SET_CALLBACK_ARM(
lptManager,
[](const_node_ptr& node) -> bool {
diff --git a/src/plugins/intel_cpu/src/transformations/utils.cpp b/src/plugins/intel_cpu/src/transformations/utils.cpp
index 700ccdc8fd4..1d76341a2f6 100644
--- a/src/plugins/intel_cpu/src/transformations/utils.cpp
+++ b/src/plugins/intel_cpu/src/transformations/utils.cpp
@@ -10,6 +10,8 @@
#include <string>
#include <vector>
+#include "low_precision/network_helper.hpp"
+#include "low_precision/resolve_precision_attribute.hpp"
#include "openvino/core/node.hpp"
#include "openvino/core/shape.hpp"
#include "openvino/core/type.hpp"
@@ -20,6 +22,8 @@
#include "openvino/op/fake_quantize.hpp"
#include "openvino/op/max_pool.hpp"
#include "openvino/op/multiply.hpp"
+#include "openvino/op/util/attr_types.hpp"
+#include "openvino/op/util/avg_pool_base.hpp"
#include "openvino/pass/pattern/matcher.hpp"
#include "openvino/pass/pattern/op/label.hpp"
#include "openvino/pass/pattern/op/pattern.hpp"
@@ -73,6 +77,15 @@ bool match_acl_int8_pooling_fq_chain(const std::shared_ptr<const ov::Node>& node
}
const auto pool = node->get_input_node_shared_ptr(0);
+ if (pool->output(0).get_target_inputs().size() != 1) {
+ return false;
+ }
+
+ const auto avg_pool = ov::as_type_ptr<const ov::op::util::AvgPoolBase>(pool);
+ if (avg_pool && avg_pool->get_rounding_type() == ov::op::RoundingType::CEIL) {
+ return false;
+ }
+
// returns true if Pooling-FQ chain will be fused into int8 pooling and handled by ACL executor
return any_of(node->get_output_element_type(0), ov::element::Type_t::u8, ov::element::Type_t::i8) &&
(ov::is_type_any_of<ov::op::v1::AvgPool, ov::op::v14::AvgPool, ov::op::v16::AvgPool>(pool) ||
@@ -90,6 +103,46 @@ bool match_acl_int8_conv_fq_chain(const std::shared_ptr<const ov::Node>& node) {
(match_conv_fq_same_types(node) || match_fq_mul_conv_bias_same_types(node, FQMulAddPattern::ConvAddMul));
}
+bool is_acl_int8_avg_pool_lpt_skipped(const std::shared_ptr<const ov::Node>& node,
+ const std::vector<ov::element::Type>& defaultPrecisions) {
+ const auto avg_pool = ov::as_type_ptr<const ov::op::util::AvgPoolBase>(node);
+ if (!avg_pool) {
+ return true;
+ }
+
+ const auto& input_pshape = avg_pool->get_input_partial_shape(0);
+ const auto input_rank = input_pshape.rank();
+ if (input_rank.is_dynamic() || input_rank.get_length() == 5) {
+ return true;
+ }
+
+ const auto dequantization = ov::pass::low_precision::NetworkHelper::getDequantization(avg_pool, defaultPrecisions);
+ if (dequantization.empty() ||
+ !any_of(dequantization.data.get_element_type(), ov::element::Type_t::u8, ov::element::Type_t::i8)) {
+ return true;
+ }
+
+ // ACL rejects NCHW AvgPool with CEIL rounding in the executor wrapper.
+ if (avg_pool->get_rounding_type() == op::RoundingType::CEIL) {
+ return true;
+ }
+
+ const auto& consumers = avg_pool->output(0).get_target_inputs();
+ if (consumers.size() != 1) {
+ return true;
+ }
+
+ const auto fq = ov::as_type_ptr<ov::op::v0::FakeQuantize>(consumers.begin()->get_node()->shared_from_this());
+ if (!fq) {
+ return true;
+ }
+
+ const auto resolved_precision = ov::pass::low_precision::ResolvePrecisionAttribute::getDataPrecision(fq);
+ return resolved_precision.empty() ||
+ !any_of(resolved_precision.precision, ov::element::Type_t::u8, ov::element::Type_t::i8) ||
+ dequantization.data.get_element_type() != resolved_precision.precision;
+}
+
bool match_conv_stride_oc_ic_limit(const std::shared_ptr<const ov::Node>& node,
const std::vector<int64_t>& strides,
const ov::Shape& kernel_shape,
diff --git a/src/plugins/intel_cpu/src/transformations/utils.hpp b/src/plugins/intel_cpu/src/transformations/utils.hpp
index 89da875fe9c..5acbe43cba7 100644
--- a/src/plugins/intel_cpu/src/transformations/utils.hpp
+++ b/src/plugins/intel_cpu/src/transformations/utils.hpp
@@ -59,6 +59,9 @@ bool match_acl_int8_conv_fq_chain(const std::shared_ptr<const ov::Node>& node);
bool match_acl_int8_pooling_fq_chain(const std::shared_ptr<const ov::Node>& node);
+bool is_acl_int8_avg_pool_lpt_skipped(const std::shared_ptr<const ov::Node>& node,
+ const std::vector<ov::element::Type>& defaultPrecisions);
+
bool match_conv_stride_oc_ic_limit(const std::shared_ptr<const ov::Node>& node,
const std::vector<int64_t>& strides,
const ov::Shape& kernel_shape,