blob: 3c1d20aeb81b767a96b63771983408113919d3ba [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
giuros01154bc1c2019-03-26 17:44:40 +00002 * Copyright (c) 2018-2019 ARM Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01003 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#ifndef __ARM_COMPUTE_NECONVOLUTIONLAYER_H__
25#define __ARM_COMPUTE_NECONVOLUTIONLAYER_H__
26
27#include "arm_compute/runtime/IFunction.h"
28
Anthony Barbier6ff3b192017-09-04 18:44:23 +010029#include "arm_compute/core/Types.h"
Georgios Pinitasbaf174e2017-09-08 19:47:30 +010030#include "arm_compute/runtime/MemoryGroup.h"
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +000031#include "arm_compute/runtime/NEON/functions/NEDirectConvolutionLayer.h"
giuros01154bc1c2019-03-26 17:44:40 +000032#include "arm_compute/runtime/NEON/functions/NEFFTConvolutionLayer.h"
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +000033#include "arm_compute/runtime/NEON/functions/NEGEMMConvolutionLayer.h"
Georgios Pinitas9fb11592018-04-26 20:34:58 +010034#include "arm_compute/runtime/NEON/functions/NEWinogradConvolutionLayer.h"
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010035#include <memory>
36
Anthony Barbier6ff3b192017-09-04 18:44:23 +010037namespace arm_compute
38{
39class ITensor;
40
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +000041/** Basic function to simulate a convolution layer. This function calls one of the following NEON functions:
Georgios Pinitas9fb11592018-04-26 20:34:58 +010042 * -# @ref NEGEMMConvolutionLayer (executed only in case GEMM is required for the operation)
43 * -# @ref NEWinogradConvolutionLayer (executed only in case Winograd is required for the operation)
44 * -# @ref NEDirectConvolutionLayer (executed only in case Direct Convolution is required for the operation)
giuros01154bc1c2019-03-26 17:44:40 +000045 * -# @ref NEFFTConvolutionLayer (executed only in case FFT is required for the operation)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010046 */
47class NEConvolutionLayer : public IFunction
48{
49public:
50 /** Constructor */
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +000051 NEConvolutionLayer(std::shared_ptr<IMemoryManager> memory_manager = nullptr);
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010052
Anthony Barbier6ff3b192017-09-04 18:44:23 +010053 /** Set the input and output tensors.
54 *
Giorgio Arenaa3221e62018-05-03 15:57:48 +010055 * @param[in] input Source tensor. 3 lower dimensions represent a single input [width, height, IFM],
56 * while every optional dimension from 4 and above represent a batch of inputs.
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +010057 * Data types supported: QASYMM8/F16/F32.
Giorgio Arenaa3221e62018-05-03 15:57:48 +010058 * @param[in] weights Weights tensor. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM]. Data type supported: Same as @p input.
59 * @param[in] biases Biases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM].
60 * Data type supported: Should match @p input data type, except for input of QASYMM8 type where biases should be of S32 type.
61 * @param[out] output Destination tensor. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs.
62 * Data types supported: Same as @p input.
63 * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo.
64 * @param[in] weights_info Specifies if the weights tensor has been reshaped with NEWeightsReshapeKernel. If this is not part of the fully connected layer the weights
65 * tensor has also been transposed with NEGEMMTranspose1xWKernel. Data type supported: Same as @p input.
66 * @param[in] dilation (Optional) Dilation, in elements, across x and y. Defaults to (1, 1).
67 * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Only RELU, BOUNDED_RELU and LU_BOUNDED_RELU supported.
68 * @param[in] enable_fast_math (Optional) Enable fast math computation. In case this flag were set, the function could dispatch the fastest implementation
Gian Marco Iodice916d1bc2018-08-13 11:20:41 +010069 * available which may introduce a drop of accuracy as well. Default is false
70 * @param[in] num_groups (Optional) Number of groups when performing a grouped convolution. num_groups != 1 is not supported
Anthony Barbier6ff3b192017-09-04 18:44:23 +010071 */
Alex Gilday7da29b62018-03-23 14:16:00 +000072 void configure(ITensor *input, const ITensor *weights, const ITensor *biases, ITensor *output, const PadStrideInfo &conv_info, const WeightsInfo &weights_info = WeightsInfo(),
Gian Marco Iodice916d1bc2018-08-13 11:20:41 +010073 const Size2D &dilation = Size2D(1U, 1U), const ActivationLayerInfo &act_info = ActivationLayerInfo(), bool enable_fast_math = false, unsigned int num_groups = 1);
Giorgio Arena7c23ad02017-11-30 15:08:38 +000074 /** Static function to check if given info will lead to a valid configuration of @ref NEConvolutionLayer
75 *
Giorgio Arenaa3221e62018-05-03 15:57:48 +010076 * @param[in] input Source tensor. 3 lower dimensions represent a single input [width, height, IFM],
77 * while every optional dimension from 4 and above represent a batch of inputs.
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +010078 * Data types supported: QASYMM8/F16/F32.
Giorgio Arenaa3221e62018-05-03 15:57:48 +010079 * @param[in] weights Weights tensor. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM]. Data type supported:Same as @p input.
80 * @param[in] biases Biases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM].
81 * Data type supported: Should match @p input data type, except for input of QASYMM8 type where biases should be of S32 type.
82 * @param[in] output Destination tensor. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs.
83 * Data types supported: Same as @p input.
84 * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo.
85 * @param[in] weights_info Specifies if the weights tensor has been reshaped with NEWeightsReshapeKernel. If this is not part of the fully connected layer the weights
86 * tensor has also been transposed with NEGEMMTranspose1xWKernel. Data type supported: Same as @p input.
87 * @param[in] dilation (Optional) Dilation, in elements, across x and y. Defaults to (1, 1).
88 * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
89 * @param[in] enable_fast_math (Optional) Enable fast math computation. In case this flag were set, the function could dispatch the fastest implementation
90 * available which may introduce a drop of accuracy as well. Default is false
Gian Marco Iodice916d1bc2018-08-13 11:20:41 +010091 * @param[in] num_groups (Optional) Number of groups when performing a grouped convolution. num_groups != 1 is not supported
Giorgio Arena7c23ad02017-11-30 15:08:38 +000092 *
93 * @return a status
94 */
95 static Status validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info,
Gian Marco Iodice916d1bc2018-08-13 11:20:41 +010096 const WeightsInfo &weights_info = WeightsInfo(), const Size2D &dilation = Size2D(1U, 1U), const ActivationLayerInfo &act_info = ActivationLayerInfo(), bool enable_fast_math = false,
97 unsigned int num_groups = 1);
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +000098 /** Static function to check if given info will return the convolution called by @ref NEConvolutionLayer
99 *
Giorgio Arenaa3221e62018-05-03 15:57:48 +0100100 * @param[in] input Source tensor. 3 lower dimensions represent a single input [width, height, IFM],
101 * while every optional dimension from 4 and above represent a batch of inputs.
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +0100102 * Data types supported: QASYMM8/F16/F32.
Giorgio Arenaa3221e62018-05-03 15:57:48 +0100103 * @param[in] weights Weights tensor. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM]. Data type supported:Same as @p input.
104 * @param[in] output Destination tensor. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs.
105 * Data types supported: Same as @p input.
106 * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo.
107 * @param[in] weights_info Specifies if the weights tensor has been reshaped with NEWeightsReshapeKernel. If this is not part of the fully connected layer the weights
108 * tensor has also been transposed with NEGEMMTranspose1xWKernel. Data type supported: Same as @p input.
109 * @param[in] dilation (Optional) Dilation, in elements, across x and y. Defaults to (1, 1).
110 * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
111 * @param[in] enable_fast_math (Optional) Enable fast math computation. In case this flag were set, the function could dispatch the fastest implementation
112 * available which may introduce a drop of accuracy as well. Default is false
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +0000113 *
114 * @return the Convolution Method Hint
115 */
Andrew Mundy4d9379a2018-03-15 16:47:03 +0000116 static ConvolutionMethod get_convolution_method(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *output, const PadStrideInfo &conv_info,
Giorgio Arenaa3221e62018-05-03 15:57:48 +0100117 const WeightsInfo &weights_info = WeightsInfo(), const Size2D &dilation = Size2D(1U, 1U), const ActivationLayerInfo &act_info = ActivationLayerInfo(), bool enable_fast_math = false);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100118 // Inherited methods overridden:
119 void run() override;
Georgios Pinitas72219332018-06-05 14:56:06 +0100120 void prepare() override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100121
122private:
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +0000123 std::shared_ptr<IMemoryManager> _memory_manager;
124 std::unique_ptr<IFunction> _function; /**< Function to run */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100125};
126}
127#endif /* __ARM_COMPUTE_NECONVOLUTIONLAYER_H__ */