From c6707aab86e3647af6bd17e53f0f1b59322f786e Mon Sep 17 00:00:00 2001 From: Aleksandr Voron Date: Tue, 24 Oct 2023 16:45:48 +0200 Subject: [PATCH] [CPU] Add input type check into in-place condition (#20529) --- src/plugins/intel_cpu/src/edge.cpp | 4 +- .../subgraph_tests/src/inplace_edge.cpp | 77 +++++++++++++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 src/plugins/intel_cpu/tests/functional/subgraph_tests/src/inplace_edge.cpp diff --git a/src/plugins/intel_cpu/src/edge.cpp b/src/plugins/intel_cpu/src/edge.cpp index 734fd462acb..ba3474fddf2 100644 --- a/src/plugins/intel_cpu/src/edge.cpp +++ b/src/plugins/intel_cpu/src/edge.cpp @@ -450,7 +450,9 @@ void Edge::init() { DEBUG_LOG(*this, " getBaseEdge() return itself"); changeStatus(Status::NeedAllocation); } else { - if (edgePtr->getParent()->isConstant() && !edgePtr->getChild()->isConstant()) { + if (Type::Input == edgePtr->getParent()->getType() && + edgePtr->getParent()->isConstant() && + !edgePtr->getChild()->isConstant()) { changeStatus(Status::NeedAllocation); DEBUG_LOG(*this, " edge inplace from ", *edgePtr, " is broken!"); return; diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/inplace_edge.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/inplace_edge.cpp new file mode 100644 index 00000000000..1385313ce88 --- /dev/null +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/inplace_edge.cpp @@ -0,0 +1,77 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include "test_utils/cpu_test_utils.hpp" +#include "shared_test_classes/base/layer_test_utils.hpp" +#include "ov_models/utils/ov_helpers.hpp" +#include "ov_models/builders.hpp" + +using namespace CPUTestUtils; +using namespace InferenceEngine; + +namespace SubgraphTestsDefinitions { +// If a node (CumSum) with constant parents has several non-constant nodes (Eltwises) than the edge is broken. +// The fix is to check node type - is should be Input. +// Subgraph: +/* + * Constant Constant + * \ / + * \ / + * CumSum + * Parameter / \ Parameter + * \ / \ / + * \ / \ / + * Eltwise Eltwise + * \ / + * Eltwise + * | + * Result + */ + +using namespace ov::test; + +class NonInputInPlaceTest : public testing::WithParamInterface, + virtual public SubgraphBaseTest { +public: + static std::string getTestCaseName(testing::TestParamInfo obj) { + std::ostringstream result; + result << "NonInputInPlaceTest_inPrc=outPrc=" << obj.param; + return result.str(); + } + + void SetUp() override { + targetDevice = utils::DEVICE_CPU; + configuration.insert({ov::hint::inference_precision.name(), ov::element::f16.to_string()}); + const std::vector inputShape = {1, 11, 3, 3}; + targetStaticShapes = {{inputShape, inputShape}}; + ElementType prc = this->GetParam(); + + ov::ParameterVector inputParams {std::make_shared(prc, ov::Shape(inputShape)), + std::make_shared(prc, ov::Shape(inputShape))}; + + auto cumsum_tensor = ngraph::opset8::Constant::create(prc, inputShape, {10.0f}); + auto axis_node = ngraph::opset8::Constant::create(ngraph::element::i32, {}, {0}); + const auto cumsum = std::make_shared(cumsum_tensor, axis_node); + + auto eltwiseMul = ngraph::builder::makeEltwise(inputParams[0], cumsum, ngraph::helpers::EltwiseTypes::MULTIPLY); + auto eltwiseAdd1 = ngraph::builder::makeEltwise(inputParams[1], cumsum, ngraph::helpers::EltwiseTypes::ADD); + auto eltwiseAdd2 = ngraph::builder::makeEltwise(eltwiseAdd1, eltwiseMul, ngraph::helpers::EltwiseTypes::ADD); + + ngraph::ResultVector results{std::make_shared(eltwiseAdd2)}; + function = std::make_shared(results, inputParams, "NonInputInPlaceT"); + } +}; + +namespace { + TEST_P(NonInputInPlaceTest, CompareWithRefs) { + run(); + } + +INSTANTIATE_TEST_SUITE_P(smoke_NonInputInPlaceTest_CPU, NonInputInPlaceTest, + testing::Values(ngraph::element::f32, ngraph::element::f16), + NonInputInPlaceTest::getTestCaseName); + +} // namespace +} // namespace SubgraphTestsDefinitions