Skip to content

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

[CPU] Allow a Reduce with an empty axes list (#38447)

Łukasz Ślusarczyk405eb32bbad9
diff --git a/src/plugins/intel_cpu/src/nodes/executors/acl/acl_reduce.hpp b/src/plugins/intel_cpu/src/nodes/executors/acl/acl_reduce.hpp
index 1edb9b74142..260d90f80ea 100644
--- a/src/plugins/intel_cpu/src/nodes/executors/acl/acl_reduce.hpp
+++ b/src/plugins/intel_cpu/src/nodes/executors/acl/acl_reduce.hpp
@@ -42,6 +42,10 @@ public:
[[nodiscard]] bool isSupported(const ReduceAttrs& reduceAttrs,
const std::vector<MemoryDescPtr>& srcDescs,
const std::vector<MemoryDescPtr>& dstDescs) const override {
+ if (reduceAttrs.axes.empty()) {
+ DEBUG_LOG("ACL has no reduction primitive for an empty axes list");
+ return false;
+ }
if (!aclSupported({srcDescs[0], dstDescs[0]})) {
DEBUG_LOG("ACL common preconditions are not met");
return false;
diff --git a/src/plugins/intel_cpu/src/nodes/reduce.cpp b/src/plugins/intel_cpu/src/nodes/reduce.cpp
index af917f4408d..1ac1e7e2c3f 100644
--- a/src/plugins/intel_cpu/src/nodes/reduce.cpp
+++ b/src/plugins/intel_cpu/src/nodes/reduce.cpp
@@ -2112,7 +2112,7 @@ void Reduce::getSupportedDescriptors() {
bool is_emulated_0d_as_1d =
getInputShapeAtPort(REDUCE_DATA).getRank() == 1 && getOutputShapeAtPort(0).getRank() == 1;
const bool rank_condition = getInputShapeAtPort(REDUCE_DATA).getRank() <= getOutputShapeAtPort(0).getRank();
- const bool invalid_config = rank_condition && !is_emulated_0d_as_1d;
+ const bool invalid_config = rank_condition && !is_emulated_0d_as_1d && !raw_axes.empty();
CPU_NODE_ASSERT(!invalid_config, "gets incorrect number of input/output dimensions!");
}
}
diff --git a/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/instances/arm/reduce.cpp b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/instances/arm/reduce.cpp
index 230ecc49ee5..07a17119c56 100644
--- a/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/instances/arm/reduce.cpp
+++ b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/instances/arm/reduce.cpp
@@ -25,6 +25,10 @@ std::vector<std::vector<ov::test::InputShape>> inputShapes_5D_ZeroDim = {
{{{}, {{2, 19, 0, 2, 0}}}},
};
+std::vector<std::vector<ov::test::InputShape>> inputShapes_EmptyAxes = {
+ {{{}, {{2, 19, 2, 9}}}},
+};
+
const std::vector<std::vector<int>> axes5D = {
{2, 4},
{1, 2, 4},
@@ -84,6 +88,26 @@ const auto params_MultiAxis_5D_ZeroDim_ref =
testing::Values(emptyFusingSpec),
testing::ValuesIn(additionalConfigFP32()));
+std::vector<CPUSpecificParams> cpuParams_4D_ref = {
+ CPUSpecificParams({nchw}, {nchw}, {"ref"}, {"ref"}),
+};
+
+// An empty axes list reduces nothing, so the output keeps the shape of the input.
+// ACL has no reduction primitive for such a list, so the reference implementation is
+// used, and it is registered with the f32 precision only.
+const auto params_EmptyAxes_ref =
+ testing::Combine(testing::Combine(testing::Values(std::vector<int>{}),
+ testing::Values(ov::test::utils::OpType::VECTOR),
+ testing::Values(false),
+ testing::ValuesIn(reductionTypes()),
+ testing::ValuesIn(inpOutPrc()),
+ testing::Values(ElementType::dynamic),
+ testing::Values(ElementType::dynamic),
+ testing::ValuesIn(inputShapes_EmptyAxes)),
+ testing::ValuesIn(filterCPUSpecificParams(cpuParams_4D_ref)),
+ testing::Values(emptyFusingSpec),
+ testing::ValuesIn(additionalConfigFP32()));
+
//There are dedicated instences of smoke_Reduce_MultiAxis_5D_CPU test in arm and x64 folders
//because ACL does not support 0 as reduction axis
INSTANTIATE_TEST_SUITE_P(
@@ -108,6 +132,14 @@ INSTANTIATE_TEST_SUITE_P(
ReduceCPULayerTest::getTestCaseName
);
+// Reference implementation testing of ACL unsupported case
+INSTANTIATE_TEST_SUITE_P(
+ smoke_Reduce_EmptyAxes_CPU_ref,
+ ReduceCPULayerTest,
+ params_EmptyAxes_ref,
+ ReduceCPULayerTest::getTestCaseName
+);
+
} // namespace
} // namespace Reduce
} // namespace test
diff --git a/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/instances/x64/reduce.cpp b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/instances/x64/reduce.cpp
index e9306f3c21a..bc6a10e85bb 100644
--- a/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/instances/x64/reduce.cpp
+++ b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/instances/x64/reduce.cpp
@@ -59,6 +59,10 @@ std::vector<std::vector<ov::test::InputShape>> inputShapes_Dynmic_ZeroDim = {
{{{2, 0, -1, -1}, {{2, 0, 3, 0}}}}
};
+std::vector<std::vector<ov::test::InputShape>> inputShapes_EmptyAxes = {
+ {{{}, {{2, 19, 2, 9}}}},
+};
+
std::vector<CPUSpecificParams> cpuParams_3D = {
CPUSpecificParams({ncw}, {ncw}, {}, {}),
};
@@ -204,6 +208,19 @@ const auto params_OneAxis = testing::Combine(testing::Combine(testing::ValuesIn(
testing::Values(emptyFusingSpec),
testing::ValuesIn(additionalConfig()));
+// An empty axes list reduces nothing, so the output keeps the shape of the input.
+const auto params_EmptyAxes = testing::Combine(testing::Combine(testing::Values(std::vector<int>{}),
+ testing::Values(ov::test::utils::OpType::VECTOR),
+ testing::Values(false),
+ testing::ValuesIn(reductionTypes()),
+ testing::ValuesIn(inpOutPrc()),
+ testing::Values(ElementType::dynamic),
+ testing::Values(ElementType::dynamic),
+ testing::ValuesIn(inputShapes_EmptyAxes)),
+ testing::Values(emptyCPUSpec),
+ testing::Values(emptyFusingSpec),
+ testing::ValuesIn(additionalConfig()));
+
const auto params_MultiAxis_4D = testing::Combine(testing::Combine(testing::ValuesIn(axesND()),
testing::Values(ov::test::utils::OpType::VECTOR),
testing::Values(true),
@@ -335,6 +352,13 @@ INSTANTIATE_TEST_SUITE_P(
ReduceCPULayerTest::getTestCaseName
);
+INSTANTIATE_TEST_SUITE_P(
+ smoke_Reduce_EmptyAxes_CPU,
+ ReduceCPULayerTest,
+ params_EmptyAxes,
+ ReduceCPULayerTest::getTestCaseName
+);
+
INSTANTIATE_TEST_SUITE_P(
smoke_Reduce_MultiAxis_4D_CPU,
ReduceCPULayerTest,