From 68508897deafe26b5d50566a6ca3ba70c728dd12 Mon Sep 17 00:00:00 2001 From: Teresa Charlin Date: Wed, 7 Apr 2021 19:18:08 +0100 Subject: Substitute CLFullyConnectedLayerReshapeWeights by CLTranspose Resolves partially: COMPMID-4359 (1/2) Signed-off-by: Teresa Charlin Change-Id: Id1859f3cd530eb05f027226e2004cf518778147e Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/5377 Tested-by: Arm Jenkins Reviewed-by: Georgios Pinitas Comments-Addressed: Arm Jenkins --- .../runtime/CL/functions/CLFullyConnectedLayer.h | 68 +++------------------- 1 file changed, 9 insertions(+), 59 deletions(-) (limited to 'arm_compute/runtime/CL/functions/CLFullyConnectedLayer.h') diff --git a/arm_compute/runtime/CL/functions/CLFullyConnectedLayer.h b/arm_compute/runtime/CL/functions/CLFullyConnectedLayer.h index a640e344d4..75cb2dc1fa 100644 --- a/arm_compute/runtime/CL/functions/CLFullyConnectedLayer.h +++ b/arm_compute/runtime/CL/functions/CLFullyConnectedLayer.h @@ -31,65 +31,15 @@ #include "arm_compute/runtime/CL/functions/CLFlattenLayer.h" #include "arm_compute/runtime/CL/functions/CLGEMM.h" #include "arm_compute/runtime/CL/functions/CLGEMMLowpMatrixMultiplyCore.h" +#include "arm_compute/runtime/CL/functions/CLTranspose.h" #include "arm_compute/runtime/IWeightsManager.h" #include "arm_compute/runtime/MemoryGroup.h" namespace arm_compute { -/** Function to reshape the weights of Fully Connected layer with OpenCL by transposing input tensor. This function calls the following kernel: - * - * -# @ref opencl::kernels::ClTransposeKernel - * - * @note The fully connected layer accepts "weights" tensors only with 2 dimensions. - */ -class CLFullyConnectedLayerReshapeWeights : public IFunction -{ -public: - /** Constructor */ - CLFullyConnectedLayerReshapeWeights(); - /** Prevent instances of this class from being copied (As this class contains pointers) */ - CLFullyConnectedLayerReshapeWeights(const CLFullyConnectedLayerReshapeWeights &) = delete; - /** Default move constructor */ - CLFullyConnectedLayerReshapeWeights(CLFullyConnectedLayerReshapeWeights &&) = default; - /** Prevent instances of this class from being copied (As this class contains pointers) */ - CLFullyConnectedLayerReshapeWeights &operator=(const CLFullyConnectedLayerReshapeWeights &) = delete; - /** Default move assignment operator */ - CLFullyConnectedLayerReshapeWeights &operator=(CLFullyConnectedLayerReshapeWeights &&) = default; - /** Default destructor */ - ~CLFullyConnectedLayerReshapeWeights(); - /** Set the input and output tensors. - * - * @param[in] input Weights tensor. The weights must be 2 dimensional. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32. - * @param[out] output Destination tensor which stores the transposed input tensor. Data type supported: Same as @p input. - */ - void configure(const ICLTensor *input, ICLTensor *output); - /** Set the input and output tensors. - * - * @param[in] compile_context The compile context to be used. - * @param[in] input Weights tensor. The weights must be 2 dimensional. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32. - * @param[out] output Destination tensor which stores the transposed input tensor. Data type supported: Same as @p input. - */ - void configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output); - /** Static function to check if given info will lead to a valid configuration of @ref CLFullyConnectedLayerReshapeWeights - * - * @param[in] input Weights tensor. The weights must be 2 dimensional. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32. - * @param[in] output Destination tensor which stores the transposed input tensor. Data type supported: Same as @p input. - * - * @return a status - */ - static Status validate(const ITensorInfo *input, const ITensorInfo *output); - - // Inherited methods overridden - void run() override; - -private: - struct Impl; - std::unique_ptr _impl; -}; - namespace weights_transformations { -/** Basic function to manage the reshape weights generated from @ref CLFullyConnectedLayerReshapeWeights */ +/** Basic function to manage the reshape weights generated from @ref CLTranspose */ class CLFullyConnectedLayerReshapeWeightsManaged : public ITransformWeights { public: @@ -119,7 +69,7 @@ public: return _uid; } - /** Configures the @ref CLFullyConnectedLayerReshapeWeights function + /** Configures the @ref CLTranspose function * * @param[in] input Source tensor. Data type supported: QASYMM8/QASYMM8_SIGNED/F16/F32. */ @@ -127,7 +77,7 @@ public: { configure(CLKernelLibrary::get().get_compile_context(), input); } - /** Configures the @ref CLFullyConnectedLayerReshapeWeights function + /** Configures the @ref CLTranspose function * * @param[in] compile_context The compile context to be used. * @param[in] input Source tensor. Data type supported: QASYMM8/QASYMM8_SIGNED/F16/F32. @@ -138,16 +88,16 @@ public: } private: - static constexpr uint32_t _uid = 0x0; - CLTensor _output{}; - CLFullyConnectedLayerReshapeWeights _func{}; + static constexpr uint32_t _uid = 0x0; + CLTensor _output{}; + CLTranspose _func{}; }; } // namespace weights_transformations /** Basic function to compute a Fully Connected layer on OpenCL. This function calls the following OpenCL kernels: * * -# @ref CLIm2ColKernel (called when the input comes from a convolutional layer) - * -# @ref CLFullyConnectedLayerReshapeWeights (if @p are_weights_reshaped is set to false and transpose_weights is set to true ) (called once) + * -# @ref CLTranspose (if @p are_weights_reshaped is set to false and transpose_weights is set to true ) (called once) * -# @ref CLGEMMMatrixMultiplyKernel or @ref CLGEMMLowpMatrixMultiplyCore (if quantized asymmetric) * * @note The fully connected layer accepts "weights" tensors only with 2 dimensions. @@ -232,7 +182,7 @@ private: weights_transformations::CLConvertFullyConnectedWeightsManaged _convert_weights_managed; weights_transformations::CLFullyConnectedLayerReshapeWeightsManaged _reshape_weights_managed_function; CLFlattenLayer _flatten_layer; - CLFullyConnectedLayerReshapeWeights _reshape_weights_function; + CLTranspose _reshape_weights_function; CLGEMM _mm_gemm; CLGEMMLowpMatrixMultiplyCore _mm_gemmlowp; CLTensor _flatten_output; -- cgit v1.2.1