diff options
author | Georgios Pinitas <georgios.pinitas@arm.com> | 2017-09-08 19:47:30 +0100 |
---|---|---|
committer | Anthony Barbier <anthony.barbier@arm.com> | 2018-11-02 16:35:24 +0000 |
commit | baf174e85ddb5399355281cd34d0f459d92124a7 (patch) | |
tree | d69904df66f7e5ad55edd268d16735542445f36f /src/runtime/TensorAllocator.cpp | |
parent | 1c8409d7ce90ea449437076574c98a4ea90d9368 (diff) | |
download | ComputeLibrary-baf174e85ddb5399355281cd34d0f459d92124a7.tar.gz |
COMPMID-485: Memory Manager
Change-Id: Ib421b7622838f050038cd81e7426bb1413a7d6e6
Reviewed-on: http://mpd-gerrit.cambridge.arm.com/87376
Tested-by: Kaizen <jeremy.johnson+kaizengerrit@arm.com>
Reviewed-by: Anthony Barbier <anthony.barbier@arm.com>
Diffstat (limited to 'src/runtime/TensorAllocator.cpp')
-rw-r--r-- | src/runtime/TensorAllocator.cpp | 74 |
1 files changed, 65 insertions, 9 deletions
diff --git a/src/runtime/TensorAllocator.cpp b/src/runtime/TensorAllocator.cpp index 5c719c761a..272b9f5695 100644 --- a/src/runtime/TensorAllocator.cpp +++ b/src/runtime/TensorAllocator.cpp @@ -26,6 +26,7 @@ #include "arm_compute/core/Coordinates.h" #include "arm_compute/core/Error.h" #include "arm_compute/core/TensorInfo.h" +#include "arm_compute/runtime/MemoryGroup.h" #include <cstddef> @@ -63,11 +64,50 @@ bool validate_subtensor_shape(const TensorInfo &parent_info, const TensorInfo &c } } // namespace -TensorAllocator::TensorAllocator() - : _buffer(nullptr) +TensorAllocator::TensorAllocator(Tensor *owner) + : _associated_memory_group(nullptr), _buffer(nullptr), _owner(owner) { } +TensorAllocator::~TensorAllocator() +{ + if((_associated_memory_group == nullptr) && (_buffer != nullptr)) + { + delete[] _buffer; + _buffer = nullptr; + info().set_is_resizable(true); + } +} + +TensorAllocator::TensorAllocator(TensorAllocator &&o) noexcept + : ITensorAllocator(std::move(o)), + _associated_memory_group(o._associated_memory_group), + _buffer(o._buffer), + _owner(o._owner) +{ + o._associated_memory_group = nullptr; + o._buffer = nullptr; + o._owner = nullptr; +} + +TensorAllocator &TensorAllocator::operator=(TensorAllocator &&o) noexcept +{ + if(&o != this) + { + _associated_memory_group = o._associated_memory_group; + o._associated_memory_group = nullptr; + + _buffer = o._buffer; + o._buffer = nullptr; + + _owner = o._owner; + o._owner = nullptr; + + ITensorAllocator::operator=(std::move(o)); + } + return *this; +} + void TensorAllocator::init(const TensorAllocator &allocator, const Coordinates &coords, TensorInfo sub_info) { // Get parent info @@ -90,28 +130,44 @@ void TensorAllocator::init(const TensorAllocator &allocator, const Coordinates & uint8_t *TensorAllocator::data() const { - return (_buffer != nullptr) ? _buffer.get()->data() : nullptr; + return _buffer; } void TensorAllocator::allocate() { ARM_COMPUTE_ERROR_ON(_buffer != nullptr); - - _buffer = std::make_shared<std::vector<uint8_t>>(info().total_size()); + if(_associated_memory_group == nullptr) + { + _buffer = new uint8_t[info().total_size()](); + } + else + { + _associated_memory_group->finalize_memory(_owner, reinterpret_cast<void **>(&_buffer), info().total_size()); + } info().set_is_resizable(false); } void TensorAllocator::free() { - ARM_COMPUTE_ERROR_ON(_buffer == nullptr); + if((_associated_memory_group == nullptr) && (_buffer != nullptr)) + { + delete[] _buffer; + _buffer = nullptr; + info().set_is_resizable(true); + } +} - _buffer.reset(); - info().set_is_resizable(true); +void TensorAllocator::set_associated_memory_group(MemoryGroup *associated_memory_group) +{ + ARM_COMPUTE_ERROR_ON(associated_memory_group == nullptr); + ARM_COMPUTE_ERROR_ON(_associated_memory_group != nullptr); + ARM_COMPUTE_ERROR_ON(_buffer != nullptr); + _associated_memory_group = associated_memory_group; } uint8_t *TensorAllocator::lock() { - return (_buffer != nullptr) ? _buffer.get()->data() : nullptr; + return _buffer; } void TensorAllocator::unlock() |