From c1b76faf6be5c33dbf3269faea95e185ac37992f Mon Sep 17 00:00:00 2001 From: Manuel Bottini Date: Mon, 17 Jun 2019 12:04:40 +0100 Subject: COMPMID-2092: Refactoring interface for the deconvolution kernels (NEON/CL) 3RDPARTY_UPDATE Change-Id: Id7ddf97e2c9ceb2cb84084fab2c6f5697890c193 Signed-off-by: giuros01 Reviewed-on: https://review.mlplatform.org/c/1424 Comments-Addressed: Arm Jenkins Tested-by: Arm Jenkins Reviewed-by: Georgios Pinitas --- .../kernels/CLDeconvolutionLayerUpsampleKernel.h | 21 ++++++------- arm_compute/core/CPP/kernels/CPPUpsampleKernel.h | 11 +++---- arm_compute/core/utils/misc/ShapeCalculator.h | 23 +++++++-------- arm_compute/graph/GraphBuilder.h | 3 +- arm_compute/graph/backends/FunctionHelpers.h | 5 ++-- arm_compute/graph/frontend/Layers.h | 20 +++++-------- arm_compute/graph/nodes/DeconvolutionLayerNode.h | 13 ++------- .../runtime/CL/functions/CLDeconvolutionLayer.h | 34 ---------------------- .../CL/functions/CLDeconvolutionLayerUpsample.h | 20 +++++-------- arm_compute/runtime/CPP/functions/CPPUpsample.h | 10 +++---- .../runtime/NEON/functions/NEDeconvolutionLayer.h | 34 +--------------------- 11 files changed, 50 insertions(+), 144 deletions(-) (limited to 'arm_compute') diff --git a/arm_compute/core/CL/kernels/CLDeconvolutionLayerUpsampleKernel.h b/arm_compute/core/CL/kernels/CLDeconvolutionLayerUpsampleKernel.h index 5ccf4e64ed..21d026e0a1 100644 --- a/arm_compute/core/CL/kernels/CLDeconvolutionLayerUpsampleKernel.h +++ b/arm_compute/core/CL/kernels/CLDeconvolutionLayerUpsampleKernel.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2018 ARM Limited. + * Copyright (c) 2017-2019 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -50,22 +50,20 @@ public: /** Initialise the kernel's input and output. * - * @param[in] input Source tensor. Data types supported: QASYMM8/F16/F32. - * @param[out] output Destination tensor. Data types supported: same as @p input. All but the lowest two dimensions must be the same size as in the input tensor, i.e. scaling is only performed within the XY-plane. - * @param[in] inner_border Top and right inner border sizes. These rows and columns will be filled with zero. - * @param[in] info Contains padding and stride information described in @ref PadStrideInfo. + * @param[in] input Source tensor. Data types supported: QASYMM8/F16/F32. + * @param[out] output Destination tensor. Data types supported: same as @p input. All but the lowest two dimensions must be the same size as in the input tensor, i.e. scaling is only performed within the XY-plane. + * @param[in] info Contains padding and stride information described in @ref PadStrideInfo. */ - void configure(const ICLTensor *input, ICLTensor *output, const BorderSize &inner_border, const PadStrideInfo &info); + void configure(const ICLTensor *input, ICLTensor *output, const PadStrideInfo &info); /** Static function to check if given info will lead to a valid configuration of @ref CLDeconvolutionLayerUpsample * - * @param[in] input Source tensor info. Data types supported: QASYMM8/F16/F32. - * @param[in] output Destination tensor info. Data types supported: same as @p input. All but the lowest two dimensions must be the same size as in the input tensor, i.e. scaling is only performed within the XY-plane. - * @param[in] inner_border Top and right inner border sizes. These rows and columns will be filled with zero. - * @param[in] info Contains padding and stride information described in @ref PadStrideInfo. + * @param[in] input Source tensor info. Data types supported: QASYMM8/F16/F32. + * @param[in] output Destination tensor info. Data types supported: same as @p input. All but the lowest two dimensions must be the same size as in the input tensor, i.e. scaling is only performed within the XY-plane. + * @param[in] info Contains padding and stride information described in @ref PadStrideInfo. * * @return a status */ - static Status validate(const ITensorInfo *input, const ITensorInfo *output, const BorderSize &inner_border, const PadStrideInfo &info); + static Status validate(const ITensorInfo *input, const ITensorInfo *output, const PadStrideInfo &info); // Inherited methods overridden: void run(const Window &window, cl::CommandQueue &queue) override; @@ -73,7 +71,6 @@ public: private: const ICLTensor *_input; ICLTensor *_output; - BorderSize _inner_border; PadStrideInfo _info; }; } // namespace arm_compute diff --git a/arm_compute/core/CPP/kernels/CPPUpsampleKernel.h b/arm_compute/core/CPP/kernels/CPPUpsampleKernel.h index fedbb54d35..571debe1b3 100644 --- a/arm_compute/core/CPP/kernels/CPPUpsampleKernel.h +++ b/arm_compute/core/CPP/kernels/CPPUpsampleKernel.h @@ -55,13 +55,11 @@ public: /** Set the input and output of the kernel. * - * @param[in] input The input tensor to upsample. Data types supported: F32/F16/QASYMM8 - * @param[out] output The output tensor. Data types supported: Same as @p input - * @param[in] info Padding info. - * @param[in] inner_border_right The number of zeros added to right edge of the input. - * @param[in] inner_border_top The number of zeros added to top edge of the input. + * @param[in] input The input tensor to upsample. Data types supported: F32/F16/QASYMM8 + * @param[out] output The output tensor. Data types supported: Same as @p input + * @param[in] info Padding info. */ - void configure(const ITensor *input, ITensor *output, const PadStrideInfo &info, unsigned int inner_border_right, unsigned int inner_border_top); + void configure(const ITensor *input, ITensor *output, const PadStrideInfo &info); // Inherited methods overridden: void run(const Window &window, const ThreadInfo &info) override; @@ -71,7 +69,6 @@ private: const ITensor *_input; ITensor *_output; PadStrideInfo _info; - std::pair _inner_border; }; } // namespace arm_compute #endif /*__ARM_COMPUTE_CPPUPSAMPLEKERNEL_H__ */ diff --git a/arm_compute/core/utils/misc/ShapeCalculator.h b/arm_compute/core/utils/misc/ShapeCalculator.h index 010501454f..65a2a1edf4 100644 --- a/arm_compute/core/utils/misc/ShapeCalculator.h +++ b/arm_compute/core/utils/misc/ShapeCalculator.h @@ -438,20 +438,17 @@ inline TensorShape compute_depthwise_convolution_shape(const ITensorInfo &input, /** Calculate the upsampled output shape used for deconvolution * - * @param[in] input Input tensor info - * @param[in] weights Weights tensor shape - * @param[in] sx Stride on x axis - * @param[in] sy Stride on y axis - * @param[in] inner_border_right The number of zeros added to right edge of the input. - * @param[in] inner_border_top The number of zeros added to top edge of the input. - * @param[in] out_dims Output shape dimensions - * @param[in] padx Padding on x axis - * @param[in] pady Padding on y axis + * @param[in] input Input tensor info + * @param[in] weights Weights tensor shape + * @param[in] sx Stride on x axis + * @param[in] sy Stride on y axis + * @param[in] out_dims Output shape dimensions + * @param[in] padx Padding on x axis + * @param[in] pady Padding on y axis * * @return the calculated shape */ -inline TensorShape compute_deconvolution_upsampled_shape(const ITensorInfo &input, const ITensorInfo &weights, unsigned int sx, unsigned int sy, unsigned int inner_border_right, - unsigned int inner_border_top, +inline TensorShape compute_deconvolution_upsampled_shape(const ITensorInfo &input, const ITensorInfo &weights, unsigned int sx, unsigned int sy, std::pair &out_dims, unsigned int &padx, unsigned int &pady) { const DataLayout data_layout = input.data_layout(); @@ -459,8 +456,8 @@ inline TensorShape compute_deconvolution_upsampled_shape(const ITensorInfo &inpu const size_t idx_h = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT); // Find the upsampled dimensions - unsigned int out_x = (input.dimension(idx_w) - 1) * sx + inner_border_right + 1; - unsigned int out_y = (input.dimension(idx_h) - 1) * sy + inner_border_top + 1; + unsigned int out_x = (input.dimension(idx_w) - 1) * sx + 1; + unsigned int out_y = (input.dimension(idx_h) - 1) * sy + 1; // Find the padding needed for the convolution with stride 1 in order to match output shape padx = out_dims.first - (out_x - weights.dimension(idx_w) + 1); diff --git a/arm_compute/graph/GraphBuilder.h b/arm_compute/graph/GraphBuilder.h index 0aaed1da7d..e1049ca938 100644 --- a/arm_compute/graph/GraphBuilder.h +++ b/arm_compute/graph/GraphBuilder.h @@ -155,14 +155,13 @@ public: * @param[in] kernel_spatial_extend Spatial extend of convolution kernels * @param[in] depth Number of convolution kernels * @param[in] deconv_info Convolution layer information - * @param[in] inner_border Inner border (right, top) * @param[in] weights_accessor (Optional) Accessor of the weights node data * @param[in] bias_accessor (Optional) Accessor of the bias node data * * @return Node ID of the created node, EmptyNodeID in case of error */ static NodeID add_deconvolution_node(Graph &g, NodeParams params, NodeIdxPair input, - Size2D kernel_spatial_extend, unsigned int depth, PadStrideInfo deconv_info, Size2D inner_border, + Size2D kernel_spatial_extend, unsigned int depth, PadStrideInfo deconv_info, ITensorAccessorUPtr weights_accessor = nullptr, ITensorAccessorUPtr bias_accessor = nullptr); /** Adds a depth concatenate node to the graph * diff --git a/arm_compute/graph/backends/FunctionHelpers.h b/arm_compute/graph/backends/FunctionHelpers.h index fbf8d17f67..5ac4fdaed9 100644 --- a/arm_compute/graph/backends/FunctionHelpers.h +++ b/arm_compute/graph/backends/FunctionHelpers.h @@ -462,8 +462,7 @@ std::unique_ptr create_deconvolution_layer(DeconvolutionLayerNode &no typename TargetInfo::TensorType *biases = get_backing_tensor(node.input(2)); typename TargetInfo::TensorType *output = get_backing_tensor(node.output(0)); - const PadStrideInfo deconv_info = node.deconvolution_info(); - const Size2D inner_border = node.inner_border(); + const PadStrideInfo deconv_info = node.deconvolution_info(); // Create and configure function (we assume that functions have been validated before creation) std::shared_ptr mm = get_memory_manager(ctx, TargetInfo::TargetType); @@ -471,7 +470,7 @@ std::unique_ptr create_deconvolution_layer(DeconvolutionLayerNode &no std::tie(func, std::ignore) = create_named_memory_managed_function( std::string(), mm, - input, weights, biases, output, deconv_info, inner_border.x(), inner_border.y()); + input, weights, biases, output, deconv_info); // Log info ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " diff --git a/arm_compute/graph/frontend/Layers.h b/arm_compute/graph/frontend/Layers.h index f73b1f49d9..3fc4af46d5 100644 --- a/arm_compute/graph/frontend/Layers.h +++ b/arm_compute/graph/frontend/Layers.h @@ -370,26 +370,23 @@ class DeconvolutionLayer final : public ILayer public: /** Construct a convolution layer. * - * @param[in] conv_width Convolution width. - * @param[in] conv_height Convolution height. - * @param[in] ofm Output feature map. - * @param[in] weights Accessor to get kernel weights from. - * @param[in] bias Accessor to get kernel bias from. - * @param[in] deconv_info Padding and stride information. - * @param[in] inner_border Inner border padding (right, top) + * @param[in] conv_width Convolution width. + * @param[in] conv_height Convolution height. + * @param[in] ofm Output feature map. + * @param[in] weights Accessor to get kernel weights from. + * @param[in] bias Accessor to get kernel bias from. + * @param[in] deconv_info Padding and stride information. */ DeconvolutionLayer(unsigned int conv_width, unsigned int conv_height, unsigned int ofm, ITensorAccessorUPtr weights, ITensorAccessorUPtr bias, - PadStrideInfo deconv_info, - Size2D inner_border) + PadStrideInfo deconv_info) : _conv_width(conv_width), _conv_height(conv_height), _ofm(ofm), _deconv_info(std::move(deconv_info)), - _inner_border(inner_border), _weights(std::move(weights)), _bias(std::move(bias)) { @@ -400,7 +397,7 @@ public: NodeIdxPair input = { s.tail_node(), 0 }; NodeParams common_params = { name(), s.hints().target_hint }; return GraphBuilder::add_deconvolution_node(s.graph(), common_params, input, - Size2D(_conv_width, _conv_height), _ofm, _deconv_info, _inner_border, + Size2D(_conv_width, _conv_height), _ofm, _deconv_info, std::move(_weights), std::move(_bias)); } @@ -409,7 +406,6 @@ private: unsigned int _conv_height; unsigned int _ofm; const PadStrideInfo _deconv_info; - Size2D _inner_border; ITensorAccessorUPtr _weights; ITensorAccessorUPtr _bias; }; diff --git a/arm_compute/graph/nodes/DeconvolutionLayerNode.h b/arm_compute/graph/nodes/DeconvolutionLayerNode.h index 19501482c6..e6869d7aae 100644 --- a/arm_compute/graph/nodes/DeconvolutionLayerNode.h +++ b/arm_compute/graph/nodes/DeconvolutionLayerNode.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 ARM Limited. + * Copyright (c) 2018-2019 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -36,20 +36,14 @@ class DeconvolutionLayerNode final : public INode public: /** Constructor * - * @param[in] info DeConvolution layer attributes - * @param[in] inner_border Inner border (right, top) + * @param[in] info DeConvolution layer attributes */ - DeconvolutionLayerNode(PadStrideInfo info, Size2D inner_border); + DeconvolutionLayerNode(PadStrideInfo info); /** Deconvolution metadata accessor * * @return Deconvolution information */ PadStrideInfo deconvolution_info() const; - /** Deconvolution inner border accessor - * - * @return Inner border(top, right) - */ - Size2D inner_border() const; /** Computes deconvolution output descriptor * * @param[in] input_descriptor Input descriptor @@ -70,7 +64,6 @@ public: private: PadStrideInfo _info; - Size2D _inner_border; }; } // namespace graph } // namespace arm_compute diff --git a/arm_compute/runtime/CL/functions/CLDeconvolutionLayer.h b/arm_compute/runtime/CL/functions/CLDeconvolutionLayer.h index e5b406ee5e..b722b466f0 100644 --- a/arm_compute/runtime/CL/functions/CLDeconvolutionLayer.h +++ b/arm_compute/runtime/CL/functions/CLDeconvolutionLayer.h @@ -44,40 +44,6 @@ public: /** Default constructor */ CLDeconvolutionLayer(std::shared_ptr memory_manager = nullptr); - /** Set the input, weights, biases and output tensors. - * - * @note This method will be deprecated in the next release. - * - * @param[in,out] input Input tensor. 3 lower dimensions represent a single input, and an optional 4th dimension for batch of inputs. Data types supported: QASYMM8/F16/F32. - * @param[in] weights The 4d weights with dimensions [width, height, IFM, OFM]. Data type supported: Same as @p input. - * @param[in] bias (Optional) The biases have one dimension. Data type supported: Same as @p input. - * @param[out] output Output tensor. The output has the same number of dimensions as the @p input. - * @param[in] deconv_info Contains padding and policies to be used in the deconvolution, this is described in @ref PadStrideInfo. - * @param[in] inner_border_right The number of zeros added to right edge of the input. - * @param[in] inner_border_top The number of zeros added to top edge of the input. - * @param[in] weights_info (Optional) Weights information needed for @ref CLConvolutionLayer, specifies if the weights tensor has been reshaped with @ref CLWeightsReshapeKernel. - * - */ - void configure(ICLTensor *input, ICLTensor *weights, const ICLTensor *bias, ICLTensor *output, const PadStrideInfo &deconv_info, - unsigned int inner_border_right, unsigned int inner_border_top, const WeightsInfo &weights_info = WeightsInfo()); - /** Static function to check if given info will lead to a valid configuration of @ref CLDeconvolutionLayer - * - * @note This method will be deprecated in the next release. - * - * @param[in] input Input tensor info. 3 lower dimensions represent a single input, and an optional 4th dimension for batch of inputs. Data types supported: QASYMM8/F16/F32. - * @param[in] weights The 4d weights info with dimensions [width, height, IFM, OFM]. Data type supported: Same as @p input. - * @param[in] bias (Optional) The biases have one dimension. Data type supported: Same as @p input. - * @param[in] output Output tensor info. The output has the same number of dimensions as the @p input. - * @param[in] deconv_info Contains padding and policies to be used in the deconvolution, this is described in @ref PadStrideInfo. - * @param[in] inner_border_right The number of zeros added to right edge of the input. - * @param[in] inner_border_top The number of zeros added to top edge of the input. - * @param[in] weights_info (Optional) Weights information needed for @ref CLConvolutionLayer, specifies if the weights tensor has been reshaped with @ref CLWeightsReshapeKernel. - * - * @return a status - */ - static Status validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *bias, ITensorInfo *output, const PadStrideInfo &deconv_info, - unsigned int inner_border_right, unsigned int inner_border_top, const WeightsInfo &weights_info = WeightsInfo()); - /** Set the input, weights, biases and output tensors. * * @param[in,out] input Input tensor. 3 lower dimensions represent a single input, and an optional 4th dimension for batch of inputs. Data types supported: QASYMM8/F16/F32. diff --git a/arm_compute/runtime/CL/functions/CLDeconvolutionLayerUpsample.h b/arm_compute/runtime/CL/functions/CLDeconvolutionLayerUpsample.h index 3751178703..cab252f0ea 100644 --- a/arm_compute/runtime/CL/functions/CLDeconvolutionLayerUpsample.h +++ b/arm_compute/runtime/CL/functions/CLDeconvolutionLayerUpsample.h @@ -61,24 +61,20 @@ public: /** Initialize the function's source, destination, interpolation type and border_mode. * - * @param[in, out] input Source tensor. Data type supported: QASYMM8/F16/F32. - * @param[out] output Destination tensor. Data type supported: same as @p input. - * @param[in] inner_border The number of zeros added to right and top edges of the input. - * @param[in] info Contains padding and policies to be used in the deconvolution. + * @param[in, out] input Source tensor. Data type supported: QASYMM8/F16/F32. + * @param[out] output Destination tensor. Data type supported: same as @p input. + * @param[in] info Contains padding and policies to be used in the deconvolution. */ - void configure(ICLTensor *input, ICLTensor *output, const BorderSize &inner_border, - const PadStrideInfo &info); + void configure(ICLTensor *input, ICLTensor *output, const PadStrideInfo &info); /** Static function to check if given info will lead to a valid configuration of @ref CLDeconvolutionLayerUpsample * - * @param[in] input Source tensor info. Data type supported: QASYMM8/F16/F32. - * @param[in] output Destination tensor info. Data type supported: same as @p input. - * @param[in] inner_border The number of zeros added to right and top edges of the input. - * @param[in] info Contains padding and policies to be used in the deconvolution. + * @param[in] input Source tensor info. Data type supported: QASYMM8/F16/F32. + * @param[in] output Destination tensor info. Data type supported: same as @p input. + * @param[in] info Contains padding and policies to be used in the deconvolution. * * @return a status */ - static Status validate(const ITensorInfo *input, const ITensorInfo *output, const BorderSize &inner_border, - const PadStrideInfo &info); + static Status validate(const ITensorInfo *input, const ITensorInfo *output, const PadStrideInfo &info); // Inherited methods overridden: void run() override; diff --git a/arm_compute/runtime/CPP/functions/CPPUpsample.h b/arm_compute/runtime/CPP/functions/CPPUpsample.h index fd7d9c24bf..13f8755762 100644 --- a/arm_compute/runtime/CPP/functions/CPPUpsample.h +++ b/arm_compute/runtime/CPP/functions/CPPUpsample.h @@ -38,13 +38,11 @@ class CPPUpsample : public ICPPSimpleFunction public: /** Configure the upsample CPP kernel * - * @param[in] input The input tensor to upsample. Data types supported: F32/F16/QASYMM8 - * @param[out] output The output tensor. Data types supported: Same as @p input - * @param[in] info Padding information - * @param[in] inner_border_right The number of zeros added to right edge of the input. - * @param[in] inner_border_top The number of zeros added to top edge of the input. + * @param[in] input The input tensor to upsample. Data types supported: F32/F16/QASYMM8 + * @param[out] output The output tensor. Data types supported: Same as @p input + * @param[in] info Padding information */ - void configure(const ITensor *input, ITensor *output, const PadStrideInfo &info, unsigned int inner_border_right, unsigned int inner_border_top); + void configure(const ITensor *input, ITensor *output, const PadStrideInfo &info); }; } #endif /* __ARM_COMPUTE_CPPUPSAMPLE_H__ */ diff --git a/arm_compute/runtime/NEON/functions/NEDeconvolutionLayer.h b/arm_compute/runtime/NEON/functions/NEDeconvolutionLayer.h index 4eb684b9aa..62977a7647 100644 --- a/arm_compute/runtime/NEON/functions/NEDeconvolutionLayer.h +++ b/arm_compute/runtime/NEON/functions/NEDeconvolutionLayer.h @@ -86,37 +86,6 @@ public: NEDeconvolutionLayer &operator=(NEDeconvolutionLayer &&) = default; /** Default destructor */ virtual ~NEDeconvolutionLayer() = default; - /** Set the input, weights, biases and output tensors. - * - * @note This method will be deprecated in the next release. - * - * @param[in,out] input Input tensor. 3 lower dimensions represent a single input, and an optional 4th dimension for batch of inputs. Data types supported: F32/F16/QASYMM8. - * @param[in] weights The 4d weights with dimensions [width, height, IFM, OFM]. Data type supported: Same as @p input. - * @param[in] bias Optional, ignored if NULL. The biases have one dimension. Data type supported: Data types supported: S32 for QASYMM8 input, F32 for F32 input, F16 for F16 input. - * @param[out] output Output tensor. The output has the same number of dimensions as the @p input. - * @param[in] info Contains padding and policies to be used in the deconvolution, this is decribed in @ref PadStrideInfo. - * @param[in] inner_border_right The number of zeros added to right edge of the input. - * @param[in] inner_border_top The number of zeros added to top edge of the input. - * - */ - void configure(ITensor *input, const ITensor *weights, const ITensor *bias, ITensor *output, const PadStrideInfo &info, - unsigned int inner_border_right, unsigned int inner_border_top); - /** Static function to check if given info will lead to a valid configuration of @ref NEDeconvolutionLayer - * - * @note This method will be deprecated in the next release. - * - * @param[in] input Input tensor info. 3 lower dimensions represent a single input, and an optional 4th dimension for batch of inputs. Data types supported: F32/F16/QASYMM8. - * @param[in] weights The 4d weights info with dimensions [width, height, IFM, OFM]. Data type supported: Same as @p input. - * @param[in] bias (Optional) The biases have one dimension. Data type supported: Data types supported: S32 for QASYMM8 input, F32 for F32 input, F16 for F16 input. - * @param[in] output Output tensor info. The output has the same number of dimensions as the @p input. - * @param[in] info Contains padding and policies to be used in the deconvolution, this is decribed in @ref PadStrideInfo. - * @param[in] inner_border_right The number of zeros added to right edge of the input. - * @param[in] inner_border_top The number of zeros added to top edge of the input. - * - * @return a status - */ - static Status validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *bias, const ITensorInfo *output, const PadStrideInfo &info, - unsigned int inner_border_right, unsigned int inner_border_top); /** Set the input, weights, biases and output tensors. * @@ -154,8 +123,7 @@ private: const ITensor *_original_weights; ITensor *_input; PadStrideInfo _info; - std::pair _inner_border; - bool _is_prepared; + bool _is_prepared; }; } // arm_compute #endif /* __ARM_COMPUTE_NEDECONVOLUTIONLAYER_H__ */ -- cgit v1.2.1