Teresa Charlin | ca58839 | 2021-10-01 11:29:08 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2021 Arm Ltd and Contributors. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "MemoryManager.hpp" |
| 7 | |
| 8 | #include <armnn/utility/IgnoreUnused.hpp> |
| 9 | |
| 10 | namespace armnn |
| 11 | { |
| 12 | |
| 13 | void MemoryManager::StoreMemToAllocate(std::vector<BufferStorage> bufferStorageVector, |
Finn Williams | b1aad42 | 2021-10-28 19:07:32 +0100 | [diff] [blame] | 14 | std::shared_ptr<ICustomAllocator> customAllocator, |
Teresa Charlin | ca58839 | 2021-10-01 11:29:08 +0100 | [diff] [blame] | 15 | const size_t typeAlignment) |
| 16 | { |
| 17 | IgnoreUnused(typeAlignment); |
| 18 | m_AllocatorBufferStoragePairVector.emplace_back(std::make_pair<Allocator, std::vector<BufferStorage>>( |
| 19 | Allocator{customAllocator}, |
| 20 | std::move(bufferStorageVector))); |
| 21 | } |
| 22 | |
| 23 | void MemoryManager::Allocate() |
| 24 | { |
| 25 | for (auto& m_AllocatorBufferStoragePair : m_AllocatorBufferStoragePairVector) |
| 26 | { |
| 27 | auto& allocator = m_AllocatorBufferStoragePair.first; |
| 28 | for (auto&& bufferStorage : m_AllocatorBufferStoragePair.second) |
| 29 | { |
| 30 | bufferStorage.m_Buffer = allocator.m_CustomAllocator->allocate(bufferStorage.m_BufferSize, 0); |
| 31 | |
| 32 | for (auto tensorMemory : bufferStorage.m_TensorMemoryVector) |
| 33 | { |
| 34 | tensorMemory->m_Data = allocator.m_CustomAllocator->GetMemoryRegionAtOffset(bufferStorage.m_Buffer, |
| 35 | tensorMemory->m_Offset); |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | void MemoryManager::Deallocate() |
| 42 | { |
| 43 | for (auto& m_AllocatorBufferStoragePair : m_AllocatorBufferStoragePairVector) |
| 44 | { |
| 45 | auto& allocator = m_AllocatorBufferStoragePair.first; |
| 46 | for (auto&& bufferStorage : m_AllocatorBufferStoragePair.second) |
| 47 | { |
| 48 | allocator.m_CustomAllocator->free(bufferStorage.m_Buffer); |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | } // namespace armnn |