[CPU] Avoid using cache for constant inplace or multi-child edges (#10573)

This commit is contained in:
Egor Duplensky
2022-03-05 14:37:50 +03:00
committed by GitHub
parent 3b8ca9f0af
commit 3b8e960b10

View File

@@ -288,11 +288,37 @@ std::string MKLDNNEdge::name() const {
return result.str(); return result.str();
} }
void MKLDNNEdge::externalAllocate(MKLDNNWeightsSharing::Ptr weightsCache) { 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) if (status != Status::NeedAllocation)
return; 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] () { auto alloc = [this] () {
allocate(); allocate();
return memoryPtr; return memoryPtr;