diff --git a/src/plugins/intel_cpu/src/edge.cpp b/src/plugins/intel_cpu/src/edge.cpp index d502413a79b..4b5f784f57e 100644 --- a/src/plugins/intel_cpu/src/edge.cpp +++ b/src/plugins/intel_cpu/src/edge.cpp @@ -596,8 +596,11 @@ EdgePtr Edge::getBaseEdge(int look) { for (auto &ch_edge : ch_edges) { auto &chch_conf = ch_edge->getChild()->getSelectedPrimitiveDescriptor()->getConfig(); - if (chch_conf.inConfs[ch_edge->getOutputNum()].inPlace() >= 0) + if (chch_conf.inConfs[ch_edge->getOutputNum()].inPlace() >= 0) { next_ch_edge = ch_edge; + // To align with upstream-inplace, we stop searching once found the first inplace consumer + break; + } } return next_ch_edge->getBaseEdge(LOOK_DOWN); } else if (parentConfig.outConfs[inputNum].inPlace() >= 0 && (look & LOOK_UP)) { @@ -614,6 +617,7 @@ EdgePtr Edge::getBaseEdge(int look) { for (auto edge : edges_for_same_port) { if (edge.get() != this) { auto base = edge->getBaseEdge(LOOK_BOTH | LOOK_NO_RECURRENT); + // Return once found the first inplace consumer if (base != edge && base != edges_for_same_port[0]) return base; } } diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/concat_reorder_inplace.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/concat_reorder_inplace.cpp new file mode 100644 index 00000000000..495942f7bca --- /dev/null +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/concat_reorder_inplace.cpp @@ -0,0 +1,66 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include "ngraph_functions/builders.hpp" +#include "ngraph_functions/utils/ngraph_helpers.hpp" +#include "shared_test_classes/base/layer_test_utils.hpp" +#include "test_utils/cpu_test_utils.hpp" + +using namespace CPUTestUtils; +using namespace ngraph; + +namespace SubgraphTestsDefinitions { +// Subgraph: +/* + * paramter1 parameter2 + * \ / + * \ / + * Concat (inPlace) + * / | \ + * / | \ + * Reorder Reorder Reorder (the reorder nodes are optimized and use inplace memory mode) + * / | \ + * / | \ + * Multiply Multiply Multiply + * / | \ + * / | \ + * Result Result Result + */ + +class ConcatReorderInPlaceTest : virtual public LayerTestsUtils::LayerTestsCommon { +public: + void SetUp() override { + const std::vector inputShape = {1, 100, 1, 1}; + auto inputParams = ngraph::builder::makeParams(ngraph::element::f32, {inputShape, inputShape}); + auto concat = ngraph::builder::makeConcat(ngraph::OutputVector{inputParams[0], inputParams[1]}, 1); + const auto targetFormat = nhwc; + auto mul1 = std::make_shared( + concat, + ngraph::builder::makeConstant(ngraph::element::f32, Shape{1}, std::vector{4})); + mul1->get_rt_info() = CPUTestsBase::makeCPUInfo({targetFormat}, {targetFormat}, {}); + auto mul2 = std::make_shared( + concat, + ngraph::builder::makeConstant(ngraph::element::f32, Shape{1}, std::vector{5})); + mul2->get_rt_info() = CPUTestsBase::makeCPUInfo({targetFormat}, {targetFormat}, {}); + auto mul3 = std::make_shared( + concat, + ngraph::builder::makeConstant(ngraph::element::f32, Shape{1}, std::vector{6})); + mul3->get_rt_info() = CPUTestsBase::makeCPUInfo({targetFormat}, {targetFormat}, {}); + + ngraph::ResultVector results{std::make_shared(mul1), + std::make_shared(mul2), + std::make_shared(mul3)}; + function = std::make_shared(results, inputParams, "ConcatReorderInPlace"); + targetDevice = CommonTestUtils::DEVICE_CPU; + } +}; + +namespace { +TEST_F(ConcatReorderInPlaceTest, smoke_ConcatReorderInPlace_CPU) { + Run(); +} +} // namespace +} // namespace SubgraphTestsDefinitions