Skip to content

Commit

Permalink
Apply review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
xuchen-intel committed Dec 1, 2024
1 parent 59eb559 commit 6f7ad9c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 159 deletions.
43 changes: 17 additions & 26 deletions src/plugins/intel_cpu/src/nodes/reduce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2030,22 +2030,7 @@ void Reduce::initSupportedPrimitiveDescriptors() {
dstMemoryDescs.push_back(config.outConfs[i].getMemDesc());
}

auto attrs = reduceAttrs;
bool apply_ref = customImplPriorities.size() > 0 && customImplPriorities[0] == ref;
bool single_axis_only = one_of(algorithm, Algorithm::ReduceSum, Algorithm::ReduceMax,
Algorithm::ReduceMin, Algorithm::ReduceProd);
// For the case of empty input, transformations ConvertReduceProd(Min, Max, Sum) are disabled to avoid empty output.
// So these 4 reduce modes with empty input reducing more than one axis are not supported by acl executor. Then
// factory->isEmpty() returns true, supportedPrimitiveDescriptors is emtpy. Though we don't actually need these acl
// kernels in execution, here we pass a fake axis {1} to pass assertion of "!supportedPrimitiveDescriptors.empty()"
// in Node::filterSupportedPrimitiveDescriptors().
if (!apply_ref && !isDynamicNode() && single_axis_only) {
const auto& src_shape = getInputShapeAtPort(REDUCE_DATA).getStaticDims();
if (shape_size(src_shape) == 0) {
attrs.axes = {1};
}
}
auto factory = std::make_shared<ReduceExecutorFactory>(attrs, srcMemoryDescs, dstMemoryDescs,
auto factory = std::make_shared<ReduceExecutorFactory>(reduceAttrs, srcMemoryDescs, dstMemoryDescs,
std::make_shared<ExecutorContext>(context, getImplPriority()));
if (!factory->isEmpty()) {
supportedPrimitiveDescriptors.push_back({config, impl_type, factory});
Expand All @@ -2057,16 +2042,22 @@ void Reduce::initSupportedPrimitiveDescriptors() {
};

#if defined (OV_CPU_WITH_ACL)
reduceAttrs.operation = algorithm;
reduceAttrs.keepDims = keep_dims;
reduceAttrs.axes = raw_axes;
for (auto &axis : reduceAttrs.axes) {
if (axis < 0)
axis += static_cast<int>(getInputShapeAtPort(REDUCE_DATA).getRank());
// acl doesn't support empty input
if (!isDynamicNode() && shape_size(getInputShapeAtPort(REDUCE_DATA).getStaticDims()) == 0) {
canUseAclExecutor = false;
} else {
reduceAttrs.operation = algorithm;
reduceAttrs.keepDims = keep_dims;
reduceAttrs.axes = raw_axes;
for (auto &axis : reduceAttrs.axes) {
if (axis < 0)
axis += static_cast<int>(getInputShapeAtPort(REDUCE_DATA).getRank());
}
pushDesc(LayoutType::nspc, LayoutType::nspc, input_prec, output_prec, impl_desc_type::undef, true);
pushDesc(LayoutType::ncsp, LayoutType::ncsp, input_prec, output_prec, impl_desc_type::undef, true);
canUseAclExecutor = !supportedPrimitiveDescriptors.empty();
}
pushDesc(LayoutType::nspc, LayoutType::nspc, input_prec, output_prec, impl_desc_type::undef, true);
pushDesc(LayoutType::ncsp, LayoutType::ncsp, input_prec, output_prec, impl_desc_type::undef, true);
canUseAclExecutor = !supportedPrimitiveDescriptors.empty();

if (canUseAclExecutor)
return;
#endif
Expand Down Expand Up @@ -2114,7 +2105,7 @@ void Reduce::prepareParams() {
auto dstMemPtr = getDstMemoryAtPort(0);
const auto& src_shape = srcMemPtr->getStaticDims();
dst_size = dstMemPtr->getSize();
empty_input = shape_size(src_shape) == 0 || srcMemPtr->getSize() == 0;
empty_input = shape_size(src_shape) == 0;
#if defined (OV_CPU_WITH_ACL)
if (canUseAclExecutor) {
std::vector<MemoryDescPtr> srcMemoryDescs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,34 +49,6 @@ const auto params_MultiAxis_5D = testing::Combine(
testing::Values(emptyFusingSpec),
testing::ValuesIn(additionalConfig()));

const auto params_MultiAxis_5D_ZeroDim = testing::Combine(
testing::Combine(
testing::ValuesIn(axes5D),
testing::Values(ov::test::utils::OpType::VECTOR),
testing::Values(true),
testing::ValuesIn(reductionTypesArithmetic()),
testing::ValuesIn(inpOutPrc()),
testing::Values(ElementType::undefined),
testing::Values(ElementType::undefined),
testing::ValuesIn(inputShapes_5D_ZeroDim)),
testing::ValuesIn(filterCPUSpecificParams(cpuParams_5D)),
testing::Values(emptyFusingSpec),
testing::ValuesIn(additionalConfig()));

const auto params_MultiAxis_5D_ZeroDim_Compare = testing::Combine(
testing::Combine(
testing::ValuesIn(axes5D),
testing::Values(ov::test::utils::OpType::VECTOR),
testing::Values(true),
testing::ValuesIn(reductionTypesCompare()),
testing::ValuesIn(inpOutPrc()),
testing::Values(ElementType::undefined),
testing::Values(ElementType::undefined),
testing::ValuesIn(inputShapes_5D_ZeroDim)),
testing::ValuesIn(filterCPUSpecificParams(cpuParams_5D)),
testing::Values(emptyFusingSpec),
testing::ValuesIn(additionalConfigFP32()));

const std::vector<std::vector<int>> axes5D_ref = {
{0}
};
Expand All @@ -103,6 +75,20 @@ const auto params_MultiAxis_5D_ref = testing::Combine(
testing::Values(emptyFusingSpec),
testing::ValuesIn(config_infer_prec_f32));

const auto params_MultiAxis_5D_ZeroDim_ref = testing::Combine(
testing::Combine(
testing::ValuesIn(axes5D),
testing::Values(ov::test::utils::OpType::VECTOR),
testing::Values(true),
testing::ValuesIn(reductionTypes()),
testing::ValuesIn(inpOutPrc()),
testing::Values(ElementType::undefined),
testing::Values(ElementType::undefined),
testing::ValuesIn(inputShapes_5D_ZeroDim)),
testing::ValuesIn(filterCPUSpecificParams(cpuParams_5D_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(
Expand All @@ -112,25 +98,18 @@ INSTANTIATE_TEST_SUITE_P(
ReduceCPULayerTest::getTestCaseName
);

// Reference implementation testing of ACL unsupported case
INSTANTIATE_TEST_SUITE_P(
smoke_Reduce_MultiAxis_5D_ZeroDim_CPU,
ReduceCPULayerTest,
params_MultiAxis_5D_ZeroDim,
ReduceCPULayerTest::getTestCaseName
);

INSTANTIATE_TEST_SUITE_P(
smoke_Reduce_MultiAxis_5D_ZeroDim_Compare_CPU,
smoke_Reduce_MultiAxis_5D_CPU_ref,
ReduceCPULayerTest,
params_MultiAxis_5D_ZeroDim_Compare,
params_MultiAxis_5D_ref,
ReduceCPULayerTest::getTestCaseName
);

// Reference implementation testing of ACL unsupported case
INSTANTIATE_TEST_SUITE_P(
smoke_Reduce_MultiAxis_5D_CPU_ref,
smoke_Reduce_MultiAxis_5D_ZeroDim_CPU_ref,
ReduceCPULayerTest,
params_MultiAxis_5D_ref,
params_MultiAxis_5D_ZeroDim_ref,
ReduceCPULayerTest::getTestCaseName
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,6 @@ const std::vector<std::vector<int>> axesGather = {
{3}
};

const std::vector<std::vector<int>> axesZeroDim {
{1, 3},
{0, 1, 3},
{1, 2, 3},
{0, 1, 2, 3}
};

const std::vector<std::vector<int>> axesZeroDimFusing = {
{1, 3},
};
Expand Down Expand Up @@ -161,6 +154,17 @@ const auto fusingFakeQuantizeTranspose = fusingSpecificParams{std::make_shared<p
return ov::builder::subgraph::makeTranspose(fakeQuantize, transpose);
}, "FakeQuantize(PerTensor)"}}), {"FakeQuantize"}};

const std::vector<fusingSpecificParams> fusingParamsFullSet {
emptyFusingSpec,
/* activations */
fusingSwish,
/* FQ */
fusingFakeQuantizePerChannelRelu,
fusingFakeQuantizePerTensorRelu,
/* another patterns */
fusingScaleShift
};

const std::vector<fusingSpecificParams> fusingParamsSet {
/* activations */
fusingSwish,
Expand Down Expand Up @@ -342,34 +346,6 @@ const auto params_SingleBatch = testing::Combine(
testing::Values(emptyFusingSpec),
testing::ValuesIn(additionalConfig()));

const auto params_DimZero_Arithmetic = testing::Combine(
testing::Combine(
testing::ValuesIn(axesZeroDim),
testing::Values(ov::test::utils::OpType::VECTOR),
testing::ValuesIn(keepDims()),
testing::ValuesIn(reductionTypesArithmetic()),
testing::ValuesIn(inpOutPrc()),
testing::Values(ElementType::undefined),
testing::Values(ElementType::undefined),
testing::ValuesIn(inputShapes_Dynmic_ZeroDim)),
testing::Values(emptyCPUSpec),
testing::Values(emptyFusingSpec),
testing::ValuesIn(additionalConfig()));

const auto params_DimZero_Compare = testing::Combine(
testing::Combine(
testing::ValuesIn(axesZeroDim),
testing::Values(ov::test::utils::OpType::VECTOR),
testing::ValuesIn(keepDims()),
testing::ValuesIn(reductionTypesCompare()),
testing::ValuesIn(inpOutPrc()),
testing::Values(ElementType::undefined),
testing::Values(ElementType::undefined),
testing::ValuesIn(inputShapes_Dynmic_ZeroDim)),
testing::Values(emptyCPUSpec),
testing::Values(emptyFusingSpec),
testing::ValuesIn(additionalConfigFP32()));

INSTANTIATE_TEST_SUITE_P(
smoke_Reduce_OneAxis_CPU,
ReduceCPULayerTest,
Expand Down Expand Up @@ -447,20 +423,6 @@ INSTANTIATE_TEST_SUITE_P(
ReduceCPULayerTest::getTestCaseName
);

INSTANTIATE_TEST_SUITE_P(
smoke_Reduce_DimZero_Arithmetic_CPU,
ReduceCPULayerTest,
params_DimZero_Arithmetic,
ReduceCPULayerTest::getTestCaseName
);

INSTANTIATE_TEST_SUITE_P(
smoke_Reduce_DimZero_Compare_CPU,
ReduceCPULayerTest,
params_DimZero_Compare,
ReduceCPULayerTest::getTestCaseName
);

/* ================================ 1.2 No fusion - Logical ================================ */
const auto params_OneAxis_Logical = testing::Combine(
testing::Combine(
Expand Down Expand Up @@ -670,7 +632,7 @@ const auto params_DimZero_Arithmetic_fusing = testing::Combine(
testing::Values(ElementType::undefined),
testing::ValuesIn(inputShapes_Dynmic_ZeroDim)),
testing::Values(emptyCPUSpec),
testing::ValuesIn(fusingParamsSet),
testing::ValuesIn(fusingParamsFullSet),
testing::ValuesIn(additionalConfig()));

const auto params_DimZero_Compare_fusing = testing::Combine(
Expand All @@ -684,7 +646,7 @@ const auto params_DimZero_Compare_fusing = testing::Combine(
testing::Values(ElementType::undefined),
testing::ValuesIn(inputShapes_Dynmic_ZeroDim)),
testing::Values(emptyCPUSpec),
testing::ValuesIn(fusingParamsSet),
testing::ValuesIn(fusingParamsFullSet),
testing::ValuesIn(additionalConfigFP32()));

INSTANTIATE_TEST_SUITE_P(
Expand Down Expand Up @@ -779,34 +741,6 @@ const auto params_MultiAxis_5D_Hybrid_fusing_KeepNoDims = testing::Combine(
testing::ValuesIn(fusingParamsSet_KeepNoDims),
testing::ValuesIn(additionalConfigFP32()));

const auto params_DimZero_Arithmetic_fusing_KeepNoDims = testing::Combine(
testing::Combine(
testing::ValuesIn(axesZeroDimFusing),
testing::Values(ov::test::utils::OpType::VECTOR),
testing::Values(false),
testing::ValuesIn(reductionTypesArithmetic()),
testing::ValuesIn(inpOutPrc()),
testing::Values(ElementType::undefined),
testing::Values(ElementType::undefined),
testing::ValuesIn(inputShapes_Dynmic_ZeroDim)),
testing::Values(emptyCPUSpec),
testing::ValuesIn(fusingParamsSet_KeepNoDims),
testing::ValuesIn(additionalConfig()));

const auto params_DimZero_Compare_fusing_KeepNoDims = testing::Combine(
testing::Combine(
testing::ValuesIn(axesZeroDimFusing),
testing::Values(ov::test::utils::OpType::VECTOR),
testing::Values(false),
testing::ValuesIn(reductionTypesCompare()),
testing::ValuesIn(inpOutPrc()),
testing::Values(ElementType::undefined),
testing::Values(ElementType::undefined),
testing::ValuesIn(inputShapes_Dynmic_ZeroDim)),
testing::Values(emptyCPUSpec),
testing::ValuesIn(fusingParamsSet_KeepNoDims),
testing::ValuesIn(additionalConfigFP32()));

INSTANTIATE_TEST_SUITE_P(
smoke_Reduce_OneAxis_fusing_KeepNoDims_CPU,
ReduceCPULayerTest,
Expand All @@ -828,20 +762,6 @@ INSTANTIATE_TEST_SUITE_P(
ReduceCPULayerTest::getTestCaseName
);

INSTANTIATE_TEST_SUITE_P(
smoke_Reduce_DimZero_Arithmetic_fusing_KeepNoDims_CPU,
ReduceCPULayerTest,
params_DimZero_Arithmetic_fusing_KeepNoDims,
ReduceCPULayerTest::getTestCaseName
);

INSTANTIATE_TEST_SUITE_P(
smoke_Reduce_DimZero_Comapre_fusing_KeepNoDims_CPU,
ReduceCPULayerTest,
params_DimZero_Arithmetic_fusing_KeepNoDims,
ReduceCPULayerTest::getTestCaseName
);

} // namespace
} // namespace Reduce
} // namespace test
Expand Down

0 comments on commit 6f7ad9c

Please sign in to comment.