blob: 2ebb80bef24b96b00c09488b5ef00854c2354a8a [file] [log] [blame]
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +00001/*
Michele Di Giorgiobd2c8e12021-01-19 15:29:02 +00002 * Copyright (c) 2017-2021 Arm Limited.
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +00003 *
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 */
Michalis Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_NEGEMMCONVOLUTIONLAYER_H
25#define ARM_COMPUTE_NEGEMMCONVOLUTIONLAYER_H
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +000026
27#include "arm_compute/runtime/IFunction.h"
28
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +000029#include "arm_compute/core/Types.h"
Manuel Bottini29599d02021-07-06 15:01:35 +010030#include "arm_compute/runtime/IFunction.h"
31#include "arm_compute/runtime/IMemoryManager.h"
Michalis Spyrou1a569a32019-09-10 17:20:34 +010032#include "arm_compute/runtime/IWeightsManager.h"
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +000033#include "arm_compute/runtime/MemoryGroup.h"
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +000034
35#include <memory>
36
37namespace arm_compute
38{
39class ITensor;
Manuel Bottini29599d02021-07-06 15:01:35 +010040class ITensorInfo;
Michalis Spyrou1a569a32019-09-10 17:20:34 +010041
Michele Di Giorgio33f41fa2021-03-09 14:09:08 +000042/** Basic function to compute the convolution layer. This function calls the following kernels/functions:
Gian Marco Iodice597a8562018-08-01 15:06:06 +010043 *
Manuel Bottini29599d02021-07-06 15:01:35 +010044 * -# @ref cpu::CpuGemmConvolution
Gian Marco Iodice597a8562018-08-01 15:06:06 +010045 *
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +000046 */
47class NEGEMMConvolutionLayer : public IFunction
48{
49public:
50 /** Constructor */
Michalis Spyrou1a569a32019-09-10 17:20:34 +010051 NEGEMMConvolutionLayer(const std::shared_ptr<IMemoryManager> &memory_manager = nullptr, IWeightsManager *weights_manager = nullptr);
Georgios Pinitas1562be32018-03-08 19:09:19 +000052 /** Prevent instances of this class from being copied (As this class contains pointers) */
53 NEGEMMConvolutionLayer(const NEGEMMConvolutionLayer &) = delete;
Michalis Spyrou770dfeb2020-11-04 18:55:34 +000054 /** Prevent instances of this class from being moved (As this class contains non movable objects) */
55 NEGEMMConvolutionLayer(NEGEMMConvolutionLayer &&) = delete;
Georgios Pinitas1562be32018-03-08 19:09:19 +000056 /** Prevent instances of this class from being copied (As this class contains pointers) */
57 NEGEMMConvolutionLayer &operator=(const NEGEMMConvolutionLayer &) = delete;
Michalis Spyrou770dfeb2020-11-04 18:55:34 +000058 /** Prevent instances of this class from being moved (As this class contains non movable objects) */
59 NEGEMMConvolutionLayer &operator=(NEGEMMConvolutionLayer &&) = delete;
Michalis Spyrouebcebf12020-10-21 00:04:14 +010060 /** Default destructor */
61 ~NEGEMMConvolutionLayer();
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +000062 /** Set the input and output tensors.
63 *
Teresa Charlin62687422021-04-28 10:58:49 +010064 * Valid data layouts:
65 * - NHWC
66 * - NCHW
67 *
68 * Valid data type configurations:
69 * |src0 |src1 |src2 |dst |
70 * |:--------------|:------------------|:--------|:--------------|
71 * |F16 |F16 |F16 |F16 |
72 * |F32 |F32 |F32 |F32 |
73 * |BFLOAT16 |BFLOAT16 |BFLOAT16 |BFLOAT16 |
74 * |QASYMM8 |QASYMM8 |S32 |QASYMM8 |
75 * |QASYMM8 |QSYMM8_PER_CHANNEL |S32 |QASYMM8 |
76 * |QASYMM8_SIGNED |QASYMM8_SIGNED |S32 |QASYMM8_SIGNED |
77 * |QASYMM8_SIGNED |QSYMM8_PER_CHANNEL |S32 |QASYMM8_SIGNED |
78 *
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +000079 * @param[in] input Source tensor. 3 lower dimensions represent a single input [width, height, IFM],
80 * while every optional dimension from 4 and above represent a batch of inputs.
Georgios Pinitasc7b183a2020-03-06 18:12:09 +000081 * Data types supported: QASYMM8/QASYMM8_SIGNED/BFLOAT16/F16/F32.
82 * @param[in] weights Weights tensor. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM].
83 * Data type supported: QASYMM8/QASYMM8_SIGNED/QSYMM8_PER_CHANNEL/BFLOAT16/F16/F32.
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +000084 * @param[in] biases Biases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM].
Georgios Pinitas6e1791b2019-12-02 19:01:25 +000085 * Data type supported: Should match @p input data type, except for input of QASYMM8/QASYMM8_SIGNED type where biases should be of S32 type.
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +000086 * @param[out] output Destination tensor. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs.
87 * Data types supported: Same as @p input.
88 * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo.
89 * @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
Michele Di Giorgio93b75e02021-06-21 12:00:43 +010090 * tensor has also been transposed with cpu::kernels::CpuGemmTranspose1xWKernel. Data type supported: Same as @p input.
Alex Gilday7da29b62018-03-23 14:16:00 +000091 * @param[in] dilation (Optional) Dilation, in elements, across x and y. Defaults to (1, 1).
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000092 * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Only RELU, BOUNDED_RELU and LU_BOUNDED_RELU supported.
Gian Marco Iodice916d1bc2018-08-13 11:20:41 +010093 * @param[in] num_groups (Optional) Number of groups when performing a grouped convolution. num_groups != 1 is not supported
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +000094 */
Alex Gilday7da29b62018-03-23 14:16:00 +000095 void configure(const 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 +010096 const Size2D &dilation = Size2D(1U, 1U), const ActivationLayerInfo &act_info = ActivationLayerInfo(), unsigned int num_groups = 1);
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +000097 /** Static function to check if given info will lead to a valid configuration of @ref NEGEMMConvolutionLayer
98 *
Georgios Pinitas6e1791b2019-12-02 19:01:25 +000099 * @param[in] input Source tensor info. 3 lower dimensions represent a single input [width, height, IFM],
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +0000100 * while every optional dimension from 4 and above represent a batch of inputs.
Georgios Pinitasc7b183a2020-03-06 18:12:09 +0000101 * Data types supported: QASYMM8/QASYMM8_SIGNED/BFLOAT16/F16/F32.
102 * @param[in] weights Weights tensor info. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM].
103 * Data type supported: QASYMM8/QASYMM8_SIGNED/QSYMM8_PER_CHANNEL/BFLOAT16/F16/F32.
Georgios Pinitas6e1791b2019-12-02 19:01:25 +0000104 * @param[in] biases Biases tensor info. Shared biases supported. Biases are 1D tensor with dimensions [OFM].
105 * Data type supported: Should match @p input data type, except for input of QASYMM8/QASYMM8_SIGNED type where biases should be of S32 type.
106 * @param[in] output Destination tensor info. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs.
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +0000107 * Data types supported: Same as @p input.
108 * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo.
109 * @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
Michele Di Giorgio93b75e02021-06-21 12:00:43 +0100110 * tensor has also been transposed with cpu::kernels::CpuGemmTranspose1xWKernel. Data type supported: Same as @p input.
Alex Gilday7da29b62018-03-23 14:16:00 +0000111 * @param[in] dilation (Optional) Dilation, in elements, across x and y. Defaults to (1, 1).
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000112 * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Only RELU, BOUNDED_RELU and LU_BOUNDED_RELU supported.
Gian Marco Iodice916d1bc2018-08-13 11:20:41 +0100113 * @param[in] num_groups (Optional) Number of groups when performing a grouped convolution. num_groups != 1 is not supported
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +0000114 *
115 * @return a status
116 */
117 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 +0100118 const WeightsInfo &weights_info = WeightsInfo(), const Size2D &dilation = Size2D(1U, 1U), const ActivationLayerInfo &act_info = ActivationLayerInfo(), unsigned int num_groups = 1);
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +0000119
120 // Inherited methods overridden:
121 void run() override;
Georgios Pinitas72219332018-06-05 14:56:06 +0100122 void prepare() override;
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +0000123
124private:
Manuel Bottini29599d02021-07-06 15:01:35 +0100125 struct Impl;
126 std::unique_ptr<Impl> _impl;
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +0000127};
Georgios Pinitas041f36d2018-09-18 18:38:37 +0100128} // namespace arm_compute
Manuel Bottini29599d02021-07-06 15:01:35 +0100129#endif /* ARM_COMPUTE_NEGEMMCONVOLUTIONLAYER_H */