aboutsummaryrefslogtreecommitdiff
path: root/src/backends/backendsCommon/MemoryManager.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/backends/backendsCommon/MemoryManager.hpp')
-rw-r--r--src/backends/backendsCommon/MemoryManager.hpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/backends/backendsCommon/MemoryManager.hpp b/src/backends/backendsCommon/MemoryManager.hpp
new file mode 100644
index 0000000000..cbd6fcf9bc
--- /dev/null
+++ b/src/backends/backendsCommon/MemoryManager.hpp
@@ -0,0 +1,60 @@
+//
+// Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include <armnn/backends/ICustomAllocator.hpp>
+
+namespace armnn
+{
+struct Allocator
+{
+ /// Pointer to @ICustomAllocator.
+ ICustomAllocator* m_CustomAllocator{};
+ /// Value which the size of each buffer (actual data size + padding) has to be a multiple of.
+ size_t m_Alignment = 0 ;
+};
+
+struct TensorMemory
+{
+ /// Number of bytes the value is away from the @BufferStorage.m_Buffer.
+ size_t m_Offset{};
+ /// Pointer to the tensor value.
+ void* m_Data = nullptr;
+ /// Identifier to be used by the @LoadedNetwork to order the tensors.
+ unsigned int m_OutputSlotId{};
+};
+
+struct BufferStorage
+{
+ /// Vector of pointer to @TensorMemory.
+ std::vector<TensorMemory*> m_TensorMemoryVector;
+ /// Total size of the buffer.
+ size_t m_BufferSize;
+ /// Pointer to the first element of the buffer.
+ void* m_Buffer = nullptr;
+};
+
+class MemoryManager
+{
+public:
+ /// Initialization method to store in @m_AllocatorBufferStoragePairVector all information needed.
+ /// @param[in] bufferStorageVector - Vector of @BufferStorage.
+ /// @param[in] customAllocator - Pointer to @ICustomAllocator.
+ /// @param[in] typeAlignment - Optional parameter. Value of which the size of each value has to be multiple of.
+ void StoreMemToAllocate(std::vector<BufferStorage> bufferStorageVector,
+ ICustomAllocator* customAllocator,
+ size_t typeAlignment = 0);
+
+ /// Allocate the amount of memory indicated by @m_BufferSize, and
+ /// point each @m_Data to each correspondent Tensor so that they are @m_Offset bytes separated.
+ void Allocate();
+
+ /// Deallocate memory
+ void Deallocate();
+
+private:
+ std::vector<std::pair<Allocator, std::vector<BufferStorage>>> m_AllocatorBufferStoragePairVector;
+};
+
+} // namespace armnn