diff options
Diffstat (limited to 'src/backends/backendsCommon/MemoryManager.cpp')
-rw-r--r-- | src/backends/backendsCommon/MemoryManager.cpp | 53 |
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 |