From f211b01505486d4e936b345a6e6d6c3acd7dddc3 Mon Sep 17 00:00:00 2001 From: Maksim Kutakov Date: Mon, 5 Aug 2024 13:11:31 +0200 Subject: [PATCH] Rename mem manager to mem block --- src/plugins/intel_cpu/src/cpu_memory.cpp | 173 +++++++----------- src/plugins/intel_cpu/src/cpu_memory.h | 138 ++++++-------- src/plugins/intel_cpu/src/dnnl_scratch_pad.h | 6 +- src/plugins/intel_cpu/src/edge.cpp | 8 +- src/plugins/intel_cpu/src/edge.h | 2 +- src/plugins/intel_cpu/src/graph.cpp | 32 ++-- src/plugins/intel_cpu/src/graph.h | 2 +- src/plugins/intel_cpu/src/infer_request.cpp | 44 ++--- src/plugins/intel_cpu/src/infer_request.h | 14 +- src/plugins/intel_cpu/src/node.cpp | 12 +- src/plugins/intel_cpu/src/nodes/concat.cpp | 8 +- src/plugins/intel_cpu/src/nodes/conv.cpp | 2 +- src/plugins/intel_cpu/src/nodes/deconv.cpp | 4 +- src/plugins/intel_cpu/src/nodes/gather.cpp | 6 +- src/plugins/intel_cpu/src/nodes/memory.cpp | 36 ++-- src/plugins/intel_cpu/src/nodes/memory.hpp | 4 +- src/plugins/intel_cpu/src/nodes/split.cpp | 6 +- .../intel_cpu/src/partitioned_mem_mgr.cpp | 24 +-- .../intel_cpu/src/partitioned_mem_mgr.h | 19 +- src/plugins/intel_cpu/src/proxy_mem_mgr.cpp | 54 +++--- src/plugins/intel_cpu/src/proxy_mem_mgr.h | 26 +-- 21 files changed, 278 insertions(+), 342 deletions(-) diff --git a/src/plugins/intel_cpu/src/cpu_memory.cpp b/src/plugins/intel_cpu/src/cpu_memory.cpp index ab454382f57d73..8229c0b1605b42 100644 --- a/src/plugins/intel_cpu/src/cpu_memory.cpp +++ b/src/plugins/intel_cpu/src/cpu_memory.cpp @@ -66,7 +66,7 @@ namespace { Memory::Memory(const dnnl::engine& eng, MemoryDescPtr desc, const void* data, bool pads_zeroing) : m_eng(eng), m_pMemDesc(desc), - m_mgrHandle(std::make_shared(make_unique()), this), + m_blockHandle(std::make_shared(make_unique()), this), dnnlMemHandle(this) { if (desc->getPrecision() == element::string) { OPENVINO_THROW("[CPU] Memory object cannot be created for string data."); @@ -77,18 +77,18 @@ Memory::Memory(const dnnl::engine& eng, MemoryDescPtr desc, const void* data, bo Memory::Memory(const dnnl::engine& eng, const MemoryDesc& desc, const void* data, bool pads_zeroing) : Memory::Memory(eng, desc.clone(), data, pads_zeroing) {} -Memory::Memory(const dnnl::engine& eng, MemoryDescPtr desc, MemoryMngrPtr mngr) : - m_eng(eng), m_pMemDesc(desc), m_mgrHandle(mngr, this), dnnlMemHandle(this) { +Memory::Memory(const dnnl::engine& eng, MemoryDescPtr desc, MemoryBlockPtr block) : + m_eng(eng), m_pMemDesc(desc), m_blockHandle(block, this), dnnlMemHandle(this) { if (desc->getPrecision() == element::string) { OPENVINO_THROW("[CPU] Memory object can't be created for string data."); } - bool memAllocated = m_mgrHandle->getRawPtr(); + bool memAllocated = m_blockHandle->getRawPtr(); create(desc, nullptr, !memAllocated); } -Memory::Memory(const dnnl::engine& eng, const MemoryDesc& desc, MemoryMngrPtr mngr) : - Memory::Memory(eng, desc.clone(), mngr) {} +Memory::Memory(const dnnl::engine& eng, const MemoryDesc& desc, MemoryBlockPtr block) : + Memory::Memory(eng, desc.clone(), block) {} size_t Memory::getSize() const { auto size = getDesc().getCurrentMemSize(); @@ -112,9 +112,9 @@ void Memory::create(MemoryDescPtr desc, const void* data, bool pads_zeroing) { } auto memSize = m_pMemDesc->getCurrentMemSize(); if (nullptr != data) { - m_mgrHandle->setExtBuff(const_cast(data), memSize); + m_blockHandle->setExtBuff(const_cast(data), memSize); } else { - m_mgrHandle->resize(memSize); + m_blockHandle->resize(memSize); } } @@ -145,7 +145,7 @@ void Memory::redefineDesc(MemoryDescPtr desc) { void Memory::update() { if (dnnlMemHandle.isInit()) { auto prim = dnnlMemHandle.getPrim(); - prim.set_data_handle(m_mgrHandle->getRawPtr()); + prim.set_data_handle(m_blockHandle->getRawPtr()); } } @@ -185,7 +185,7 @@ dnnl::memory Memory::DnnlMemPrimHandle::getPrim() const { } bool Memory::isAllocated() const noexcept { - if (m_mgrHandle->getRawPtr()) { + if (m_blockHandle->getRawPtr()) { return true; } if (!m_pMemDesc) { @@ -209,17 +209,17 @@ void* Memory::getData() const { return data; } -void* MemoryMngrWithReuse::getRawPtr() const noexcept { +void* MemoryBlockWithReuse::getRawPtr() const noexcept { return m_data.get(); } -void MemoryMngrWithReuse::setExtBuff(void *ptr, size_t size) { +void MemoryBlockWithReuse::setExtBuff(void *ptr, size_t size) { m_useExternalStorage = true; m_memUpperBound = size; m_data = decltype(m_data)(ptr, release); } -bool MemoryMngrWithReuse::resize(size_t size) { +bool MemoryBlockWithReuse::resize(size_t size) { constexpr int cacheLineSize = 64; bool sizeChanged = false; if (size > m_memUpperBound) { @@ -234,63 +234,20 @@ bool MemoryMngrWithReuse::resize(size_t size) { if (numa_node >= 0) { if (!mbind_move(ptr, size, numa_node)) { - DEBUG_LOG("MemoryMngrWithReuse move_memory to node ", numa_node, " failed\n"); + DEBUG_LOG("MemoryBlockWithReuse move_memory to node ", numa_node, " failed\n"); } } } return sizeChanged; } -bool MemoryMngrWithReuse::hasExtBuffer() const noexcept { +bool MemoryBlockWithReuse::hasExtBuffer() const noexcept { return m_useExternalStorage; } -void MemoryMngrWithReuse::release(void *ptr) {} +void MemoryBlockWithReuse::release(void *ptr) {} -void MemoryMngrWithReuse::destroy(void *ptr) { - dnnl::impl::free(ptr); -} - -void* MemoryMngrRealloc::getRawPtr() const noexcept { - return m_data.get(); -} - -void MemoryMngrRealloc::setExtBuff(void *ptr, size_t size) { - m_useExternalStorage = true; - m_memUpperBound = size; - m_data = decltype(m_data)(ptr, release); -} - -bool MemoryMngrRealloc::resize(size_t size) { - constexpr int cacheLineSize = 64; - constexpr size_t growFactor = 2; - bool sizeChanged = false; - if (size > m_memUpperBound) { - size *= growFactor; - void *ptr = dnnl::impl::malloc(size, cacheLineSize); - if (!ptr) { - OPENVINO_THROW("Failed to allocate ", size, " bytes of memory"); - } - - if (auto src = m_data.get()) { - std::memcpy(ptr, src, m_memUpperBound); - } - - m_memUpperBound = size; - m_useExternalStorage = false; - m_data = decltype(m_data)(ptr, destroy); - sizeChanged = true; - } - return sizeChanged; -} - -bool MemoryMngrRealloc::hasExtBuffer() const noexcept { - return m_useExternalStorage; -} - -void MemoryMngrRealloc::release(void *ptr) {} - -void MemoryMngrRealloc::destroy(void *ptr) { +void MemoryBlockWithReuse::destroy(void *ptr) { dnnl::impl::free(ptr); } @@ -301,7 +258,7 @@ StringMemory::StringMemory(const dnnl::engine& engine, const MemoryDescPtr& desc OPENVINO_THROW("[CPU] StringMemory supports String type only."); } - m_manager = std::make_shared(); + m_memoryBlock = std::make_shared(); if (!m_mem_desc->isDefined()) { return; @@ -311,9 +268,9 @@ StringMemory::StringMemory(const dnnl::engine& engine, const MemoryDescPtr& desc if (data != nullptr) { auto not_const_data = const_cast(data); - m_manager->setExtBuff(reinterpret_cast(not_const_data), string_size); + m_memoryBlock->setExtBuff(reinterpret_cast(not_const_data), string_size); } else { - m_manager->resize(string_size); + m_memoryBlock->resize(string_size); } } @@ -326,7 +283,7 @@ void StringMemory::load(const IMemory& src, bool ftz) const { } void* StringMemory::getData() const { - return m_manager->getRawPtr(); + return m_memoryBlock->getRawPtr(); } void StringMemory::redefineDesc(MemoryDescPtr desc) { @@ -339,13 +296,13 @@ void StringMemory::redefineDesc(MemoryDescPtr desc) { m_mem_desc = desc; const auto string_size = m_mem_desc->getShape().getElementsCount(); - m_manager->resize(string_size); + m_memoryBlock->resize(string_size); } void StringMemory::nullify() { - auto data_ptr = m_manager->getStringPtr(); + auto data_ptr = m_memoryBlock->getStringPtr(); if (data_ptr != nullptr) { - std::fill(data_ptr, data_ptr + m_manager->getStrLen(), OvString()); + std::fill(data_ptr, data_ptr + m_memoryBlock->getStrLen(), OvString()); } } @@ -373,25 +330,25 @@ size_t StringMemory::getSize() const { // In bytes return size; } -MemoryMngrPtr StringMemory::getMemoryMngr() const { - OPENVINO_THROW("Unexpected call of StringMemory::getMemoryMngr()"); +MemoryBlockPtr StringMemory::getMemoryBlock() const { + OPENVINO_THROW("Unexpected call of StringMemory::getMemoryBlock()"); } dnnl::memory StringMemory::getPrimitive() const { OPENVINO_THROW("Unexpected call of StringMemory::getPrimitive()"); } -void StringMemory::StringMemoryMngr::setExtBuff(OvString* ptr, size_t size) { +void StringMemory::StringMemoryBlock::setExtBuff(OvString* ptr, size_t size) { m_use_external_storage = true; m_str_upper_bound = size; m_data = decltype(m_data)(ptr, release); } -StringMemory::OvString* StringMemory::StringMemoryMngr::getStringPtr() const noexcept { +StringMemory::OvString* StringMemory::StringMemoryBlock::getStringPtr() const noexcept { return m_data.get(); } -bool StringMemory::StringMemoryMngr::resize(size_t size) { +bool StringMemory::StringMemoryBlock::resize(size_t size) { bool sizeChanged = false; if (size > m_str_upper_bound) { if (size > PTRDIFF_MAX) { @@ -410,58 +367,58 @@ bool StringMemory::StringMemoryMngr::resize(size_t size) { return sizeChanged; } -bool StringMemory::StringMemoryMngr::hasExtBuffer() const noexcept { +bool StringMemory::StringMemoryBlock::hasExtBuffer() const noexcept { return m_use_external_storage; } -size_t StringMemory::StringMemoryMngr::getStrLen() const noexcept { +size_t StringMemory::StringMemoryBlock::getStrLen() const noexcept { return m_str_upper_bound; } -void StringMemory::StringMemoryMngr::destroy(OvString* ptr) { +void StringMemory::StringMemoryBlock::destroy(OvString* ptr) { delete[] ptr; } -void* StringMemory::StringMemoryMngr::getRawPtr() const noexcept { +void* StringMemory::StringMemoryBlock::getRawPtr() const noexcept { return reinterpret_cast(m_data.get()); } -/////////////// DnnlMemoryMngr /////////////// +/////////////// DnnlMemoryBlock /////////////// -void* DnnlMemoryMngr::getRawPtr() const noexcept { - return m_pMemMngr->getRawPtr(); +void* DnnlMemoryBlock::getRawPtr() const noexcept { + return m_pMemBlock->getRawPtr(); } -void DnnlMemoryMngr::setExtBuff(void *ptr, size_t size) { - m_pMemMngr->setExtBuff(ptr, size); +void DnnlMemoryBlock::setExtBuff(void *ptr, size_t size) { + m_pMemBlock->setExtBuff(ptr, size); notifyUpdate(); } -bool DnnlMemoryMngr::resize(size_t size) { - bool sizeChanged = m_pMemMngr->resize(size); +bool DnnlMemoryBlock::resize(size_t size) { + bool sizeChanged = m_pMemBlock->resize(size); if (sizeChanged) { notifyUpdate(); } return sizeChanged; } -bool DnnlMemoryMngr::hasExtBuffer() const noexcept { - return m_pMemMngr->hasExtBuffer(); +bool DnnlMemoryBlock::hasExtBuffer() const noexcept { + return m_pMemBlock->hasExtBuffer(); } -void DnnlMemoryMngr::registerMemory(Memory* memPtr) { +void DnnlMemoryBlock::registerMemory(Memory* memPtr) { if (memPtr) { m_setMemPtrs.insert(memPtr); } } -void DnnlMemoryMngr::unregisterMemory(Memory* memPtr) { +void DnnlMemoryBlock::unregisterMemory(Memory* memPtr) { if (memPtr) { m_setMemPtrs.erase(memPtr); } } -void DnnlMemoryMngr::notifyUpdate() { +void DnnlMemoryBlock::notifyUpdate() { for (auto& item : m_setMemPtrs) { if (item) { item->update(); @@ -481,9 +438,9 @@ StaticMemory::StaticMemory(const dnnl::engine& eng, MemoryDescPtr desc, const vo m_size = m_pMemDesc->getCurrentMemSize(); if (data) { - m_pMemMngr = std::make_shared(const_cast(data), m_size); + m_pMemBlock = std::make_shared(const_cast(data), m_size); } else { - m_pMemMngr = std::make_shared(m_size); + m_pMemBlock = std::make_shared(m_size); } try { @@ -494,7 +451,7 @@ StaticMemory::StaticMemory(const dnnl::engine& eng, MemoryDescPtr desc, const vo m_prim = dnnl::memory(dnnl_desc->getDnnlDesc(), m_eng, DNNL_MEMORY_NONE); // // ======================== - m_prim.set_data_handle(m_pMemMngr->getRawPtr()); + m_prim.set_data_handle(m_pMemBlock->getRawPtr()); } catch (const std::exception& exc) { dnnlErrorCtx = exc.what(); @@ -517,7 +474,7 @@ MemoryDescPtr StaticMemory::getDescPtr() const { } void* StaticMemory::getData() const { - return m_pMemMngr->getRawPtr(); + return m_pMemBlock->getRawPtr(); } size_t StaticMemory::getSize() const { @@ -543,8 +500,8 @@ void StaticMemory::load(const IMemory& src, bool ftz) const { transferData(src, *this, ftz); } -MemoryMngrPtr StaticMemory::getMemoryMngr() const { - return m_pMemMngr; +MemoryBlockPtr StaticMemory::getMemoryBlock() const { + return m_pMemBlock; } //oneDNN specifics for backward compatibility @@ -561,38 +518,38 @@ void StaticMemory::nullify() { memset(dataPtr, 0, getSize()); } -StaticMemory::StaticMemoryMngr::StaticMemoryMngr(size_t size) : m_size(size) { - memMngrImpl.resize(m_size); +StaticMemory::StaticMemoryBlock::StaticMemoryBlock(size_t size) : m_size(size) { + memBlockImpl.resize(m_size); } -StaticMemory::StaticMemoryMngr::StaticMemoryMngr(void* data, size_t size) : m_size(size) { - memMngrImpl.setExtBuff(data, m_size); +StaticMemory::StaticMemoryBlock::StaticMemoryBlock(void* data, size_t size) : m_size(size) { + memBlockImpl.setExtBuff(data, m_size); } -void* StaticMemory::StaticMemoryMngr::getRawPtr() const noexcept { - return memMngrImpl.getRawPtr(); +void* StaticMemory::StaticMemoryBlock::getRawPtr() const noexcept { + return memBlockImpl.getRawPtr(); } -void StaticMemory::StaticMemoryMngr::setExtBuff(void* ptr, size_t size) { - OPENVINO_THROW("Unexpected: StaticMemoryMngr may not be modified"); +void StaticMemory::StaticMemoryBlock::setExtBuff(void* ptr, size_t size) { + OPENVINO_THROW("Unexpected: StaticMemoryBlock may not be modified"); } -bool StaticMemory::StaticMemoryMngr::resize(size_t size) { +bool StaticMemory::StaticMemoryBlock::resize(size_t size) { if (size != m_size) { - OPENVINO_THROW("Unexpected: StaticMemoryMngr may not resize the memory"); + OPENVINO_THROW("Unexpected: StaticMemoryBlock may not resize the memory"); } return false; } -bool StaticMemory::StaticMemoryMngr::hasExtBuffer() const noexcept { - return memMngrImpl.hasExtBuffer(); +bool StaticMemory::StaticMemoryBlock::hasExtBuffer() const noexcept { + return memBlockImpl.hasExtBuffer(); } -void StaticMemory::StaticMemoryMngr::registerMemory(Memory* memPtr) { +void StaticMemory::StaticMemoryBlock::registerMemory(Memory* memPtr) { //do nothing } -void StaticMemory::StaticMemoryMngr::unregisterMemory(Memory* memPtr) { +void StaticMemory::StaticMemoryBlock::unregisterMemory(Memory* memPtr) { //do nothing } diff --git a/src/plugins/intel_cpu/src/cpu_memory.h b/src/plugins/intel_cpu/src/cpu_memory.h index 69b70cb6e583a3..65d61bc97a2693 100644 --- a/src/plugins/intel_cpu/src/cpu_memory.h +++ b/src/plugins/intel_cpu/src/cpu_memory.h @@ -29,16 +29,16 @@ namespace ov { namespace intel_cpu { class Memory; -class ProxyMemoryMngr; +class ProxyMemoryBlock; /** - * @interface IMemoryMngr + * @interface IMemoryBlock * @brief An interface to memory control object */ -class IMemoryMngr { +class IMemoryBlock { public: - virtual ~IMemoryMngr() = default; + virtual ~IMemoryBlock() = default; /** * @brief Accessor to underlying memory buffer @@ -68,11 +68,11 @@ class IMemoryMngr { }; /** - * @brief An implementation of the mem manager where memory reallocation occurs only if a bigger buffer is requested. + * @brief An implementation of the mem block where memory reallocation occurs only if a bigger buffer is requested. */ -class MemoryMngrWithReuse : public IMemoryMngr { +class MemoryBlockWithReuse : public IMemoryBlock { public: - MemoryMngrWithReuse(int numa_node = -1) : m_data(nullptr, release), numa_node(numa_node) {} + MemoryBlockWithReuse(int numa_node = -1) : m_data(nullptr, release), numa_node(numa_node) {} void* getRawPtr() const noexcept override; void setExtBuff(void* ptr, size_t size) override; bool resize(size_t size) override; @@ -88,24 +88,7 @@ class MemoryMngrWithReuse : public IMemoryMngr { static void destroy(void *ptr); }; -class MemoryMngrRealloc : public IMemoryMngr { -public: - MemoryMngrRealloc() : m_data(nullptr, release) {} - void* getRawPtr() const noexcept override; - void setExtBuff(void* ptr, size_t size) override; - bool resize(size_t size) override; - bool hasExtBuffer() const noexcept override; - -private: - bool m_useExternalStorage = false; - size_t m_memUpperBound = 0ul; - std::unique_ptr m_data; - - static void release(void *ptr); - static void destroy(void *ptr); -}; - -class IMemoryMngrObserver : public IMemoryMngr { +class IMemoryBlockObserver : public IMemoryBlock { public: virtual void registerMemory(Memory* memPtr) = 0; virtual void unregisterMemory(Memory* memPtr) = 0; @@ -114,9 +97,9 @@ class IMemoryMngrObserver : public IMemoryMngr { /** * @brief A proxy object that additionally implements observer pattern */ -class DnnlMemoryMngr : public IMemoryMngrObserver { +class DnnlMemoryBlock : public IMemoryBlockObserver { public: - explicit DnnlMemoryMngr(std::unique_ptr mngr) : m_pMemMngr(std::move(mngr)) {} + explicit DnnlMemoryBlock(std::unique_ptr memBlock) : m_pMemBlock(std::move(memBlock)) {} void* getRawPtr() const noexcept override; void setExtBuff(void* ptr, size_t size) override; bool resize(size_t size) override; @@ -129,49 +112,49 @@ class DnnlMemoryMngr : public IMemoryMngrObserver { private: std::unordered_set m_setMemPtrs; - std::unique_ptr m_pMemMngr; + std::unique_ptr m_pMemBlock; }; -using MemoryMngrPtr = std::shared_ptr; -using MemoryMngrCPtr = std::shared_ptr; +using MemoryBlockPtr = std::shared_ptr; +using MemoryBlockCPtr = std::shared_ptr; -class DnnlMemMngrHandle { +class DnnlMemBlockHandle { public: - DnnlMemMngrHandle(MemoryMngrPtr pMgr, Memory* pMem) : m_pMgr(pMgr), m_pMem(pMem) { - if (m_pMgr) { - m_pMgr->registerMemory(m_pMem); + DnnlMemBlockHandle(MemoryBlockPtr pBlock, Memory* pMem) : m_pMemBlock(pBlock), m_pMem(pMem) { + if (m_pMemBlock) { + m_pMemBlock->registerMemory(m_pMem); } } - DnnlMemMngrHandle(const DnnlMemMngrHandle&) = delete; - DnnlMemMngrHandle& operator= (const DnnlMemMngrHandle&) = delete; + DnnlMemBlockHandle(const DnnlMemBlockHandle&) = delete; + DnnlMemBlockHandle& operator= (const DnnlMemBlockHandle&) = delete; - DnnlMemMngrHandle(DnnlMemMngrHandle&& source) { - std::swap(m_pMgr, source.m_pMgr); + DnnlMemBlockHandle(DnnlMemBlockHandle&& source) { + std::swap(m_pMemBlock, source.m_pMemBlock); std::swap(m_pMem, source.m_pMem); } - DnnlMemMngrHandle& operator= (DnnlMemMngrHandle&& rhs) { - std::swap(m_pMgr, rhs.m_pMgr); + DnnlMemBlockHandle& operator= (DnnlMemBlockHandle&& rhs) { + std::swap(m_pMemBlock, rhs.m_pMemBlock); std::swap(m_pMem, rhs.m_pMem); return *this; } - ~DnnlMemMngrHandle() { - if (m_pMgr) { - m_pMgr->unregisterMemory(m_pMem); + ~DnnlMemBlockHandle() { + if (m_pMemBlock) { + m_pMemBlock->unregisterMemory(m_pMem); } } - MemoryMngrPtr get() const { - return m_pMgr; + MemoryBlockPtr get() const { + return m_pMemBlock; } - MemoryMngrPtr::element_type* operator->() const noexcept { - return m_pMgr.get(); + MemoryBlockPtr::element_type* operator->() const noexcept { + return m_pMemBlock.get(); } private: - MemoryMngrPtr m_pMgr = nullptr; + MemoryBlockPtr m_pMemBlock = nullptr; Memory* m_pMem = nullptr; }; @@ -200,13 +183,13 @@ class IMemory { virtual const VectorDims& getStaticDims() const = 0; // Redefines descriptor. The memory descriptor will be replaced with the new one. - // Memory will not be reallocated if the new tensor size is less or equal the upper bound. + // Memory will not be reallocated according to the dynamic memory block policy // Caution!!! This action invalidates the previous data layout. The old data may become unreachable. virtual void redefineDesc(MemoryDescPtr desc) = 0; virtual void load(const IMemory& src, bool ftz = true) const = 0; - virtual MemoryMngrPtr getMemoryMngr() const = 0; + virtual MemoryBlockPtr getMemoryBlock() const = 0; //oneDNN specifics for backward compatibility virtual dnnl::memory getPrimitive() const = 0; @@ -229,10 +212,10 @@ class IMemory { class StaticMemory final : public IMemory { public: - class StaticMemoryMngr : public IMemoryMngrObserver { + class StaticMemoryBlock : public IMemoryBlockObserver { public: - explicit StaticMemoryMngr(size_t size); - StaticMemoryMngr(void* data, size_t size); + explicit StaticMemoryBlock(size_t size); + StaticMemoryBlock(void* data, size_t size); void* getRawPtr() const noexcept override; void setExtBuff(void* ptr, size_t size) override; bool resize(size_t size) override; @@ -242,10 +225,10 @@ class StaticMemory final : public IMemory { private: size_t m_size = 0; - MemoryMngrWithReuse memMngrImpl; + MemoryBlockWithReuse memBlockImpl; }; - using MemMngrPtr = std::shared_ptr; + using MemBlockPtr = std::shared_ptr; public: StaticMemory(const dnnl::engine& eng, MemoryDescPtr desc, const void* data = nullptr, bool pads_zeroing = true); @@ -273,7 +256,7 @@ class StaticMemory final : public IMemory { void load(const IMemory& src, bool ftz = true) const override; - MemoryMngrPtr getMemoryMngr() const override; + MemoryBlockPtr getMemoryBlock() const override; //oneDNN specifics for backward compatibility dnnl::memory getPrimitive() const override; @@ -285,7 +268,7 @@ class StaticMemory final : public IMemory { MemoryDescPtr m_pMemDesc; size_t m_size; dnnl::memory m_prim; - MemMngrPtr m_pMemMngr; + MemBlockPtr m_pMemBlock; std::string dnnlErrorCtx; }; @@ -293,8 +276,8 @@ class Memory : public IMemory { public: Memory(const dnnl::engine& eng, MemoryDescPtr desc, const void* data = nullptr, bool pads_zeroing = true); Memory(const dnnl::engine& eng, const MemoryDesc& desc, const void* data = nullptr, bool pads_zeroing = true); - Memory(const dnnl::engine& eng, MemoryDescPtr desc, MemoryMngrPtr mngr); - Memory(const dnnl::engine& eng, const MemoryDesc& desc, MemoryMngrPtr mbgr); + Memory(const dnnl::engine& eng, MemoryDescPtr desc, MemoryBlockPtr block); + Memory(const dnnl::engine& eng, const MemoryDesc& desc, MemoryBlockPtr block); Memory(const Memory&) = delete; Memory& operator= (const Memory&) = delete; @@ -326,9 +309,6 @@ class Memory : public IMemory { return getDesc().getShape().getStaticDims(); } - // Redefines descriptor. The memory descriptor will be replaced with the new one. - // Memory will not be reallocated if the new tensor size is less or equal the upper bound. - // Caution!!! This action invalidates the previous data layout. The old data may become unreachable. void redefineDesc(MemoryDescPtr desc) override; void load(const IMemory& src, bool ftz = true) const override; @@ -338,13 +318,13 @@ class Memory : public IMemory { return m_eng; } - MemoryMngrPtr getMemoryMngr() const override { - return m_mgrHandle.get(); + MemoryBlockPtr getMemoryBlock() const override { + return m_blockHandle.get(); } private: - friend DnnlMemoryMngr; - friend ProxyMemoryMngr; + friend DnnlMemoryBlock; + friend ProxyMemoryBlock; private: void update(); @@ -355,7 +335,7 @@ class Memory : public IMemory { private: dnnl::engine m_eng; MemoryDescPtr m_pMemDesc; - DnnlMemMngrHandle m_mgrHandle; + DnnlMemBlockHandle m_blockHandle; bool m_padsZeroing = true; class DnnlMemPrimHandle { public: @@ -373,7 +353,7 @@ class Memory : public IMemory { } dnnlMemHandle; void* getDataNoThrow() const noexcept { - return m_mgrHandle->getRawPtr(); + return m_blockHandle->getRawPtr(); } }; @@ -381,9 +361,9 @@ class StringMemory : public IMemory { public: using OvString = ov::element_type_traits::value_type; - class StringMemoryMngr { + class StringMemoryBlock { public: - StringMemoryMngr() : m_data(nullptr, release) {} + StringMemoryBlock() : m_data(nullptr, release) {} OvString* getStringPtr() const noexcept; void setExtBuff(OvString* ptr, size_t size); size_t getStrLen() const noexcept; @@ -400,18 +380,18 @@ class StringMemory : public IMemory { static void destroy(OvString* ptr); }; - using StringMemoryMngrPtr = std::shared_ptr; + using StringMemoryBlockPtr = std::shared_ptr; StringMemory(const dnnl::engine& engine, const MemoryDescPtr& desc, const void* data = nullptr); StringMemory(const dnnl::engine& engine, const MemoryDesc& desc, const void* data = nullptr) : StringMemory(engine, desc.clone(), data) {} - StringMemory(const dnnl::engine& engine, const MemoryDescPtr& desc, const StringMemoryMngrPtr& manager) - : m_engine(engine), m_mem_desc(desc), m_manager(manager) {} + StringMemory(const dnnl::engine& engine, const MemoryDescPtr& desc, const StringMemoryBlockPtr& block) + : m_engine(engine), m_mem_desc(desc), m_memoryBlock(block) {} - StringMemory(const dnnl::engine& engine, const MemoryDesc& desc, const StringMemoryMngrPtr& manager) - : StringMemory(engine, desc.clone(), manager) {} + StringMemory(const dnnl::engine& engine, const MemoryDesc& desc, const StringMemoryBlockPtr& block) + : StringMemory(engine, desc.clone(), block) {} bool isAllocated() const noexcept override; @@ -439,10 +419,10 @@ class StringMemory : public IMemory { void load(const IMemory& src, bool ftz = false) const override; - MemoryMngrPtr getMemoryMngr() const override; + MemoryBlockPtr getMemoryBlock() const override; - StringMemoryMngrPtr getStringMemoryMngrPtr() const { - return m_manager; + StringMemoryBlockPtr getStringMemoryBlockPtr() const { + return m_memoryBlock; } dnnl::memory getPrimitive() const override; @@ -452,7 +432,7 @@ class StringMemory : public IMemory { private: dnnl::engine m_engine; MemoryDescPtr m_mem_desc; - StringMemoryMngrPtr m_manager; + StringMemoryBlockPtr m_memoryBlock; }; using MemoryPtr = std::shared_ptr; diff --git a/src/plugins/intel_cpu/src/dnnl_scratch_pad.h b/src/plugins/intel_cpu/src/dnnl_scratch_pad.h index a589b9dbb0cf71..6f356e58c4770b 100644 --- a/src/plugins/intel_cpu/src/dnnl_scratch_pad.h +++ b/src/plugins/intel_cpu/src/dnnl_scratch_pad.h @@ -13,16 +13,16 @@ namespace ov { namespace intel_cpu { class DnnlScratchPad { - MemoryMngrPtr mgrPtr; + MemoryBlockPtr blockPtr; dnnl::engine eng; public: DnnlScratchPad(const dnnl::engine& eng, int numa_node = -1) : eng(eng) { - mgrPtr = std::make_shared(make_unique(numa_node)); + blockPtr = std::make_shared(make_unique(numa_node)); } MemoryPtr createScratchPadMem(const MemoryDescPtr& md) { - return std::make_shared(eng, md, mgrPtr); + return std::make_shared(eng, md, blockPtr); } }; diff --git a/src/plugins/intel_cpu/src/edge.cpp b/src/plugins/intel_cpu/src/edge.cpp index c193cb1641285b..0a9bc4cae34ddf 100644 --- a/src/plugins/intel_cpu/src/edge.cpp +++ b/src/plugins/intel_cpu/src/edge.cpp @@ -273,14 +273,14 @@ void Edge::allocate(const void* mem_ptr) { allocateCommon(allocateFunc); } -void Edge::allocate(MemoryMngrPtr memMngr) { - if (!memMngr) { - OPENVINO_THROW("Unexpected: Memory manager ptr is NULL"); +void Edge::allocate(MemoryBlockPtr memBlock) { + if (!memBlock) { + OPENVINO_THROW("Unexpected: Memory block ptr is NULL"); } auto allocateFunc = [OV_CAPTURE_CPY_AND_THIS](const MemoryDesc& inputDesc) -> MemoryPtr { auto parentPtr = getParent(); - return std::make_shared(parentPtr->getEngine(), inputDesc, memMngr); + return std::make_shared(parentPtr->getEngine(), inputDesc, memBlock); }; allocateCommon(allocateFunc); diff --git a/src/plugins/intel_cpu/src/edge.h b/src/plugins/intel_cpu/src/edge.h index e9f26a2d8955b4..29cb8113943cd3 100644 --- a/src/plugins/intel_cpu/src/edge.h +++ b/src/plugins/intel_cpu/src/edge.h @@ -52,7 +52,7 @@ class Edge { void init(); void allocate(const void* mem_ptr = nullptr); - void allocate(MemoryMngrPtr memMngr); + void allocate(MemoryBlockPtr memBlock); void externalAllocate(WeightsSharing::Ptr weightsCache); void reuse(MemoryPtr ptr); void validate(); diff --git a/src/plugins/intel_cpu/src/graph.cpp b/src/plugins/intel_cpu/src/graph.cpp index c939eb15eb8555..fd8f211d25f10a 100644 --- a/src/plugins/intel_cpu/src/graph.cpp +++ b/src/plugins/intel_cpu/src/graph.cpp @@ -727,7 +727,7 @@ void Graph::AllocateWithReuse(const std::vector& syncNodesInds) { // Special allocation for string tensors if (edge->getDesc().getPrecision() == element::string && edge->getStatus() == Edge::Status::NeedAllocation) { - StringMemory::StringMemoryMngrPtr mngr; + StringMemory::StringMemoryBlockPtr memBlcok; if (edge->getParent()->isConstant()) { if (edge->getParent()->getType() == Type::Input) { auto constNode = static_cast(edge->getParent().get()); @@ -738,11 +738,11 @@ void Graph::AllocateWithReuse(const std::vector& syncNodesInds) { auto stringMemory = dynamic_cast(edge->getMemoryPtr().get()); OPENVINO_ASSERT(stringMemory, "[CPU] Edge between nodes '", edge->getParent()->getName(), "' and '", edge->getChild()->getName(), "' must have StringMemory."); - mngr = stringMemory->getStringMemoryMngrPtr(); + memBlcok = stringMemory->getStringMemoryBlockPtr(); } else { auto memory = std::make_shared(getEngine(), edge->getDesc()); edge->reuse(memory); - mngr = memory->getStringMemoryMngrPtr(); + memBlcok = memory->getStringMemoryBlockPtr(); } for (auto& edge_c : cluster) { if (edge_c == edge) { @@ -750,7 +750,7 @@ void Graph::AllocateWithReuse(const std::vector& syncNodesInds) { } OPENVINO_ASSERT(edge_c->getDesc().getPrecision() == element::string, "All edges in the cluster must be string."); if (edge_c->getStatus() == Edge::Status::NotAllocated) { - auto memory = std::make_shared(getEngine(), edge_c->getDesc(), mngr); + auto memory = std::make_shared(getEngine(), edge_c->getDesc(), memBlcok); edge_c->reuse(memory); } else { OPENVINO_THROW("[CPU] String tensors allocation in the cluster. Edge between nodes '", edge_c->getParent()->getName(), "' and '", @@ -868,23 +868,23 @@ void Graph::AllocateWithReuse(const std::vector& syncNodesInds) { //Process undefined boxes (dynamic shapes) if (!undefinedBoxes.empty()) { - // Use proxy memory manager for output edges + // Use proxy memory block for output edges for (const auto& box : undefinedBoxes) { for (auto& edge : edge_clusters[box.id]) { const auto child = edge->getChild(); if (child->getType() == Type::Output && edge->getStatus() == Edge::Status::NeedAllocation) { - auto proxyMemMngr = - std::make_shared(); - DEBUG_LOG("ProxyMemoryMngr ", proxyMemMngr, " ", this); - edge->allocate(proxyMemMngr); + auto proxyMemBlock = + std::make_shared(); + DEBUG_LOG("ProxyMemoryBlock ", proxyMemBlock, " ", this); + edge->allocate(proxyMemBlock); - // Store the output memory managers. + // Store the output memory blocks. // So that, the infer requests can be able to access them. int count = 0; for (auto &output : outputNodesMap) { if (output.second == child) { - outputNodesMemMngrMap[output.first] = proxyMemMngr; + outputNodesMemBlocksMap[output.first] = proxyMemBlock; count++; } } @@ -941,12 +941,12 @@ void Graph::AllocateWithReuse(const std::vector& syncNodesInds) { } } for (auto& group : groups) { - auto grpMemMngr = - std::make_shared(make_unique()); + auto grpMemBlock = + std::make_shared(make_unique()); for (auto& box : group) { for (auto& edge : edge_clusters[box.id]) { if (edge->getStatus() == Edge::Status::NeedAllocation) { - edge->allocate(grpMemMngr); + edge->allocate(grpMemBlock); } } } @@ -975,7 +975,7 @@ void Graph::AllocateWithReuse(const std::vector& syncNodesInds) { } else { auto sharedEdge = edge->getSharedEdge(); auto sharedEdgeParent = sharedEdge->getParent(); - edge->allocate(sharedEdge->getMemoryPtr()->getMemoryMngr()); + edge->allocate(sharedEdge->getMemoryPtr()->getMemoryBlock()); DEBUG_LOG(*edge, " sharedEdge with ", *sharedEdge); } } @@ -1021,7 +1021,7 @@ bool Graph::ProcessDynNodes() { return node->isDynamicNode(); }); // In case of dynamic shapes, tensors may be resized due to the shapes variations. - // If the input tensor is included to memory reuse, it means that its memory manager is shared with other tensors in the graph, which in turn may cause data + // If the input tensor is included to memory reuse, it means that its memory block is shared with other tensors in the graph, which in turn may cause data // loss when one of the tensors down the graph requests mem resize, while the input data have not been yet read by the consumers. To avoid such situations // we disable io mem reuse for the case of dynamic shapes. if (containsDynamicNodes) { diff --git a/src/plugins/intel_cpu/src/graph.h b/src/plugins/intel_cpu/src/graph.h index 4e6d6e6f3beca6..ffcc970af6a5b6 100644 --- a/src/plugins/intel_cpu/src/graph.h +++ b/src/plugins/intel_cpu/src/graph.h @@ -244,7 +244,7 @@ class Graph { std::map inputNodesMap; std::map outputNodesMap; - std::unordered_map outputNodesMemMngrMap; + std::unordered_map outputNodesMemBlocksMap; // these node pointers (from graphNodes) are to avoid regular checking for // constantness of nodes in Infer methods and calls of diff --git a/src/plugins/intel_cpu/src/infer_request.cpp b/src/plugins/intel_cpu/src/infer_request.cpp index 82b72137b6b561..c9ebddfbcbe018 100644 --- a/src/plugins/intel_cpu/src/infer_request.cpp +++ b/src/plugins/intel_cpu/src/infer_request.cpp @@ -154,13 +154,13 @@ static inline void change_edge_ptr(const EdgePtr& edge, ov::SoPtr& OPENVINO_ASSERT(mem != nullptr, "Edge with name '", edge->name(), "' doesn't have allocated memory object."); if (tensor->get_element_type() == element::string) { - auto memMngr = dynamic_cast(mem.get())->getStringMemoryMngrPtr(); - OPENVINO_ASSERT(memMngr); - memMngr->setExtBuff(tensor->data(), tensor->get_size()); + auto memBlock = dynamic_cast(mem.get())->getStringMemoryBlockPtr(); + OPENVINO_ASSERT(memBlock); + memBlock->setExtBuff(tensor->data(), tensor->get_size()); } else { - auto memMngr = mem->getMemoryMngr(); - OPENVINO_ASSERT(memMngr); - memMngr->setExtBuff(tensor->data(), tensor->get_byte_size()); + auto memBlock = mem->getMemoryBlock(); + OPENVINO_ASSERT(memBlock); + memBlock->setExtBuff(tensor->data(), tensor->get_byte_size()); } } @@ -271,13 +271,13 @@ void SyncInferRequest::change_default_ptr() { } if (Graph::Status::ReadyDynamic == m_graph->getStatus()) { - const auto &outMemMngrMap = m_graph->outputNodesMemMngrMap; - for (auto&& item : outMemMngrMap) { + const auto &outMemBlocksMap = m_graph->outputNodesMemBlocksMap; + for (auto&& item : outMemBlocksMap) { const auto& name = item.first; - // share intel_cpu::Tensor to Graph by injecting to corresponding ProxyMemoryMngr instance. - auto outputMemMngr = item.second; - OPENVINO_ASSERT(outputMemMngr, "proxy mem manager for output ", name, " is empty."); + // share intel_cpu::Tensor to Graph by injecting to corresponding ProxyMemoryBlock instance. + auto outputMemBlock = item.second; + OPENVINO_ASSERT(outputMemBlock, "proxy mem block for output ", name, " is empty."); auto controlBlockItr = m_outputControlBlocks.find(name); @@ -288,15 +288,15 @@ void SyncInferRequest::change_default_ptr() { //avoid cyclic memory use auto&& controlBlock = controlBlockItr->second; - std::shared_ptr memMngr = inputPtrs.count(controlBlock.rawPtr()) ? // same memory is used on the input and output - controlBlock.nextMemMngr() : // then swap internal buffer to avoid data corruption - controlBlock.currentMemMngr(); // else reuse the existing buffer + std::shared_ptr memBlock = inputPtrs.count(controlBlock.rawPtr()) ? // same memory is used on the input and output + controlBlock.nextMemBlock() : // then swap internal buffer to avoid data corruption + controlBlock.currentMemBlock(); // else reuse the existing buffer - outputMemMngr->setMemMngrResize(memMngr); - DEBUG_LOG("reset proxy ", outputMemMngr, ", actual ", controlBlock.currentMemMngr(), " graph ", m_graph, " inferrequest ", this); + outputMemBlock->setMemBlockResize(memBlock); + DEBUG_LOG("reset proxy ", outputMemBlock, ", actual ", controlBlock.currentMemBlock(), " graph ", m_graph, " inferrequest ", this); DEBUG_LOG(name, ", tensor ", controlBlock.tensor()); } else { - outputMemMngr->reset(); // switch to the internal memory since memory sharing is no longer possible + outputMemBlock->reset(); // switch to the internal memory since memory sharing is no longer possible } } } @@ -536,8 +536,8 @@ void SyncInferRequest::init_tensor(const std::size_t& port_index, const ov::ISyn DEBUG_LOG(port_index, ", tensor ", control_block.tensor(), - ", memmngr ", - control_block.tensor()->get_memory()->getMemoryMngr(), + ", memBlock ", + control_block.tensor()->get_memory()->getMemoryBlock(), "memory object ", control_block.tensor()->get_memory().get()); @@ -581,8 +581,8 @@ void SyncInferRequest::push_input_data() { SyncInferRequest::OutputControlBlock::OutputControlBlock(const ov::element::Type& precision, const Shape& shape) { dnnl::engine eng(dnnl::engine::kind::cpu, 0); - m_buffers[m_buffIndx] = std::make_shared(); - m_proxyMemMngr = std::make_shared(m_buffers[m_buffIndx]); + m_buffers[m_buffIndx] = std::make_shared(); + m_proxyMemBlock = std::make_shared(m_buffers[m_buffIndx]); VectorDims memDims; if (shape.isDynamic()) { // this is a WA since the ITensor doesn't allow dyn shapes @@ -596,7 +596,7 @@ SyncInferRequest::OutputControlBlock::OutputControlBlock(const ov::element::Type CpuBlockedMemoryDescPtr desc = std::make_shared(precision, Shape{memDims}); - auto memory = std::make_shared(eng, desc, m_proxyMemMngr); + auto memory = std::make_shared(eng, desc, m_proxyMemBlock); m_tensor = std::make_shared(memory); } diff --git a/src/plugins/intel_cpu/src/infer_request.h b/src/plugins/intel_cpu/src/infer_request.h index e3839466f0ce0e..9344baf1879fe9 100644 --- a/src/plugins/intel_cpu/src/infer_request.h +++ b/src/plugins/intel_cpu/src/infer_request.h @@ -50,7 +50,7 @@ class SyncInferRequest : public ov::ISyncInferRequest { private: class OutputControlBlock { public: - using MemMngrPtr = std::shared_ptr; + using MemBlockPtr = std::shared_ptr; public: OutputControlBlock(const ov::element::Type& precision, const Shape& shape); @@ -69,26 +69,26 @@ class SyncInferRequest : public ov::ISyncInferRequest { return m_tensor->get_memory()->getData(); } - MemMngrPtr currentMemMngr() const { + MemBlockPtr currentMemBlock() const { return m_buffers[m_buffIndx]; } - MemMngrPtr nextMemMngr() { + MemBlockPtr nextMemBlock() { m_buffIndx ^= 0x1; if (!m_buffers[m_buffIndx]) { - m_buffers[m_buffIndx] = std::make_shared(); + m_buffers[m_buffIndx] = std::make_shared(); } return m_buffers[m_buffIndx]; } void update() { - m_proxyMemMngr->setMemMngrResize(currentMemMngr()); + m_proxyMemBlock->setMemBlockResize(currentMemBlock()); } private: std::shared_ptr m_tensor = nullptr; - ProxyMemoryMngrPtr m_proxyMemMngr = nullptr; - std::array m_buffers; + ProxyMemoryBlockPtr m_proxyMemBlock = nullptr; + std::array m_buffers; int m_buffIndx = 0; }; diff --git a/src/plugins/intel_cpu/src/node.cpp b/src/plugins/intel_cpu/src/node.cpp index 326b3e907dcc8f..62c091c9985300 100644 --- a/src/plugins/intel_cpu/src/node.cpp +++ b/src/plugins/intel_cpu/src/node.cpp @@ -365,9 +365,9 @@ void Node::resolveInPlaceEdges(Edge::LOOK look) { " Could not find an allocated edge to resolve in-place for node: ", getName()); - auto baseMemMngr = (*itr)->getMemory().getMemoryMngr(); - auto memMngr = std::make_shared(baseMemMngr); - auto newMem = std::make_shared(getEngine(), selected_pd->getConfig().inConfs[i].getMemDesc(), memMngr); + auto baseMemBlock = (*itr)->getMemory().getMemoryBlock(); + auto memBlock = std::make_shared(baseMemBlock); + auto newMem = std::make_shared(getEngine(), selected_pd->getConfig().inConfs[i].getMemDesc(), memBlock); parentEdge->reuse(newMem); } } @@ -378,15 +378,15 @@ void Node::resolveInPlaceEdges(Edge::LOOK look) { if (inplaceInpIndx < 0) continue; - auto baseMemMngr = getParentEdgeAt(inplaceInpIndx)->getMemory().getMemoryMngr(); - auto memMngr = std::make_shared(baseMemMngr); + auto baseMemBlock = getParentEdgeAt(inplaceInpIndx)->getMemory().getMemoryBlock(); + auto memBlock = std::make_shared(baseMemBlock); const auto& childEdges = getChildEdgesAtPort(i); for (auto& childEdge : childEdges) { OPENVINO_ASSERT(childEdge->getStatus() == Edge::Status::NotAllocated, " Unexpected inplace resolve call to an allocated edge: ", childEdge->name()); - auto newMem = std::make_shared(getEngine(), selected_pd->getConfig().outConfs[i].getMemDesc(), memMngr); + auto newMem = std::make_shared(getEngine(), selected_pd->getConfig().outConfs[i].getMemDesc(), memBlock); childEdge->reuse(newMem); } } diff --git a/src/plugins/intel_cpu/src/nodes/concat.cpp b/src/plugins/intel_cpu/src/nodes/concat.cpp index f02863b6f707aa..216e2b135d6cff 100644 --- a/src/plugins/intel_cpu/src/nodes/concat.cpp +++ b/src/plugins/intel_cpu/src/nodes/concat.cpp @@ -694,8 +694,8 @@ void Concat::resolveInPlaceEdges(Edge::LOOK look) { auto itr = std::find_if(edges.begin(), edges.end(), [](const EdgePtr& edge) { return edge->getStatus() == Edge::Status::Allocated; }); OPENVINO_ASSERT(itr != edges.end(), " Could not find allocated child edge for concat node: " , getName()); - auto baseMemMngr = (*itr)->getMemory().getMemoryMngr(); - OPENVINO_ASSERT(baseMemMngr != nullptr, " NULL base memory manager in concat node: " , getName()); + auto baseMemBlock = (*itr)->getMemory().getMemoryBlock(); + OPENVINO_ASSERT(baseMemBlock != nullptr, " NULL base memory block in concat node: ", getName()); ptrdiff_t offset = 0; for (size_t i = 0; i < numberOfInputs; ++i) { @@ -714,8 +714,8 @@ void Concat::resolveInPlaceEdges(Edge::LOOK look) { auto memDesc = selected_pd->getConfig().inConfs[i].getMemDesc(); MemoryPtr newMem; if (partDim != 0) { - auto memMngr = std::make_shared(baseMemMngr, baseDim, offset, partDim); - newMem = std::make_shared(getEngine(), memDesc, memMngr); + auto memBlock = std::make_shared(baseMemBlock, baseDim, offset, partDim); + newMem = std::make_shared(getEngine(), memDesc, memBlock); } else { // empty tensor, no need to reference a part, default memory is enough newMem = std::make_shared(getEngine(), memDesc); diff --git a/src/plugins/intel_cpu/src/nodes/conv.cpp b/src/plugins/intel_cpu/src/nodes/conv.cpp index 2422e2d3bb041c..60c59ea13708bb 100644 --- a/src/plugins/intel_cpu/src/nodes/conv.cpp +++ b/src/plugins/intel_cpu/src/nodes/conv.cpp @@ -1531,7 +1531,7 @@ void Convolution::executeDynamicImpl(dnnl::stream strm) { const auto& sumInpMem = getParentEdgeAt(sumPortNum)->getMemory(); auto inp1 = subgraph->getInput(1); auto inp1Mem = inp1->getDstMemoryAtPort(0); - inp1Mem->getMemoryMngr()->setExtBuff(sumInpMem.getData(), sumInpMem.getSize()); + inp1Mem->getMemoryBlock()->setExtBuff(sumInpMem.getData(), sumInpMem.getSize()); subgraph->infer(); diff --git a/src/plugins/intel_cpu/src/nodes/deconv.cpp b/src/plugins/intel_cpu/src/nodes/deconv.cpp index d3f1ae0ba691a5..499f172eca3645 100644 --- a/src/plugins/intel_cpu/src/nodes/deconv.cpp +++ b/src/plugins/intel_cpu/src/nodes/deconv.cpp @@ -270,9 +270,9 @@ void Deconvolution::createDnnlCompatibleWeights() { Shape(dnnlCompatibleWeiDims), blockedDims, order); - // Create the memory with the edge memory mgr. In the case of the weight memory changes when inference, + // Create the memory with the edge memory block. In the case of the weight memory changes when inference, // dnnlCompatibleWeights memory would be updated automatically via update inform mechanism. - dnnlCompatibleWeights = std::make_shared(getEngine(), desc, blob->getMemoryMngr()); + dnnlCompatibleWeights = std::make_shared(getEngine(), desc, blob->getMemoryBlock()); } bool Deconvolution::canBeExecutedInInt8() const { diff --git a/src/plugins/intel_cpu/src/nodes/gather.cpp b/src/plugins/intel_cpu/src/nodes/gather.cpp index 434a32073aca4f..799ec3d480028b 100644 --- a/src/plugins/intel_cpu/src/nodes/gather.cpp +++ b/src/plugins/intel_cpu/src/nodes/gather.cpp @@ -945,7 +945,7 @@ void Gather::resolveInPlaceEdges(Edge::LOOK look) { "Gather node: ", getName(), " can not use inPlace memory with splitting on dynamic dimention"); - auto baseMemMngr = getParentEdgeAt(inplaceInpIndx)->getMemory().getMemoryMngr(); + auto baseMemBlock = getParentEdgeAt(inplaceInpIndx)->getMemory().getMemoryBlock(); const auto index = constIndices.front(); const ptrdiff_t offset = index < 0 ? baseDim + index : index; const auto& childEdges = getChildEdgesAtPort(outputPort); @@ -956,8 +956,8 @@ void Gather::resolveInPlaceEdges(Edge::LOOK look) { " with type ", getTypeStr()); - auto memMngr = std::make_shared(baseMemMngr, baseDim, offset); - auto newMem = std::make_shared(getEngine(), config.outConfs[outputPort].getMemDesc(), memMngr); + auto memBlock = std::make_shared(baseMemBlock, baseDim, offset); + auto newMem = std::make_shared(getEngine(), config.outConfs[outputPort].getMemDesc(), memBlock); childEdge->reuse(newMem); } diff --git a/src/plugins/intel_cpu/src/nodes/memory.cpp b/src/plugins/intel_cpu/src/nodes/memory.cpp index f372259b783e50..9e70720e50146d 100644 --- a/src/plugins/intel_cpu/src/nodes/memory.cpp +++ b/src/plugins/intel_cpu/src/nodes/memory.cpp @@ -59,8 +59,8 @@ class MemoryStub : public IMemory { OPENVINO_THROW("Unexpected call MemoryStub::load()"); } - MemoryMngrPtr getMemoryMngr() const override { - OPENVINO_THROW("Unexpected call MemoryStub::getMemoryMngr()"); + MemoryBlockPtr getMemoryBlock() const override { + OPENVINO_THROW("Unexpected call MemoryStub::getMemoryBlock()"); } dnnl::memory getPrimitive() const override { @@ -233,8 +233,8 @@ void MemoryOutput::resolveInPlaceEdges(Edge::LOOK look) { " Unexpected inplace resolve call to an allocated edge: ", parentEdge->name()); auto memDesc = selected_pd->getConfig().inConfs.front().getMemDesc(); - memMngr = std::make_shared(); - auto edgeMem = std::make_shared(getEngine(), memDesc, memMngr); + memBlock = std::make_shared(); + auto edgeMem = std::make_shared(getEngine(), memDesc, memBlock); parentEdge->reuse(edgeMem); } @@ -251,13 +251,13 @@ void MemoryOutput::assignExtMemory(const MemoryPtr& mem, const MemoryDescPtr& me getName(), " assigned state has null base mem desc ptr"); - if (!memMngr) { return; } //nothing to do, edge memory isn't under control + if (!memBlock) { return; } //nothing to do, edge memory isn't under control auto inpDesc = getBaseMemDescAtInputPort(0); if (inpDesc->isCompatible(*extMemDesc)) { - memMngr->setMemMngrResize(assignedMem->getMemoryMngr()); + memBlock->setMemBlockResize(assignedMem->getMemoryBlock()); } else { - memMngr->reset(); + memBlock->reset(); } } @@ -569,20 +569,20 @@ void MemoryInput::runDynamic(dnnl::stream strm) { getName(), " assigned state has null memory ptr"); - // check whether we can share memory manager + // check whether we can share memory block const auto& stateDims = assignedMem->getStaticDims(); const bool hasZeroDims = std::count(std::begin(stateDims), std::end(stateDims), 0) > 0; auto internDesc = getBaseMemDescAtOutputPort(0)->cloneWithNewDims(stateDims, hasZeroDims); - OPENVINO_ASSERT(memMngr, + OPENVINO_ASSERT(memBlock, "MemoryInput ", getName(), - " has uninitialized memory manager."); + " has uninitialized memory block."); if (internDesc->isCompatible(assignedMem->getDesc())) { - memMngr->setMemMngr(assignedMem->getMemoryMngr()); + memBlock->setMemBlock(assignedMem->getMemoryBlock()); } else { - memMngr->reset(); + memBlock->reset(); } const bool processInitGraph = needInitGraphProcessing(); @@ -619,15 +619,15 @@ void MemoryInput::runStatic(dnnl::stream strm) { auto internDesc = getBaseMemDescAtOutputPort(0); - OPENVINO_ASSERT(memMngr, + OPENVINO_ASSERT(memBlock, "MemoryInput ", getName(), - " has uninitialized memory manager."); + " has uninitialized memory block."); if (internDesc->isCompatible(assignedMem->getDesc())) { - memMngr->setMemMngr(assignedMem->getMemoryMngr()); + memBlock->setMemBlock(assignedMem->getMemoryBlock()); } else { - memMngr->reset(); + memBlock->reset(); } const auto processInitGraph = needInitGraphProcessing(); @@ -653,13 +653,13 @@ void MemoryInput::resolveInPlaceEdges(Edge::LOOK look) { " failed getSelectedPrimitiveDescriptor() call, preferable primitive descriptor is not set"); auto memDesc = selected_pd->getConfig().outConfs.front().getMemDesc(); - memMngr = std::make_shared(); + memBlock = std::make_shared(); for (auto&& edge : getChildEdgesAtPort(0)) { // always only one child port OPENVINO_ASSERT(one_of(edge->getStatus(), Edge::Status::Uninitialized, Edge::Status::NotAllocated), " Unexpected inplace resolve call to an allocated edge: ", edge->name()); - auto edgeMem = std::make_shared(getEngine(), memDesc, memMngr); + auto edgeMem = std::make_shared(getEngine(), memDesc, memBlock); edge->reuse(edgeMem); } } diff --git a/src/plugins/intel_cpu/src/nodes/memory.hpp b/src/plugins/intel_cpu/src/nodes/memory.hpp index f804259b431402..88b6a3d1250f0f 100644 --- a/src/plugins/intel_cpu/src/nodes/memory.hpp +++ b/src/plugins/intel_cpu/src/nodes/memory.hpp @@ -103,7 +103,7 @@ class MemoryOutput : public MemoryOutputBase { private: MemoryPtr assignedMem = nullptr; MemoryDescPtr extMemDesc = nullptr; // used for resize - ProxyMemoryMngrPtr memMngr = nullptr; + ProxyMemoryBlockPtr memBlock = nullptr; }; class MemoryOutputStub : public MemoryOutputBase { @@ -186,7 +186,7 @@ class MemoryInput : public MemoryInputBase { bool needInitGraphProcessing() const; private: - ProxyMemoryMngrPtr memMngr = nullptr; + ProxyMemoryBlockPtr memBlock = nullptr; }; class MemoryInputSDPA : public MemoryInputBase { diff --git a/src/plugins/intel_cpu/src/nodes/split.cpp b/src/plugins/intel_cpu/src/nodes/split.cpp index 5eafc402621008..ad869bd40e03cb 100644 --- a/src/plugins/intel_cpu/src/nodes/split.cpp +++ b/src/plugins/intel_cpu/src/nodes/split.cpp @@ -541,7 +541,7 @@ void Split::resolveInPlaceEdges(Edge::LOOK look) { " Split node: ", getName(), " can not use inPlace memory with splitting on dynamic dimension"); - auto baseMemMngr = getParentEdgeAt(inplaceInpIndx)->getMemory().getMemoryMngr(); + auto baseMemBlock = getParentEdgeAt(inplaceInpIndx)->getMemory().getMemoryBlock(); ptrdiff_t offset = 0; for (size_t i = 0; i < numberOfOutputs; ++i) { auto partDim = outputShapes[i].getDims()[axis]; @@ -560,8 +560,8 @@ void Split::resolveInPlaceEdges(Edge::LOOK look) { auto memDesc = selected_pd->getConfig().outConfs[i].getMemDesc(); MemoryPtr newMem; if (partDim != 0) { - auto memMngr = std::make_shared(baseMemMngr, baseDim, offset, partDim); - newMem = std::make_shared(getEngine(), memDesc, memMngr); + auto memBlock = std::make_shared(baseMemBlock, baseDim, offset, partDim); + newMem = std::make_shared(getEngine(), memDesc, memBlock); } else { // empty tensor, no need to reference a part, default memory is enough newMem = std::make_shared(getEngine(), memDesc); diff --git a/src/plugins/intel_cpu/src/partitioned_mem_mgr.cpp b/src/plugins/intel_cpu/src/partitioned_mem_mgr.cpp index d962546bf367f9..bd4376c8a2812e 100644 --- a/src/plugins/intel_cpu/src/partitioned_mem_mgr.cpp +++ b/src/plugins/intel_cpu/src/partitioned_mem_mgr.cpp @@ -6,28 +6,28 @@ using namespace ov::intel_cpu; -void* PartitionedMemoryMngr::getRawPtr() const noexcept { - return static_cast(m_pMngr->getRawPtr()) + m_offset_blocks * m_size / m_size_blocks; +void* PartitionedMemoryBlock::getRawPtr() const noexcept { + return static_cast(m_pBlock->getRawPtr()) + m_offset_chunks * m_size / m_size_chunks; } -void PartitionedMemoryMngr::setExtBuff(void* ptr, size_t size) { - m_pMngr->setExtBuff(ptr, size); +void PartitionedMemoryBlock::setExtBuff(void* ptr, size_t size) { + m_pBlock->setExtBuff(ptr, size); } -bool PartitionedMemoryMngr::resize(size_t size) { +bool PartitionedMemoryBlock::resize(size_t size) { m_size = size; - return m_pMngr->resize(m_size * m_total_blocks / m_size_blocks); + return m_pBlock->resize(m_size * m_total_chunks / m_size_chunks); } -bool PartitionedMemoryMngr::hasExtBuffer() const noexcept { - return m_pMngr->hasExtBuffer(); +bool PartitionedMemoryBlock::hasExtBuffer() const noexcept { + return m_pBlock->hasExtBuffer(); } -void PartitionedMemoryMngr::registerMemory(Memory* memPtr) { - m_pMngr->registerMemory(memPtr); +void PartitionedMemoryBlock::registerMemory(Memory* memPtr) { + m_pBlock->registerMemory(memPtr); } -void PartitionedMemoryMngr::unregisterMemory(Memory* memPtr) { - m_pMngr->unregisterMemory(memPtr); +void PartitionedMemoryBlock::unregisterMemory(Memory* memPtr) { + m_pBlock->unregisterMemory(memPtr); } diff --git a/src/plugins/intel_cpu/src/partitioned_mem_mgr.h b/src/plugins/intel_cpu/src/partitioned_mem_mgr.h index 2b7b5568bbc93d..58179ce5b04d55 100644 --- a/src/plugins/intel_cpu/src/partitioned_mem_mgr.h +++ b/src/plugins/intel_cpu/src/partitioned_mem_mgr.h @@ -10,15 +10,14 @@ namespace ov { namespace intel_cpu { /** - * This is a memory manager that represents a view on a partition inside a continuous memory block controlled by - * another memory manager. + * This is a memory block that represents a view on a subblock inside another continuous dynamic memory block * */ -class PartitionedMemoryMngr : public IMemoryMngrObserver { +class PartitionedMemoryBlock : public IMemoryBlockObserver { public: - PartitionedMemoryMngr(MemoryMngrPtr pMngr, size_t total_blocks = 1, ptrdiff_t offset_blocks = 0, size_t size_blocks = 1) - : m_pMngr(pMngr), m_total_blocks(total_blocks), m_offset_blocks(offset_blocks), m_size_blocks(size_blocks) { - OPENVINO_ASSERT(m_pMngr, "Memory manager is uninitialized"); + PartitionedMemoryBlock(MemoryBlockPtr pBlock, size_t total_chunks = 1, ptrdiff_t offset_chunks = 0, size_t size_chunks = 1) + : m_pBlock(pBlock), m_total_chunks(total_chunks), m_offset_chunks(offset_chunks), m_size_chunks(size_chunks) { + OPENVINO_ASSERT(m_pBlock, "Memory block is uninitialized"); } void* getRawPtr() const noexcept override; @@ -29,10 +28,10 @@ class PartitionedMemoryMngr : public IMemoryMngrObserver { void unregisterMemory(Memory* memPtr) override; private: - MemoryMngrPtr m_pMngr; - size_t m_total_blocks = 1; // size of the parent memory in abstract blocks - ptrdiff_t m_offset_blocks = 0; // offset from the beginning of the external memory in abstract blocks - size_t m_size_blocks = 1; // size of the viewed partition in abstract blocks + MemoryBlockPtr m_pBlock; + size_t m_total_chunks = 1; // size of the parent memory in abstract chunks + ptrdiff_t m_offset_chunks = 0; // offset from the beginning of the external memory in abstract chunks + size_t m_size_chunks = 1; // size of the viewed partition in abstract chunks size_t m_size = 0; // size of the viewed partition in bytes }; diff --git a/src/plugins/intel_cpu/src/proxy_mem_mgr.cpp b/src/plugins/intel_cpu/src/proxy_mem_mgr.cpp index fee56e70560895..1ab2f639985e67 100644 --- a/src/plugins/intel_cpu/src/proxy_mem_mgr.cpp +++ b/src/plugins/intel_cpu/src/proxy_mem_mgr.cpp @@ -7,75 +7,75 @@ using namespace ov::intel_cpu; -void ProxyMemoryMngr::setMemMngr(std::shared_ptr pMngr) { - OPENVINO_ASSERT(pMngr, "Attempt to set null memory manager to a ProxyMemoryMngr object"); - if (m_pMngr == pMngr) { +void ProxyMemoryBlock::setMemBlock(std::shared_ptr pBlock) { + OPENVINO_ASSERT(pBlock, "Attempt to set null memory block to a ProxyMemoryBlock object"); + if (m_pMemBlock == pBlock) { return; } - m_pMngr = pMngr; + m_pMemBlock = pBlock; notifyUpdate(); } -void ProxyMemoryMngr::setMemMngrResize(std::shared_ptr pMngr) { - OPENVINO_ASSERT(pMngr, "Attempt to set null memory manager to a ProxyMemoryMngr object"); - if (m_pMngr == pMngr) { +void ProxyMemoryBlock::setMemBlockResize(std::shared_ptr pBlock) { + OPENVINO_ASSERT(pBlock, "Attempt to set null memory block to a ProxyMemoryBlock object"); + if (m_pMemBlock == pBlock) { return; } - m_pMngr = pMngr; - m_pMngr->resize(m_size); + m_pMemBlock = pBlock; + m_pMemBlock->resize(m_size); notifyUpdate(); } -void ProxyMemoryMngr::reset() { - if (!m_pOrigMngr) { - m_pOrigMngr = std::make_shared(); +void ProxyMemoryBlock::reset() { + if (!m_pOrigBlock) { + m_pOrigBlock = std::make_shared(); } - if (m_pMngr == m_pOrigMngr) { + if (m_pMemBlock == m_pOrigBlock) { return; } - m_pMngr = m_pOrigMngr; - m_pMngr->resize(m_size); + m_pMemBlock = m_pOrigBlock; + m_pMemBlock->resize(m_size); notifyUpdate(); } -void* ProxyMemoryMngr::getRawPtr() const noexcept { - return m_pMngr->getRawPtr(); +void* ProxyMemoryBlock::getRawPtr() const noexcept { + return m_pMemBlock->getRawPtr(); } -void ProxyMemoryMngr::setExtBuff(void* ptr, size_t size) { - m_pMngr->setExtBuff(ptr, size); +void ProxyMemoryBlock::setExtBuff(void* ptr, size_t size) { + m_pMemBlock->setExtBuff(ptr, size); notifyUpdate(); } -bool ProxyMemoryMngr::resize(size_t size) { - auto res = m_pMngr->resize(size); - DEBUG_LOG(this, ", ", m_pMngr, " size ", m_size, " -> ", size, " resized? ", res, " RawPtr ", getRawPtr()); +bool ProxyMemoryBlock::resize(size_t size) { + auto res = m_pMemBlock->resize(size); + DEBUG_LOG(this, ", ", m_pMemBlock, " size ", m_size, " -> ", size, " resized? ", res, " RawPtr ", getRawPtr()); m_size = size; notifyUpdate(); return res; } -bool ProxyMemoryMngr::hasExtBuffer() const noexcept { - return m_pMngr->hasExtBuffer(); +bool ProxyMemoryBlock::hasExtBuffer() const noexcept { + return m_pMemBlock->hasExtBuffer(); } -void ProxyMemoryMngr::registerMemory(Memory* memPtr) { +void ProxyMemoryBlock::registerMemory(Memory* memPtr) { if (memPtr) { m_setMemPtrs.insert(memPtr); } } -void ProxyMemoryMngr::unregisterMemory(Memory* memPtr) { +void ProxyMemoryBlock::unregisterMemory(Memory* memPtr) { if (memPtr) { m_setMemPtrs.erase(memPtr); } } -void ProxyMemoryMngr::notifyUpdate() { +void ProxyMemoryBlock::notifyUpdate() { for (auto& item : m_setMemPtrs) { if (item) { item->update(); diff --git a/src/plugins/intel_cpu/src/proxy_mem_mgr.h b/src/plugins/intel_cpu/src/proxy_mem_mgr.h index 0788cef280ec96..9ce35887ef250e 100644 --- a/src/plugins/intel_cpu/src/proxy_mem_mgr.h +++ b/src/plugins/intel_cpu/src/proxy_mem_mgr.h @@ -12,12 +12,12 @@ namespace intel_cpu { /** * @brief A proxy object that additionally implements observer pattern */ -class ProxyMemoryMngr : public IMemoryMngrObserver { +class ProxyMemoryBlock : public IMemoryBlockObserver { public: - ProxyMemoryMngr() : m_pOrigMngr(std::make_shared()), m_pMngr(m_pOrigMngr) {} - explicit ProxyMemoryMngr(std::shared_ptr pMngr) { - OPENVINO_ASSERT(pMngr, "Memory manager is uninitialized"); - m_pMngr = pMngr; + ProxyMemoryBlock() : m_pOrigBlock(std::make_shared()), m_pMemBlock(m_pOrigBlock) {} + explicit ProxyMemoryBlock(std::shared_ptr pBlock) { + OPENVINO_ASSERT(pBlock, "Memory block is uninitialized"); + m_pMemBlock = pBlock; } void* getRawPtr() const noexcept override; @@ -28,26 +28,26 @@ class ProxyMemoryMngr : public IMemoryMngrObserver { void registerMemory(Memory* memPtr) override; void unregisterMemory(Memory* memPtr) override; - void setMemMngr(std::shared_ptr pMngr); - void setMemMngrResize(std::shared_ptr pMngr); + void setMemBlock(std::shared_ptr pBlock); + void setMemBlockResize(std::shared_ptr pBlock); void reset(); private: void notifyUpdate(); - // We keep the original MemMngr as may fallback to copy output. - std::shared_ptr m_pOrigMngr = nullptr; - std::shared_ptr m_pMngr = nullptr; + // We keep the original MemBlock as may fallback to copy output. + std::shared_ptr m_pOrigBlock = nullptr; + std::shared_ptr m_pMemBlock = nullptr; std::unordered_set m_setMemPtrs; // WA: resize stage might not work because there is no shape change, - // but the underlying actual memory manager changes. + // but the underlying actual memory block changes. size_t m_size = 0ul; }; -using ProxyMemoryMngrPtr = std::shared_ptr; -using ProxyMemoryMngrCPtr = std::shared_ptr; +using ProxyMemoryBlockPtr = std::shared_ptr; +using ProxyMemoryBlockCPtr = std::shared_ptr; } // namespace intel_cpu } // namespace ov \ No newline at end of file