telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
David Beck | ecb56cd | 2018-09-05 12:52:57 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 4 | // |
| 5 | #include "OffsetLifetimeManager.hpp" |
| 6 | #include "OffsetMemoryPool.hpp" |
| 7 | |
Aron Virginas-Tar | f9aeef0 | 2018-10-12 15:18:03 +0100 | [diff] [blame] | 8 | #include <arm_compute/runtime/IMemoryGroup.h> |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 9 | |
| 10 | #include <numeric> |
| 11 | |
Aron Virginas-Tar | f9aeef0 | 2018-10-12 15:18:03 +0100 | [diff] [blame] | 12 | #include <boost/assert.hpp> |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 13 | |
| 14 | namespace armnn |
| 15 | { |
| 16 | |
| 17 | OffsetLifetimeManager::OffsetLifetimeManager() |
| 18 | : m_BlobSize(0) |
| 19 | { |
| 20 | } |
| 21 | |
| 22 | std::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 | |
| 28 | arm_compute::MappingType OffsetLifetimeManager::mapping_type() const |
| 29 | { |
| 30 | return arm_compute::MappingType::OFFSETS; |
| 31 | } |
| 32 | |
| 33 | void 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 |