blob: d0174f893c1fb987a40fd6b792837e016455bed5 [file] [log] [blame]
telsoa01c577f2c2018-08-31 09:22:23 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa01c577f2c2018-08-31 09:22:23 +01004//
5#include "OffsetLifetimeManager.hpp"
6#include "OffsetMemoryPool.hpp"
7
Aron Virginas-Tarf9aeef02018-10-12 15:18:03 +01008#include <arm_compute/runtime/IMemoryGroup.h>
telsoa01c577f2c2018-08-31 09:22:23 +01009
10#include <numeric>
11
Aron Virginas-Tarf9aeef02018-10-12 15:18:03 +010012#include <boost/assert.hpp>
telsoa01c577f2c2018-08-31 09:22:23 +010013
14namespace armnn
15{
16
17OffsetLifetimeManager::OffsetLifetimeManager()
18 : m_BlobSize(0)
19{
20}
21
22std::unique_ptr<arm_compute::IMemoryPool> OffsetLifetimeManager::create_pool(arm_compute::IAllocator* allocator)
23{
24 BOOST_ASSERT(allocator);
25 return std::make_unique<OffsetMemoryPool>(allocator, m_BlobSize);
26}
27
28arm_compute::MappingType OffsetLifetimeManager::mapping_type() const
29{
30 return arm_compute::MappingType::OFFSETS;
31}
32
33void OffsetLifetimeManager::update_blobs_and_mappings()
34{
35 BOOST_ASSERT(are_all_finalized());
36 BOOST_ASSERT(_active_group);
37
38 // Update blob size
39 size_t maxGroupSize = std::accumulate(std::begin(_free_blobs), std::end(_free_blobs),
40 static_cast<size_t>(0), [](size_t s, const Blob& b)
41 {
42 return s + b.max_size;
43 });
44 m_BlobSize = std::max(m_BlobSize, maxGroupSize);
45
46 // Calculate group mappings
47 auto& groupMappings = _active_group->mappings();
48 size_t offset = 0;
49 for(auto& freeBlob : _free_blobs)
50 {
51 for(auto& boundElementId : freeBlob.bound_elements)
52 {
53 BOOST_ASSERT(_active_elements.find(boundElementId) != std::end(_active_elements));
54 Element& boundElement = _active_elements[boundElementId];
55 groupMappings[boundElement.handle] = offset;
56 }
57 offset += freeBlob.max_size;
58 BOOST_ASSERT(offset <= m_BlobSize);
59 }
60}
61
62} // namespace armnn