From 9e9cbafa9e6cc6b543c89a96d52fc9c5fde04ceb Mon Sep 17 00:00:00 2001 From: Michalis Spyrou Date: Thu, 15 Mar 2018 14:41:34 +0000 Subject: COMPMID-1004 GLES: Add memory manager to GLES functions Change-Id: I80fc9c0dd02afd79b501abde751036f9599b7bf2 Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/125103 Tested-by: Jenkins Reviewed-by: Georgios Pinitas --- src/runtime/GLES_COMPUTE/GCTensorAllocator.cpp | 41 ++++++++++++++++++++------ 1 file changed, 32 insertions(+), 9 deletions(-) (limited to 'src/runtime/GLES_COMPUTE/GCTensorAllocator.cpp') diff --git a/src/runtime/GLES_COMPUTE/GCTensorAllocator.cpp b/src/runtime/GLES_COMPUTE/GCTensorAllocator.cpp index 694b34f1ec..abd2b483d3 100644 --- a/src/runtime/GLES_COMPUTE/GCTensorAllocator.cpp +++ b/src/runtime/GLES_COMPUTE/GCTensorAllocator.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2017-2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -31,11 +31,16 @@ using namespace arm_compute; -GCTensorAllocator::GCTensorAllocator() - : _gl_buffer(), _mapping(nullptr) +GCTensorAllocator::GCTensorAllocator(GCTensor *owner) + : _associated_memory_group(nullptr), _gl_buffer(), _mapping(nullptr), _owner(owner) { } +GCTensorAllocator::~GCTensorAllocator() +{ + _gl_buffer = support::cpp14::make_unique(); +} + uint8_t *GCTensorAllocator::data() { return _mapping; @@ -43,17 +48,35 @@ uint8_t *GCTensorAllocator::data() void GCTensorAllocator::allocate() { - _gl_buffer = support::cpp14::make_unique(); - ARM_COMPUTE_GL_CHECK(glBindBuffer(GL_SHADER_STORAGE_BUFFER, _gl_buffer->_ssbo_name)); - ARM_COMPUTE_GL_CHECK(glBufferData(GL_SHADER_STORAGE_BUFFER, static_cast(info().total_size()), nullptr, GL_STATIC_DRAW)); - ARM_COMPUTE_GL_CHECK(glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0)); + if(_associated_memory_group == nullptr) + { + _gl_buffer = support::cpp14::make_unique(); + ARM_COMPUTE_GL_CHECK(glBindBuffer(GL_SHADER_STORAGE_BUFFER, _gl_buffer->_ssbo_name)); + ARM_COMPUTE_GL_CHECK(glBufferData(GL_SHADER_STORAGE_BUFFER, static_cast(info().total_size()), nullptr, GL_STATIC_DRAW)); + ARM_COMPUTE_GL_CHECK(glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0)); + } + else + { + _associated_memory_group->finalize_memory(_owner, reinterpret_cast(&_gl_buffer), info().total_size()); + } info().set_is_resizable(false); } void GCTensorAllocator::free() { - _gl_buffer.reset(); - info().set_is_resizable(true); + if(_associated_memory_group == nullptr) + { + _gl_buffer.reset(); + info().set_is_resizable(true); + } +} + +void GCTensorAllocator::set_associated_memory_group(GCMemoryGroup *associated_memory_group) +{ + ARM_COMPUTE_ERROR_ON(associated_memory_group == nullptr); + ARM_COMPUTE_ERROR_ON(_associated_memory_group != nullptr); + ARM_COMPUTE_ERROR_ON(_gl_buffer.get() != nullptr); + _associated_memory_group = associated_memory_group; } uint8_t *GCTensorAllocator::lock() -- cgit v1.2.1