ArmNN
 24.02
MemoryManager.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 #pragma once
6 
8 
9 namespace armnn
10 {
11 struct Allocator
12 {
13  /// Pointer to @ICustomAllocator.
14  std::shared_ptr<ICustomAllocator> m_CustomAllocator{};
15  /// Value which the size of each buffer (actual data size + padding) has to be a multiple of.
16  size_t m_Alignment = 0 ;
17 };
18 
20 {
21  /// Number of bytes the value is away from the @BufferStorage.m_Buffer.
22  size_t m_Offset{};
23  /// Identifier to be used by the @LoadedNetwork to order the tensors.
24  unsigned int m_OutputSlotId{};
25  /// Pointer to the tensor value.
26  void* m_Data = nullptr;
27 };
28 
30 {
31  /// Vector of pointer to @TensorMemory.
32  std::vector<std::shared_ptr<TensorMemory>> m_TensorMemoryVector;
33  /// Total size of the buffer.
34  size_t m_BufferSize;
35  /// Pointer to the first element of the buffer.
36  void* m_Buffer = nullptr;
37 };
38 
40 {
41 public:
42  /// Initialization method to store in m_AllocatorBufferStoragePairVector all information needed.
43  /// @param[in] bufferStorageVector - Vector of BufferStorage.
44  /// @param[in] customAllocator - Pointer to ICustomAllocator.
45  /// @param[in] typeAlignment - Optional parameter. Value of which the size of each value has to be multiple of.
46  void StoreMemToAllocate(std::vector<BufferStorage> bufferStorageVector,
47  std::shared_ptr<ICustomAllocator> customAllocator,
48  size_t typeAlignment = 0);
49 
50  /// Allocate the amount of memory indicated by m_BufferSize, and
51  /// point each m_Data to each correspondent Tensor so that they are m_Offset bytes separated.
52  void Allocate();
53 
54  /// Deallocate memory
55  void Deallocate();
56 
57 private:
58  std::vector<std::pair<Allocator, std::vector<BufferStorage>>> m_AllocatorBufferStoragePairVector;
59 };
60 
61 } // namespace armnn
armnn::TensorMemory::m_Data
void * m_Data
Pointer to the tensor value.
Definition: MemoryManager.hpp:26
armnn::Allocator
Definition: MemoryManager.hpp:11
armnn::BufferStorage::m_TensorMemoryVector
std::vector< std::shared_ptr< TensorMemory > > m_TensorMemoryVector
Vector of pointer to @TensorMemory.
Definition: MemoryManager.hpp:32
armnn::Allocator::m_Alignment
size_t m_Alignment
Value which the size of each buffer (actual data size + padding) has to be a multiple of.
Definition: MemoryManager.hpp:16
armnn::MemoryManager::Allocate
void Allocate()
Allocate the amount of memory indicated by m_BufferSize, and point each m_Data to each correspondent ...
Definition: MemoryManager.cpp:23
ICustomAllocator.hpp
armnn::TensorMemory::m_Offset
size_t m_Offset
Number of bytes the value is away from the @BufferStorage.m_Buffer.
Definition: MemoryManager.hpp:22
armnn::TensorMemory
Definition: MemoryManager.hpp:19
armnn::BufferStorage::m_Buffer
void * m_Buffer
Pointer to the first element of the buffer.
Definition: MemoryManager.hpp:36
armnn::BufferStorage
Definition: MemoryManager.hpp:29
armnn::MemoryManager::StoreMemToAllocate
void StoreMemToAllocate(std::vector< BufferStorage > bufferStorageVector, std::shared_ptr< ICustomAllocator > customAllocator, size_t typeAlignment=0)
Initialization method to store in m_AllocatorBufferStoragePairVector all information needed.
Definition: MemoryManager.cpp:13
armnn::BufferStorage::m_BufferSize
size_t m_BufferSize
Total size of the buffer.
Definition: MemoryManager.hpp:34
armnn::TensorMemory::m_OutputSlotId
unsigned int m_OutputSlotId
Identifier to be used by the @LoadedNetwork to order the tensors.
Definition: MemoryManager.hpp:24
armnn::MemoryManager
Definition: MemoryManager.hpp:39
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
armnn::Allocator::m_CustomAllocator
std::shared_ptr< ICustomAllocator > m_CustomAllocator
Pointer to @ICustomAllocator.
Definition: MemoryManager.hpp:14
armnn::MemoryManager::Deallocate
void Deallocate()
Deallocate memory.
Definition: MemoryManager.cpp:41