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
diff --git a/src/backends/backendsCommon/MemoryManager.cpp b/src/backends/backendsCommon/MemoryManager.cpp
new file mode 100644
index 0000000..1c109c3
--- /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