aboutsummaryrefslogtreecommitdiff
path: root/src/backends/backendsCommon/MemoryManager.cpp
diff options
context:
space:
mode:
authorTeresa Charlin <teresa.charlinreyes@arm.com>2021-10-01 11:29:08 +0100
committerTeresaARM <teresa.charlinreyes@arm.com>2021-10-26 16:15:13 +0000
commitca5883951ab51191eb19502459f0936fc96e14f1 (patch)
tree03973265a28e489719cc51a826c1531006823c83 /src/backends/backendsCommon/MemoryManager.cpp
parentfea41d70385fec1d9e1c3367cfad2736ed7d20b2 (diff)
downloadarmnn-ca5883951ab51191eb19502459f0936fc96e14f1.tar.gz
IVGCVSW-6301 Create the MemoryManager class
Signed-off-by: Teresa Charlin <teresa.charlinreyes@arm.com> Signed-off-by: Finn Williams <finn.williams@arm.com> Change-Id: Ia41b5252d695daabd5afaf1b2267444d24be173a
Diffstat (limited to 'src/backends/backendsCommon/MemoryManager.cpp')
-rw-r--r--src/backends/backendsCommon/MemoryManager.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/backends/backendsCommon/MemoryManager.cpp b/src/backends/backendsCommon/MemoryManager.cpp
new file mode 100644
index 0000000000..1c109c3c91
--- /dev/null
+++ b/src/backends/backendsCommon/MemoryManager.cpp
@@ -0,0 +1,53 @@
+//
+// Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include "MemoryManager.hpp"
+
+#include <armnn/utility/IgnoreUnused.hpp>
+
+namespace armnn
+{
+
+void MemoryManager::StoreMemToAllocate(std::vector<BufferStorage> bufferStorageVector,
+ ICustomAllocator* customAllocator,
+ const size_t typeAlignment)
+{
+ IgnoreUnused(typeAlignment);
+ m_AllocatorBufferStoragePairVector.emplace_back(std::make_pair<Allocator, std::vector<BufferStorage>>(
+ Allocator{customAllocator},
+ std::move(bufferStorageVector)));
+}
+
+void MemoryManager::Allocate()
+{
+ for (auto& m_AllocatorBufferStoragePair : m_AllocatorBufferStoragePairVector)
+ {
+ auto& allocator = m_AllocatorBufferStoragePair.first;
+ for (auto&& bufferStorage : m_AllocatorBufferStoragePair.second)
+ {
+ bufferStorage.m_Buffer = allocator.m_CustomAllocator->allocate(bufferStorage.m_BufferSize, 0);
+
+ for (auto tensorMemory : bufferStorage.m_TensorMemoryVector)
+ {
+ tensorMemory->m_Data = allocator.m_CustomAllocator->GetMemoryRegionAtOffset(bufferStorage.m_Buffer,
+ tensorMemory->m_Offset);
+ }
+ }
+ }
+}
+
+void MemoryManager::Deallocate()
+{
+ for (auto& m_AllocatorBufferStoragePair : m_AllocatorBufferStoragePairVector)
+ {
+ auto& allocator = m_AllocatorBufferStoragePair.first;
+ for (auto&& bufferStorage : m_AllocatorBufferStoragePair.second)
+ {
+ allocator.m_CustomAllocator->free(bufferStorage.m_Buffer);
+ }
+ }
+}
+
+} // namespace armnn \ No newline at end of file