From 26014cf4d0519aef280c8444c60ec34c4e37e3b6 Mon Sep 17 00:00:00 2001 From: Georgios Pinitas Date: Mon, 9 Sep 2019 19:00:57 +0100 Subject: COMPMID-2649: Generalize MemoryGroup. Avoids any upcasting. Change-Id: I2181c7c9df59a7fb8a78e11934fbd96058fd39c7 Signed-off-by: Georgios Pinitas Reviewed-on: https://review.mlplatform.org/c/1918 Comments-Addressed: Arm Jenkins Tested-by: Arm Jenkins Reviewed-by: Gian Marco Iodice --- arm_compute/runtime/GLES_COMPUTE/GCMemoryGroup.h | 48 ---------------------- arm_compute/runtime/GLES_COMPUTE/GCTensor.h | 8 ++-- .../runtime/GLES_COMPUTE/GCTensorAllocator.h | 19 ++++----- .../GLES_COMPUTE/functions/GCConvolutionLayer.h | 6 +-- .../GLES_COMPUTE/functions/GCFullyConnectedLayer.h | 6 +-- .../runtime/GLES_COMPUTE/functions/GCGEMM.h | 6 +-- .../GLES_COMPUTE/functions/GCNormalizationLayer.h | 6 +-- .../GLES_COMPUTE/functions/GCSoftmaxLayer.h | 8 ++-- 8 files changed, 28 insertions(+), 79 deletions(-) delete mode 100644 arm_compute/runtime/GLES_COMPUTE/GCMemoryGroup.h (limited to 'arm_compute/runtime/GLES_COMPUTE') diff --git a/arm_compute/runtime/GLES_COMPUTE/GCMemoryGroup.h b/arm_compute/runtime/GLES_COMPUTE/GCMemoryGroup.h deleted file mode 100644 index 10f4fc6b05..0000000000 --- a/arm_compute/runtime/GLES_COMPUTE/GCMemoryGroup.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2018 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef __ARM_COMPUTE_GCMEMORYGROUP_H__ -#define __ARM_COMPUTE_GCMEMORYGROUP_H__ - -#include "arm_compute/runtime/MemoryGroupBase.h" - -#include "arm_compute/core/GLES_COMPUTE/OpenGLES.h" -#include "arm_compute/core/utils/misc/Cast.h" -#include "arm_compute/runtime/GLES_COMPUTE/GCTensor.h" - -namespace arm_compute -{ -using GCMemoryGroup = MemoryGroupBase; - -template <> -inline void MemoryGroupBase::associate_memory_group(GCTensor *obj) -{ - ARM_COMPUTE_ERROR_ON(obj == nullptr); - ARM_COMPUTE_ERROR_ON(dynamic_cast(obj->allocator()) == nullptr); - - auto allocator = arm_compute::utils::cast::polymorphic_downcast(obj->allocator()); - ARM_COMPUTE_ERROR_ON(allocator == nullptr); - allocator->set_associated_memory_group(this); -} -} // namespace arm_compute -#endif /*__ARM_COMPUTE_GCMEMORYGROUP_H__ */ diff --git a/arm_compute/runtime/GLES_COMPUTE/GCTensor.h b/arm_compute/runtime/GLES_COMPUTE/GCTensor.h index 05305f9b1b..344c78852b 100644 --- a/arm_compute/runtime/GLES_COMPUTE/GCTensor.h +++ b/arm_compute/runtime/GLES_COMPUTE/GCTensor.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2018 ARM Limited. + * Copyright (c) 2017-2019 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -34,7 +34,7 @@ class ITensorAllocator; class ITensorInfo; /** Interface for OpenGL ES tensor */ -class GCTensor : public IGCTensor +class GCTensor : public IGCTensor, public IMemoryManageable { public: /** Default constructor */ @@ -84,6 +84,7 @@ public: TensorInfo *info() override; uint8_t *buffer() const override; GLuint gc_buffer() const override; + void associate_memory_group(IMemoryGroup *memory_group) override; protected: // Inherited methods overridden: @@ -96,6 +97,5 @@ private: /** OpenGL ES Image */ using GCImage = GCTensor; -} - +} // namespace arm_compute #endif /*__ARM_COMPUTE_GCTENSOR_H__ */ diff --git a/arm_compute/runtime/GLES_COMPUTE/GCTensorAllocator.h b/arm_compute/runtime/GLES_COMPUTE/GCTensorAllocator.h index b7067664fc..2cd842942e 100644 --- a/arm_compute/runtime/GLES_COMPUTE/GCTensorAllocator.h +++ b/arm_compute/runtime/GLES_COMPUTE/GCTensorAllocator.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2018 ARM Limited. + * Copyright (c) 2017-2019 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -28,23 +28,20 @@ #include "arm_compute/core/GLES_COMPUTE/OpenGLES.h" #include "arm_compute/runtime/GLES_COMPUTE/GCMemory.h" #include "arm_compute/runtime/ITensorAllocator.h" -#include "arm_compute/runtime/MemoryGroupBase.h" +#include "arm_compute/runtime/MemoryGroup.h" #include namespace arm_compute { class GCTensor; -template -class MemoryGroupBase; -using GCMemoryGroup = MemoryGroupBase; /** Basic implementation of a GLES memory tensor allocator. */ class GCTensorAllocator : public ITensorAllocator { public: /** Default constructor. */ - GCTensorAllocator(GCTensor *owner = nullptr); + GCTensorAllocator(IMemoryManageable *owner = nullptr); /** Prevent instances of this class from being copied (As this class contains pointers) */ GCTensorAllocator(const GCTensorAllocator &) = delete; @@ -109,7 +106,7 @@ public: * * @param[in] associated_memory_group Memory group to associate the tensor with */ - void set_associated_memory_group(GCMemoryGroup *associated_memory_group); + void set_associated_memory_group(IMemoryGroup *associated_memory_group); protected: /** Call map() on the SSBO. @@ -122,10 +119,10 @@ protected: void unlock() override; private: - GCMemoryGroup *_associated_memory_group; /**< Registered memory group */ - GCMemory _memory; /**< OpenGL ES memory */ - uint8_t *_mapping; /**< Pointer to the CPU mapping of the OpenGL ES buffer. */ - GCTensor *_owner; /**< Owner of the allocator */ + IMemoryManageable *_owner; /**< Owner of the allocator */ + IMemoryGroup *_associated_memory_group; /**< Registered memory group */ + GCMemory _memory; /**< OpenGL ES memory */ + uint8_t *_mapping; /**< Pointer to the CPU mapping of the OpenGL ES buffer. */ }; } // namespace arm_compute #endif /* __ARM_COMPUTE_GCTENSORALLOCATOR_H__ */ diff --git a/arm_compute/runtime/GLES_COMPUTE/functions/GCConvolutionLayer.h b/arm_compute/runtime/GLES_COMPUTE/functions/GCConvolutionLayer.h index 4fac95e72f..74b875fcc0 100644 --- a/arm_compute/runtime/GLES_COMPUTE/functions/GCConvolutionLayer.h +++ b/arm_compute/runtime/GLES_COMPUTE/functions/GCConvolutionLayer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2018 ARM Limited. + * Copyright (c) 2017-2019 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -30,11 +30,11 @@ #include "arm_compute/core/GLES_COMPUTE/kernels/GCIm2ColKernel.h" #include "arm_compute/core/GLES_COMPUTE/kernels/GCWeightsReshapeKernel.h" #include "arm_compute/core/Types.h" -#include "arm_compute/runtime/GLES_COMPUTE/GCMemoryGroup.h" #include "arm_compute/runtime/GLES_COMPUTE/GCTensor.h" #include "arm_compute/runtime/GLES_COMPUTE/functions/GCActivationLayer.h" #include "arm_compute/runtime/GLES_COMPUTE/functions/GCGEMM.h" #include "arm_compute/runtime/IFunction.h" +#include "arm_compute/runtime/MemoryGroup.h" #include @@ -130,7 +130,7 @@ private: static Status validate_mm(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *output); private: - GCMemoryGroup _memory_group; + MemoryGroup _memory_group; GCConvolutionLayerReshapeWeights _reshape_weights; GCIm2ColKernel _input_im2col_kernel; GCGEMM _mm_gemm; diff --git a/arm_compute/runtime/GLES_COMPUTE/functions/GCFullyConnectedLayer.h b/arm_compute/runtime/GLES_COMPUTE/functions/GCFullyConnectedLayer.h index 63565df1a7..6fcebd63b4 100644 --- a/arm_compute/runtime/GLES_COMPUTE/functions/GCFullyConnectedLayer.h +++ b/arm_compute/runtime/GLES_COMPUTE/functions/GCFullyConnectedLayer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2018 ARM Limited. + * Copyright (c) 2017-2019 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -28,9 +28,9 @@ #include "arm_compute/core/GLES_COMPUTE/kernels/GCGEMMMatrixMultiplyKernel.h" #include "arm_compute/core/GLES_COMPUTE/kernels/GCIm2ColKernel.h" #include "arm_compute/core/GLES_COMPUTE/kernels/GCTransposeKernel.h" -#include "arm_compute/runtime/GLES_COMPUTE/GCMemoryGroup.h" #include "arm_compute/runtime/GLES_COMPUTE/GCTensor.h" #include "arm_compute/runtime/GLES_COMPUTE/IGCSimpleFunction.h" +#include "arm_compute/runtime/MemoryGroup.h" namespace arm_compute { @@ -92,7 +92,7 @@ private: void configure_fc_fc(const IGCTensor *input, const IGCTensor *weights, IGCTensor *output); void configure_conv_fc(const IGCTensor *input, const IGCTensor *weights, IGCTensor *output); - GCMemoryGroup _memory_group; + MemoryGroup _memory_group; GCIm2ColKernel _im2col_kernel; GCFullyConnectedLayerReshapeWeights _reshape_weights_kernel; GCGEMMMatrixMultiplyKernel _mm_kernel; diff --git a/arm_compute/runtime/GLES_COMPUTE/functions/GCGEMM.h b/arm_compute/runtime/GLES_COMPUTE/functions/GCGEMM.h index 2db254527f..75531b3428 100644 --- a/arm_compute/runtime/GLES_COMPUTE/functions/GCGEMM.h +++ b/arm_compute/runtime/GLES_COMPUTE/functions/GCGEMM.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2018 ARM Limited. + * Copyright (c) 2017-2019 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -29,9 +29,9 @@ #include "arm_compute/core/GLES_COMPUTE/kernels/GCGEMMMatrixAdditionKernel.h" #include "arm_compute/core/GLES_COMPUTE/kernels/GCGEMMMatrixMultiplyKernel.h" #include "arm_compute/core/GLES_COMPUTE/kernels/GCGEMMTranspose1xWKernel.h" -#include "arm_compute/runtime/GLES_COMPUTE/GCMemoryGroup.h" #include "arm_compute/runtime/GLES_COMPUTE/GCTensor.h" #include "arm_compute/runtime/IFunction.h" +#include "arm_compute/runtime/MemoryGroup.h" namespace arm_compute { @@ -96,7 +96,7 @@ public: void prepare() override; private: - GCMemoryGroup _memory_group; + MemoryGroup _memory_group; GCGEMMInterleave4x4Kernel _interleave_kernel; GCGEMMTranspose1xWKernel _transpose_kernel; GCGEMMMatrixMultiplyKernel _mm_kernel; diff --git a/arm_compute/runtime/GLES_COMPUTE/functions/GCNormalizationLayer.h b/arm_compute/runtime/GLES_COMPUTE/functions/GCNormalizationLayer.h index adc8157f0e..2e68f8edb9 100644 --- a/arm_compute/runtime/GLES_COMPUTE/functions/GCNormalizationLayer.h +++ b/arm_compute/runtime/GLES_COMPUTE/functions/GCNormalizationLayer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2018 ARM Limited. + * Copyright (c) 2017-2019 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -29,8 +29,8 @@ #include "arm_compute/core/GLES_COMPUTE/kernels/GCFillBorderKernel.h" #include "arm_compute/core/GLES_COMPUTE/kernels/GCNormalizationLayerKernel.h" #include "arm_compute/core/GLES_COMPUTE/kernels/GCPixelWiseMultiplicationKernel.h" -#include "arm_compute/runtime/GLES_COMPUTE/GCMemoryGroup.h" #include "arm_compute/runtime/GLES_COMPUTE/GCTensor.h" +#include "arm_compute/runtime/MemoryGroup.h" #include "arm_compute/core/Types.h" @@ -63,7 +63,7 @@ public: void run() override; private: - GCMemoryGroup _memory_group; + MemoryGroup _memory_group; GCTensor _squared_input; /**< The intermediate buffer which stores results of squaring input*/ GCNormalizationLayerKernel _norm_kernel; /**< Normalization layer kernel to run */ GCPixelWiseMultiplicationKernel _multiply_kernel; /**< Pixel multiplication kernel to run */ diff --git a/arm_compute/runtime/GLES_COMPUTE/functions/GCSoftmaxLayer.h b/arm_compute/runtime/GLES_COMPUTE/functions/GCSoftmaxLayer.h index f6c6edb6a1..ec7c8d8a2f 100644 --- a/arm_compute/runtime/GLES_COMPUTE/functions/GCSoftmaxLayer.h +++ b/arm_compute/runtime/GLES_COMPUTE/functions/GCSoftmaxLayer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2018 ARM Limited. + * Copyright (c) 2017-2019 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -25,9 +25,9 @@ #define __ARM_COMPUTE_GCSOFTMAXLAYER_H__ #include "arm_compute/core/GLES_COMPUTE/kernels/GCSoftmaxLayerKernel.h" -#include "arm_compute/runtime/GLES_COMPUTE/GCMemoryGroup.h" #include "arm_compute/runtime/GLES_COMPUTE/GCTensor.h" #include "arm_compute/runtime/IFunction.h" +#include "arm_compute/runtime/MemoryGroup.h" namespace arm_compute { @@ -65,7 +65,7 @@ public: void run() override; private: - GCMemoryGroup _memory_group; + MemoryGroup _memory_group; GCLogits1DMaxKernel _max_kernel; GCLogits1DShiftExpSumKernel _shift_exp_sum_kernel; GCLogits1DNormKernel _norm_kernel; @@ -73,5 +73,5 @@ private: GCTensor _sum; GCTensor _tmp; }; -} +} // namespace arm_compute #endif /* __ARM_COMPUTE_GCSOFTMAXLAYER_H__ */ -- cgit v1.2.1