From 555f1c2241d6fa8c84926a72a0c54e4158817df4 Mon Sep 17 00:00:00 2001 From: Georgios Pinitas Date: Fri, 14 Dec 2018 17:11:20 +0000 Subject: COMPMID-1710: Account alignment for blob-base allocations Change-Id: I290d33e25a5966d25a91df39ebc01c28bfa31f78 Reviewed-on: https://review.mlplatform.org/402 Reviewed-by: Anthony Barbier Tested-by: Arm Jenkins --- src/runtime/Allocator.cpp | 3 +-- src/runtime/BlobLifetimeManager.cpp | 14 ++++++++------ src/runtime/BlobMemoryPool.cpp | 14 +++++++------- src/runtime/ISimpleLifetimeManager.cpp | 18 ++++++++++-------- src/runtime/TensorAllocator.cpp | 2 +- 5 files changed, 27 insertions(+), 24 deletions(-) (limited to 'src/runtime') diff --git a/src/runtime/Allocator.cpp b/src/runtime/Allocator.cpp index 7f0e37495e..d9de11ebbf 100644 --- a/src/runtime/Allocator.cpp +++ b/src/runtime/Allocator.cpp @@ -44,6 +44,5 @@ void Allocator::free(void *ptr) std::unique_ptr Allocator::make_region(size_t size, size_t alignment) { - ARM_COMPUTE_UNUSED(alignment); - return arm_compute::support::cpp14::make_unique(size); + return arm_compute::support::cpp14::make_unique(size, alignment); } \ No newline at end of file diff --git a/src/runtime/BlobLifetimeManager.cpp b/src/runtime/BlobLifetimeManager.cpp index 2a4ab6ec0d..9fef943fb5 100644 --- a/src/runtime/BlobLifetimeManager.cpp +++ b/src/runtime/BlobLifetimeManager.cpp @@ -62,19 +62,21 @@ void BlobLifetimeManager::update_blobs_and_mappings() { return ba.max_size > bb.max_size; }); - std::vector group_sizes; + + // Create group sizes vector + std::vector group_sizes; std::transform(std::begin(_free_blobs), std::end(_free_blobs), std::back_inserter(group_sizes), [](const Blob & b) { - return b.max_size; + return BlobInfo(b.max_size, b.max_alignment); }); // Update blob sizes size_t max_size = std::max(_blobs.size(), group_sizes.size()); - _blobs.resize(max_size, 0); - group_sizes.resize(max_size, 0); - std::transform(std::begin(_blobs), std::end(_blobs), std::begin(group_sizes), std::begin(_blobs), [](size_t lhs, size_t rhs) + _blobs.resize(max_size); + group_sizes.resize(max_size); + std::transform(std::begin(_blobs), std::end(_blobs), std::begin(group_sizes), std::begin(_blobs), [](BlobInfo lhs, BlobInfo rhs) { - return std::max(lhs, rhs); + return BlobInfo(std::max(lhs.size, rhs.size), std::max(lhs.alignment, rhs.alignment)); }); // Calculate group mappings diff --git a/src/runtime/BlobMemoryPool.cpp b/src/runtime/BlobMemoryPool.cpp index e09451cd62..812cbdd673 100644 --- a/src/runtime/BlobMemoryPool.cpp +++ b/src/runtime/BlobMemoryPool.cpp @@ -33,11 +33,11 @@ using namespace arm_compute; -BlobMemoryPool::BlobMemoryPool(IAllocator *allocator, std::vector blob_sizes) - : _allocator(allocator), _blobs(), _blob_sizes(std::move(blob_sizes)) +BlobMemoryPool::BlobMemoryPool(IAllocator *allocator, std::vector blob_info) + : _allocator(allocator), _blobs(), _blob_info(std::move(blob_info)) { ARM_COMPUTE_ERROR_ON(!allocator); - allocate_blobs(_blob_sizes); + allocate_blobs(_blob_info); } BlobMemoryPool::~BlobMemoryPool() @@ -73,16 +73,16 @@ MappingType BlobMemoryPool::mapping_type() const std::unique_ptr BlobMemoryPool::duplicate() { ARM_COMPUTE_ERROR_ON(!_allocator); - return support::cpp14::make_unique(_allocator, _blob_sizes); + return support::cpp14::make_unique(_allocator, _blob_info); } -void BlobMemoryPool::allocate_blobs(const std::vector &sizes) +void BlobMemoryPool::allocate_blobs(const std::vector &blob_info) { ARM_COMPUTE_ERROR_ON(!_allocator); - for(const auto &size : sizes) + for(const auto &bi : blob_info) { - _blobs.push_back(_allocator->make_region(size, 0)); + _blobs.push_back(_allocator->make_region(bi.size, bi.alignment)); } } diff --git a/src/runtime/ISimpleLifetimeManager.cpp b/src/runtime/ISimpleLifetimeManager.cpp index 7d928d6a7a..97c20d1882 100644 --- a/src/runtime/ISimpleLifetimeManager.cpp +++ b/src/runtime/ISimpleLifetimeManager.cpp @@ -59,7 +59,7 @@ void ISimpleLifetimeManager::start_lifetime(void *obj) // Check if there is a free blob if(_free_blobs.empty()) { - _occupied_blobs.emplace_front(Blob{ obj, 0, { obj } }); + _occupied_blobs.emplace_front(Blob{ obj, 0, 0, { obj } }); } else { @@ -71,7 +71,7 @@ void ISimpleLifetimeManager::start_lifetime(void *obj) _active_elements.insert(std::make_pair(obj, obj)); } -void ISimpleLifetimeManager::end_lifetime(void *obj, IMemory &obj_memory, size_t size) +void ISimpleLifetimeManager::end_lifetime(void *obj, IMemory &obj_memory, size_t size, size_t alignment) { ARM_COMPUTE_ERROR_ON(obj == nullptr); @@ -80,10 +80,11 @@ void ISimpleLifetimeManager::end_lifetime(void *obj, IMemory &obj_memory, size_t ARM_COMPUTE_ERROR_ON(active_object_it == std::end(_active_elements)); // Update object fields and mark object as complete - Element &el = active_object_it->second; - el.handle = &obj_memory; - el.size = size; - el.status = true; + Element &el = active_object_it->second; + el.handle = &obj_memory; + el.size = size; + el.alignment = alignment; + el.status = true; // Find object in the occupied lists auto occupied_blob_it = std::find_if(std::begin(_occupied_blobs), std::end(_occupied_blobs), [&obj](const Blob & b) @@ -94,8 +95,9 @@ void ISimpleLifetimeManager::end_lifetime(void *obj, IMemory &obj_memory, size_t // Update occupied blob and return as free occupied_blob_it->bound_elements.insert(obj); - occupied_blob_it->max_size = std::max(occupied_blob_it->max_size, size); - occupied_blob_it->id = nullptr; + occupied_blob_it->max_size = std::max(occupied_blob_it->max_size, size); + occupied_blob_it->max_alignment = std::max(occupied_blob_it->max_alignment, alignment); + occupied_blob_it->id = nullptr; _free_blobs.splice(std::begin(_free_blobs), _occupied_blobs, occupied_blob_it); // Check if all object are finalized and reset active group diff --git a/src/runtime/TensorAllocator.cpp b/src/runtime/TensorAllocator.cpp index 5fa51d7140..38edb8ba03 100644 --- a/src/runtime/TensorAllocator.cpp +++ b/src/runtime/TensorAllocator.cpp @@ -138,7 +138,7 @@ void TensorAllocator::allocate() } else { - _associated_memory_group->finalize_memory(_owner, _memory, info().total_size()); + _associated_memory_group->finalize_memory(_owner, _memory, info().total_size(), alignment()); } info().set_is_resizable(false); } -- cgit v1.2.1