From 734151d20bef56cbedce2ae67945f42cb4e265c8 Mon Sep 17 00:00:00 2001 From: Georgios Pinitas Date: Mon, 21 Jan 2019 18:38:21 +0000 Subject: COMPMID-1848: Account alignment in Offset-based pool allocations Change-Id: I061d612341bf951a7d0e7ddd04a42139c8400d41 Reviewed-on: https://review.mlplatform.org/554 Tested-by: Arm Jenkins Reviewed-by: Michalis Spyrou --- src/runtime/OffsetLifetimeManager.cpp | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'src/runtime/OffsetLifetimeManager.cpp') diff --git a/src/runtime/OffsetLifetimeManager.cpp b/src/runtime/OffsetLifetimeManager.cpp index d0b3bde724..ad23220c0e 100644 --- a/src/runtime/OffsetLifetimeManager.cpp +++ b/src/runtime/OffsetLifetimeManager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2018 ARM Limited. + * Copyright (c) 2017-2019 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -34,8 +34,16 @@ #include #include -using namespace arm_compute; - +namespace arm_compute +{ +namespace +{ +size_t align_offset(size_t offset, size_t alignment) +{ + const size_t remainder = (alignment != 0U) ? offset % alignment : 0U; + return (remainder != 0U) ? offset + (alignment - remainder) : offset; +} +} // namespace OffsetLifetimeManager::OffsetLifetimeManager() : _blob(0) { @@ -58,11 +66,15 @@ void OffsetLifetimeManager::update_blobs_and_mappings() ARM_COMPUTE_ERROR_ON(_active_group == nullptr); // Update blob size - size_t max_group_size = std::accumulate(std::begin(_free_blobs), std::end(_free_blobs), static_cast(0), [](size_t s, const Blob & b) + size_t max_aggregated_size = 0; + std::for_each(std::begin(_free_blobs), std::end(_free_blobs), [&](const Blob & b) { - return s + b.max_size; + max_aggregated_size += b.max_size; + _blob.alignment = std::max(_blob.alignment, b.max_alignment); }); - _blob = std::max(_blob, max_group_size); + max_aggregated_size += _free_blobs.size() * _blob.alignment; + _blob.owners = std::max(_blob.owners, _free_blobs.size()); + _blob.size = std::max(_blob.size, max_aggregated_size); // Calculate group mappings auto &group_mappings = _active_group->mappings(); @@ -76,6 +88,8 @@ void OffsetLifetimeManager::update_blobs_and_mappings() group_mappings[bound_element.handle] = offset; } offset += free_blob.max_size; - ARM_COMPUTE_ERROR_ON(offset > _blob); + offset = align_offset(offset, _blob.alignment); + ARM_COMPUTE_ERROR_ON(offset > _blob.size); } } +} // namespace arm_compute -- cgit v1.2.1