aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/CL/CLTensorAllocator.cpp
diff options
context:
space:
mode:
authorMichele Di Giorgio <michele.digiorgio@arm.com>2018-05-14 11:58:24 +0100
committerAnthony Barbier <anthony.barbier@arm.com>2018-11-02 16:52:54 +0000
commitaaab60220085e2df5f13d7fe020a45a335df38be (patch)
tree2c5f6c038c355a616d30c725fdf59bc06a3f1de2 /src/runtime/CL/CLTensorAllocator.cpp
parentdcb5b284300c34d5984091cfe99559cc420e59bb (diff)
downloadComputeLibrary-aaab60220085e2df5f13d7fe020a45a335df38be.tar.gz
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 <anthony.barbier@arm.com> Tested-by: Jenkins <bsgcomp@arm.com>
Diffstat (limited to 'src/runtime/CL/CLTensorAllocator.cpp')
-rw-r--r--src/runtime/CL/CLTensorAllocator.cpp12
1 files changed, 10 insertions, 2 deletions
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
{