diff options
author | Finn Williams <Finn.Williams@arm.com> | 2021-04-26 12:06:34 +0100 |
---|---|---|
committer | finn.williams <finn.williams@arm.com> | 2021-04-28 11:39:10 +0000 |
commit | 01097941ef85073c56cbd1d5f00d7e8ffeb9876d (patch) | |
tree | 818686d467b142084e0e49bbd4084670d1d0d50b /src/armnn/WorkingMemHandle.cpp | |
parent | c2b99a8783388ec3bd90dfed2e1b6d4f4d4bd1c8 (diff) | |
download | armnn-01097941ef85073c56cbd1d5f00d7e8ffeb9876d.tar.gz |
IVGCVSW-5843 Separate memory managers for WorkingMemHandles
* Add inter layer memory management to WorkingMemHandle
* Change Const layers to be executed once in loadedNetworkConstruction
and share tensorHandle between all WorkingMemHandles
* Fix various reference workloads pointing to memory in the queueDescriptor
Signed-off-by: Finn Williams <Finn.Williams@arm.com>
Change-Id: I69d4b3c5c84d2f5abe4540c3e624ab4f00d88226
Diffstat (limited to 'src/armnn/WorkingMemHandle.cpp')
-rw-r--r-- | src/armnn/WorkingMemHandle.cpp | 56 |
1 files changed, 34 insertions, 22 deletions
diff --git a/src/armnn/WorkingMemHandle.cpp b/src/armnn/WorkingMemHandle.cpp index c1a48d482f..0cbef82e83 100644 --- a/src/armnn/WorkingMemHandle.cpp +++ b/src/armnn/WorkingMemHandle.cpp @@ -6,6 +6,7 @@ #include "backendsCommon/CpuTensorHandle.hpp" #include "WorkingMemHandle.hpp" #include "Network.hpp" +#include <armnn/backends/IMemoryManager.hpp> namespace armnn { @@ -13,36 +14,47 @@ namespace armnn namespace experimental { -WorkingMemHandle::WorkingMemHandle(NetworkId networkId, - std::vector<WorkingMemDescriptor> workingMemDescriptors, - std::unordered_map<LayerGuid, WorkingMemDescriptor> workingMemDescriptorMap) : +WorkingMemHandle::WorkingMemHandle( + NetworkId networkId, + std::vector<WorkingMemDescriptor> workingMemDescriptors, + std::unordered_map<LayerGuid, WorkingMemDescriptor> workingMemDescriptorMap, + std::vector<std::shared_ptr<IMemoryManager>> memoryManagers, + std::unordered_map<LayerGuid, std::vector<std::unique_ptr<ITensorHandle> > > ownedTensorHandles) : m_NetworkId(networkId), m_WorkingMemDescriptors(workingMemDescriptors), m_WorkingMemDescriptorMap(workingMemDescriptorMap), + m_MemoryManagers(memoryManagers), + m_OwnedTensorHandles(std::move(ownedTensorHandles)), m_IsAllocated(false), m_Mutex() -{} +{ +} -void WorkingMemHandle::FreeWorkingMemory() +void WorkingMemHandle::Allocate() { - for (auto workingMemDescriptor : m_WorkingMemDescriptors) + if (m_IsAllocated) + { + return; + } + m_IsAllocated = true; + + for (auto& mgr : m_MemoryManagers) + { + mgr->Acquire(); + } +} + +void WorkingMemHandle::Free() +{ + if (!m_IsAllocated) + { + return; + } + m_IsAllocated = false; + + for (auto& mgr : m_MemoryManagers) { - for (auto input : workingMemDescriptor.m_Inputs) - { - if (input) - { - delete input; - input = nullptr; - } - } - for (auto output : workingMemDescriptor.m_Outputs) - { - if (output) - { - delete output; - output = nullptr; - } - } + mgr->Release(); } } |