From 4dafbe9c52a4fe4fae92a48395b8e5009338038d Mon Sep 17 00:00:00 2001 From: Egor Duplensky Date: Wed, 17 Apr 2024 17:40:53 +0200 Subject: [PATCH] [CPU] Avoid extra copy of const inputs to the weights cache --- src/plugins/intel_cpu/src/nodes/input.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/plugins/intel_cpu/src/nodes/input.cpp b/src/plugins/intel_cpu/src/nodes/input.cpp index 03054af7054..fa47a34eac8 100644 --- a/src/plugins/intel_cpu/src/nodes/input.cpp +++ b/src/plugins/intel_cpu/src/nodes/input.cpp @@ -375,15 +375,23 @@ void Input::cloneBlobIfRequired() { auto weightCache = context->getWeightsCache(); - if (weightCache) { - MemoryPtr ptr = *weightCache->findOrCreate(blobKey(), cloneBlob); - memoryPtr = std::const_pointer_cast(ptr); - // IRs already have all subnormals flushed to zero, but in - // read_model scenario with directly loaded original model still can have subnormals - } else if (prec != element::string && isBlobAligned() && (!needFlushDenormalsToZero || !hasSubnormals()) && !isWA()) { + // if (weightCache) { + // MemoryPtr ptr = *weightCache->findOrCreate(blobKey(), cloneBlob); + // memoryPtr = std::const_pointer_cast(ptr); + // // IRs already have all subnormals flushed to zero, but in + // // read_model scenario with directly loaded original model still can have subnormals + // } else + if (prec != element::string && isBlobAligned() && (!needFlushDenormalsToZero || !hasSubnormals()) && !isWA()) { memoryPtr = std::make_shared(getEngine(), memDesc, constOp->get_data_ptr()); } else { - memoryPtr = std::const_pointer_cast(cloneBlob()); + if (weightCache) { + MemoryPtr ptr = *weightCache->findOrCreate(blobKey(), cloneBlob); + memoryPtr = std::const_pointer_cast(ptr); + // IRs already have all subnormals flushed to zero, but in + // read_model scenario with directly loaded original model still can have subnormals + } else { + memoryPtr = std::const_pointer_cast(cloneBlob()); + } } }