diff options
author | Aron Virginas-Tar <Aron.Virginas-Tar@arm.com> | 2018-10-12 15:18:03 +0100 |
---|---|---|
committer | Matthew Bentham <matthew.bentham@arm.com> | 2018-10-22 16:57:53 +0100 |
commit | f9aeef0e036df176699aa96d30d2ca8d7546534e (patch) | |
tree | 09ad918f7d2cffbca2c013c688332fa687b8d8ca /src/backends/aclCommon/memory/BlobLifetimeManager.cpp | |
parent | 3b278e9261bd0de67c82f7d6c36731f118124f52 (diff) | |
download | armnn-f9aeef0e036df176699aa96d30d2ca8d7546534e.tar.gz |
IVGCVSW-2006: Move ACL memory manager source code under aclCommon
Change-Id: Ie1c74a18de5c3dd1cd5285c222bd6327489c1508
Diffstat (limited to 'src/backends/aclCommon/memory/BlobLifetimeManager.cpp')
-rw-r--r-- | src/backends/aclCommon/memory/BlobLifetimeManager.cpp | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/src/backends/aclCommon/memory/BlobLifetimeManager.cpp b/src/backends/aclCommon/memory/BlobLifetimeManager.cpp new file mode 100644 index 0000000000..41100e945f --- /dev/null +++ b/src/backends/aclCommon/memory/BlobLifetimeManager.cpp @@ -0,0 +1,79 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// +#include "BlobLifetimeManager.hpp" +#include "BlobMemoryPool.hpp" + +#include <arm_compute/runtime/IMemoryGroup.h> + +#include "boost/assert.hpp" + +#include <algorithm> + +namespace armnn +{ + +BlobLifetimeManager::BlobLifetimeManager() + : m_BlobSizes() +{ +} + +arm_compute::MappingType BlobLifetimeManager::mapping_type() const +{ + return arm_compute::MappingType::BLOBS; +} + +void BlobLifetimeManager::update_blobs_and_mappings() +{ + using namespace arm_compute; + + BOOST_ASSERT(are_all_finalized()); + BOOST_ASSERT(_active_group); + + // Sort free blobs requirements in descending order. + _free_blobs.sort([](const Blob & ba, const Blob & bb) + { + return ba.max_size > bb.max_size; + }); + std::vector<size_t> groupSizes; + std::transform(std::begin(_free_blobs), std::end(_free_blobs), std::back_inserter(groupSizes), [](const Blob & b) + { + return b.max_size; + }); + + // Update blob sizes + size_t max_size = std::max(m_BlobSizes.size(), groupSizes.size()); + m_BlobSizes.resize(max_size, 0); + groupSizes.resize(max_size, 0); + std::transform(std::begin(m_BlobSizes), std::end(m_BlobSizes), std::begin(groupSizes), + std::begin(m_BlobSizes), [](size_t lhs, size_t rhs) + { + return std::max(lhs, rhs); + }); + + // Calculate group mappings + auto& groupMappings = _active_group->mappings(); + unsigned int blobIdx = 0; + + for(auto& freeBlob : _free_blobs) + { + for(auto& boundElementId : freeBlob.bound_elements) + { + BOOST_ASSERT(_active_elements.find(boundElementId) != std::end(_active_elements)); + + Element& boundElement = _active_elements[boundElementId]; + groupMappings[boundElement.handle] = blobIdx; + } + + ++blobIdx; + } +} + +std::unique_ptr<arm_compute::IMemoryPool> BlobLifetimeManager::create_pool(arm_compute::IAllocator* allocator) +{ + BOOST_ASSERT(allocator); + return std::make_unique<BlobMemoryPool>(allocator, m_BlobSizes); +} + +} // namespace armnn
\ No newline at end of file |