From 3b8e960b10815167372b6c7cf7f4d8a86493806b Mon Sep 17 00:00:00 2001 From: Egor Duplensky Date: Sat, 5 Mar 2022 14:37:50 +0300 Subject: [PATCH] [CPU] Avoid using cache for constant inplace or multi-child edges (#10573) --- src/plugins/intel_cpu/src/edge.cpp | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/plugins/intel_cpu/src/edge.cpp b/src/plugins/intel_cpu/src/edge.cpp index 5c93554b953..a95e983a9a6 100644 --- a/src/plugins/intel_cpu/src/edge.cpp +++ b/src/plugins/intel_cpu/src/edge.cpp @@ -288,11 +288,37 @@ std::string MKLDNNEdge::name() const { return result.str(); } + + void MKLDNNEdge::externalAllocate(MKLDNNWeightsSharing::Ptr weightsCache) { + auto isInPlace = [](const MKLDNNNodePtr node, int port) -> bool { + const auto& selected_pd = node->getSelectedPrimitiveDescriptor(); + if (selected_pd == nullptr) + IE_THROW() << "Preferable primitive descriptor is not set."; + + const auto& config = selected_pd->getConfig(); + + for (const auto& in : config.inConfs) { + if (in.inPlace() == port) { + return true; + } + } + for (const auto& out : config.outConfs) { + if (out.inPlace() == port) { + return true; + } + } + + return false; + }; + if (status != Status::NeedAllocation) return; - if (weightsCache) { + bool isTheOnlyChildEdgeAtPort = getParent()->getChildEdgesAtPort(getInputNum()).size() == 1; + bool isConcurrentUpdatePossible = isInPlace(getParent(), getInputNum()) || isInPlace(getChild(), getOutputNum()) || !isTheOnlyChildEdgeAtPort; + + if (weightsCache && !isConcurrentUpdatePossible) { auto alloc = [this] () { allocate(); return memoryPtr;