From 28fcc35fbc0b22e85d234a882a9c1f9c4faa3900 Mon Sep 17 00:00:00 2001 From: Teresa Charlin Date: Wed, 7 Apr 2021 20:39:49 +0100 Subject: Substitute NEFullyConnectedLayerReshapeWeights by NETranspose Resolves partially: COMPMID-4359 (2/2) Signed-off-by: Teresa Charlin Change-Id: Id65ef04268575cc9d74be6114e82e116b8ed106d Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/5378 Tested-by: Arm Jenkins Reviewed-by: Georgios Pinitas Comments-Addressed: Arm Jenkins --- .../runtime/NEON/functions/NEFullyConnectedLayer.h | 54 +++------------------- docs/06_functions_list.dox | 1 - .../NEON/functions/NEFullyConnectedLayer.cpp | 37 +-------------- 3 files changed, 8 insertions(+), 84 deletions(-) diff --git a/arm_compute/runtime/NEON/functions/NEFullyConnectedLayer.h b/arm_compute/runtime/NEON/functions/NEFullyConnectedLayer.h index 58b11744a8..bc45e58b4b 100644 --- a/arm_compute/runtime/NEON/functions/NEFullyConnectedLayer.h +++ b/arm_compute/runtime/NEON/functions/NEFullyConnectedLayer.h @@ -31,55 +31,15 @@ #include "arm_compute/runtime/NEON/functions/NEFlattenLayer.h" #include "arm_compute/runtime/NEON/functions/NEGEMM.h" #include "arm_compute/runtime/NEON/functions/NEGEMMLowpMatrixMultiplyCore.h" +#include "arm_compute/runtime/NEON/functions/NETranspose.h" #include "arm_compute/runtime/Tensor.h" namespace arm_compute { -/** Basic function to reshape the weights of Fully Connected layer. This function calls the following kernels: - * - * @note The fully connected layer accepts "weights" tensors only with 2 dimensions. - */ -class NEFullyConnectedLayerReshapeWeights : public IFunction -{ -public: - /** Constructor */ - NEFullyConnectedLayerReshapeWeights(); - /** Prevent instances of this class from being copied (As this class contains pointers) */ - NEFullyConnectedLayerReshapeWeights(const NEFullyConnectedLayerReshapeWeights &) = delete; - /** Prevent instances of this class from being copied (As this class contains pointers) */ - NEFullyConnectedLayerReshapeWeights &operator=(const NEFullyConnectedLayerReshapeWeights &) = delete; - /** Prevent instances of this class from being moved (As this class contains non movable objects) */ - NEFullyConnectedLayerReshapeWeights(NEFullyConnectedLayerReshapeWeights &&) = delete; - /** Prevent instances of this class from being moved (As this class contains non movable objects) */ - NEFullyConnectedLayerReshapeWeights &operator=(NEFullyConnectedLayerReshapeWeights &&) = delete; - /** Default destructor */ - ~NEFullyConnectedLayerReshapeWeights(); - /** 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. Data type supported: Same as @p input. - */ - void configure(const ITensor *input, ITensor *output); - /** Static function to check if given info will lead to a valid configuration of @ref NEFullyConnectedLayerReshapeWeights - * - * @param[in] input Weights tensor info. The weights must be 2 dimensional. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32. - * @param[in] output Destination tensor info. 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 NEFullyConnectedLayerReshapeWeights */ +/** Basic function to manage the reshape weights generated from @ref NETranspose */ class NEFullyConnectedLayerReshapeWeightsManaged : public ITransformWeights { public: @@ -111,15 +71,15 @@ public: } private: - static constexpr uint32_t _uid = 0x0; - Tensor _output{}; - NEFullyConnectedLayerReshapeWeights _func{}; + static constexpr uint32_t _uid = 0x0; + Tensor _output{}; + NETranspose _func{}; }; } // namespace weights_transformations /** Basic function to compute a Fully Connected layer. This function calls the following kernels: * -# @ref NEIm2ColKernel (called when the input comes from a convolutional layer) - * -# @ref NEFullyConnectedLayerReshapeWeights (if @p are_weights_reshaped is set to false and transpose_weights is set to true ) (called once) + * -# @ref NETranspose (if @p are_weights_reshaped is set to false and transpose_weights is set to true ) (called once) * -# @ref NEGEMMMatrixMultiplyKernel or @ref NEGEMMLowpMatrixMultiplyCore (if quantized asymmetric) * -# @ref NEGEMMMatrixAdditionKernel or @ref NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint (if quantized asymmetric) (if @p biases is not equal to nullptr) * @@ -189,7 +149,7 @@ private: NEFlattenLayer _flatten; NEConvertFullyConnectedWeights _convert_weights; weights_transformations::NEConvertFullyConnectedWeightsManaged _convert_weights_managed; - NEFullyConnectedLayerReshapeWeights _reshape_weights_function; + NETranspose _reshape_weights_function; weights_transformations::NEFullyConnectedLayerReshapeWeightsManaged _reshape_weights_managed_function; NEGEMM _mm_gemm; NEGEMMLowpMatrixMultiplyCore _mm_gemmlowp; diff --git a/docs/06_functions_list.dox b/docs/06_functions_list.dox index 2cd16d0603..0b2263555d 100644 --- a/docs/06_functions_list.dox +++ b/docs/06_functions_list.dox @@ -67,7 +67,6 @@ namespace arm_compute - @ref NEDepthConvertLayer - @ref NEFlattenLayer - @ref NEFloor - - @ref NEFullyConnectedLayerReshapeWeights - @ref NEGather - @ref NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint - @ref NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint diff --git a/src/runtime/NEON/functions/NEFullyConnectedLayer.cpp b/src/runtime/NEON/functions/NEFullyConnectedLayer.cpp index 0a5318ac30..6ff102cd4a 100644 --- a/src/runtime/NEON/functions/NEFullyConnectedLayer.cpp +++ b/src/runtime/NEON/functions/NEFullyConnectedLayer.cpp @@ -142,41 +142,6 @@ Status validate_mm(const ITensorInfo *input, const ITensorInfo *weights, const I } } // namespace -struct NEFullyConnectedLayerReshapeWeights::Impl -{ - const ITensor *src{ nullptr }; - ITensor *dst{ nullptr }; - std::unique_ptr op{ nullptr }; -}; - -NEFullyConnectedLayerReshapeWeights::NEFullyConnectedLayerReshapeWeights() - : _impl(std::make_unique()) -{ -} - -NEFullyConnectedLayerReshapeWeights::~NEFullyConnectedLayerReshapeWeights() = default; - -void NEFullyConnectedLayerReshapeWeights::configure(const ITensor *input, ITensor *output) -{ - _impl->op = std::make_unique(); - _impl->op->configure(input->info(), output->info()); - _impl->src = input; - _impl->dst = output; -} - -Status NEFullyConnectedLayerReshapeWeights::validate(const ITensorInfo *input, const ITensorInfo *output) -{ - return cpu::kernels::CpuTransposeKernel::validate(input, output); -} - -void NEFullyConnectedLayerReshapeWeights::run() -{ - ITensorPack pack{}; - pack.add_tensor(TensorType::ACL_SRC, _impl->src); - pack.add_tensor(TensorType::ACL_DST, _impl->dst); - NEScheduler::get().schedule_op(_impl->op.get(), Window::DimY, _impl->op->window(), pack); -} - NEFullyConnectedLayer::~NEFullyConnectedLayer() = default; NEFullyConnectedLayer::NEFullyConnectedLayer(std::shared_ptr memory_manager, IWeightsManager *weights_manager) @@ -392,7 +357,7 @@ Status NEFullyConnectedLayer::validate(const ITensorInfo *input, const ITensorIn if(!weights_reshaped) { // Validate reshape weights kernel - ARM_COMPUTE_RETURN_ON_ERROR(NEFullyConnectedLayerReshapeWeights::validate(weights, &reshaped_weights)); + ARM_COMPUTE_RETURN_ON_ERROR(NETranspose::validate(weights, &reshaped_weights)); weights_to_use = &reshaped_weights; } -- cgit v1.2.1