From aaab60220085e2df5f13d7fe020a45a335df38be Mon Sep 17 00:00:00 2001 From: Michele Di Giorgio Date: Mon, 14 May 2018 11:58:24 +0100 Subject: COMPMID-1156: Allow memory reusage when trying to reallocate a smaller CLTensor In case of reconfiguration there might be the need for reallocating internal data. This patch allows resusage of already allocated memory for CLTensors only if the newly requested memory is smaller than the previous one, otherwise an error is thrown. Change-Id: Ibb545d0c521f87636f8a00154b879958570ee184 Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/131022 Reviewed-by: Anthony Barbier Tested-by: Jenkins --- src/runtime/CL/CLTensorAllocator.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/runtime/CL/CLTensorAllocator.cpp') diff --git a/src/runtime/CL/CLTensorAllocator.cpp b/src/runtime/CL/CLTensorAllocator.cpp index 54e7c5b336..dd716f77ff 100644 --- a/src/runtime/CL/CLTensorAllocator.cpp +++ b/src/runtime/CL/CLTensorAllocator.cpp @@ -74,8 +74,16 @@ void CLTensorAllocator::allocate() if(_associated_memory_group == nullptr) { - ARM_COMPUTE_ERROR_ON(_memory.region()->cl_data().get() != nullptr); - _memory = CLMemory(allocate_region(CLScheduler::get().context(), info().total_size(), 0)); + if(_memory.region()->cl_data().get() != nullptr) + { + // Memory is already allocated. Reuse it if big enough, otherwise fire an assertion + ARM_COMPUTE_ERROR_ON_MSG(info().total_size() > _memory.region()->size(), "Reallocation of a bigger memory region is not allowed!"); + } + else + { + // Perform memory allocation + _memory = CLMemory(allocate_region(CLScheduler::get().context(), info().total_size(), 0)); + } } else { -- cgit v1.2.1