aboutsummaryrefslogtreecommitdiff
path: root/src/backends/backendsCommon/MemoryManager.cpp
blob: 77cab27789790d7668e0fc03071536406bad47b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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,
                                       std::shared_ptr<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