Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | bd2c8e1 | 2021-01-19 15:29:02 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2021 Arm Limited. |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 3 | * |
| 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 Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_NEGEMMCONVOLUTIONLAYER_H |
| 25 | #define ARM_COMPUTE_NEGEMMCONVOLUTIONLAYER_H |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 26 | |
| 27 | #include "arm_compute/runtime/IFunction.h" |
| 28 | |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 29 | #include "arm_compute/core/Types.h" |
Michalis Spyrou | 1a569a3 | 2019-09-10 17:20:34 +0100 | [diff] [blame] | 30 | #include "arm_compute/runtime/IWeightsManager.h" |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 31 | #include "arm_compute/runtime/MemoryGroup.h" |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 32 | #include "arm_compute/runtime/NEON/functions/NEGEMM.h" |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 33 | #include "arm_compute/runtime/NEON/functions/NEGEMMLowpMatrixMultiplyCore.h" |
| 34 | #include "arm_compute/runtime/NEON/functions/NEGEMMLowpOutputStage.h" |
Gian Marco Iodice | db9d46d | 2018-08-08 12:29:38 +0100 | [diff] [blame] | 35 | #include "arm_compute/runtime/NEON/functions/NEReshapeLayer.h" |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 36 | #include "arm_compute/runtime/Tensor.h" |
| 37 | |
| 38 | #include <memory> |
| 39 | |
| 40 | namespace arm_compute |
| 41 | { |
| 42 | class ITensor; |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 43 | class NECol2ImKernel; |
| 44 | class NEIm2ColKernel; |
| 45 | class NEWeightsReshapeKernel; |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 46 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 47 | /** Function to reshape the weights. This function calls the following kernel: |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 48 | * -# @ref NEWeightsReshapeKernel |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 49 | */ |
| 50 | class NEConvolutionLayerReshapeWeights : public IFunction |
| 51 | { |
| 52 | public: |
| 53 | /** Constructor */ |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 54 | NEConvolutionLayerReshapeWeights(); |
Michalis Spyrou | 1a569a3 | 2019-09-10 17:20:34 +0100 | [diff] [blame] | 55 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 56 | NEConvolutionLayerReshapeWeights(const NEConvolutionLayerReshapeWeights &) = delete; |
Michalis Spyrou | 770dfeb | 2020-11-04 18:55:34 +0000 | [diff] [blame] | 57 | /** Prevent instances of this class from being moved (As this class contains non movable objects) */ |
| 58 | NEConvolutionLayerReshapeWeights(NEConvolutionLayerReshapeWeights &&) = delete; |
Michalis Spyrou | 1a569a3 | 2019-09-10 17:20:34 +0100 | [diff] [blame] | 59 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 60 | NEConvolutionLayerReshapeWeights &operator=(const NEConvolutionLayerReshapeWeights &) = delete; |
Michalis Spyrou | 770dfeb | 2020-11-04 18:55:34 +0000 | [diff] [blame] | 61 | /** Prevent instances of this class from being moved (As this class contains non movable objects) */ |
| 62 | NEConvolutionLayerReshapeWeights &operator=(NEConvolutionLayerReshapeWeights &&) = delete; |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 63 | /** Default destructor */ |
| 64 | ~NEConvolutionLayerReshapeWeights(); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 65 | /** Set the input and output tensors. |
| 66 | * |
Georgios Pinitas | c7b183a | 2020-03-06 18:12:09 +0000 | [diff] [blame] | 67 | * @param[in] weights Weights tensor. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM]. |
Michele Di Giorgio | f9b595a | 2020-07-03 13:34:52 +0100 | [diff] [blame] | 68 | * Data type supported: All. |
Michele Di Giorgio | f29d1b7 | 2019-10-29 10:58:13 +0000 | [diff] [blame] | 69 | * @param[in] biases Biases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM]. |
Michele Di Giorgio | f9b595a | 2020-07-03 13:34:52 +0100 | [diff] [blame] | 70 | * Data type supported: same as @p weights. |
| 71 | * @warning Appending biases to weights reshaped matrix is not supported for quantized asymmetric types. |
| 72 | * @param[out] output Destination tensor. Data types supported: same as @p weights. |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 73 | */ |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 74 | void configure(const ITensor *weights, const ITensor *biases, ITensor *output); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 75 | /** Static function to check if given info will lead to a valid configuration of @ref NEConvolutionLayerReshapeWeights |
| 76 | * |
Georgios Pinitas | c7b183a | 2020-03-06 18:12:09 +0000 | [diff] [blame] | 77 | * @param[in] weights Weights tensor info. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM]. |
Michele Di Giorgio | f9b595a | 2020-07-03 13:34:52 +0100 | [diff] [blame] | 78 | * Data type supported: All. |
Michele Di Giorgio | f29d1b7 | 2019-10-29 10:58:13 +0000 | [diff] [blame] | 79 | * @param[in] biases Biases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM]. |
Michele Di Giorgio | f9b595a | 2020-07-03 13:34:52 +0100 | [diff] [blame] | 80 | * Data type supported: same as @p weights. |
| 81 | * @warning Appending biases to weights reshaped matrix is not supported for quantized asymmetric types. |
| 82 | * @param[in] output Destination tensor. Data types supported: same as @p weights. |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 83 | * |
| 84 | * @return an error status |
| 85 | */ |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 86 | static Status validate(const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 87 | |
| 88 | // Inherited methods overridden: |
| 89 | void run() override; |
| 90 | |
| 91 | private: |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 92 | std::unique_ptr<NEWeightsReshapeKernel> _weights_reshape_kernel; |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 93 | }; |
| 94 | |
Michalis Spyrou | 1a569a3 | 2019-09-10 17:20:34 +0100 | [diff] [blame] | 95 | namespace weights_transformations |
| 96 | { |
| 97 | /** Basic function to manage the reshape weights generated from @ref NEConvolutionLayerReshapeWeights */ |
| 98 | class NEConvolutionLayerReshapeWeightsTransform : public ITransformWeights |
| 99 | { |
| 100 | public: |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 101 | /** Constructor */ |
| 102 | NEConvolutionLayerReshapeWeightsTransform() = default; |
| 103 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 104 | NEConvolutionLayerReshapeWeightsTransform(const NEConvolutionLayerReshapeWeightsTransform &) = delete; |
| 105 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 106 | NEConvolutionLayerReshapeWeightsTransform &operator=(const NEConvolutionLayerReshapeWeightsTransform &) = delete; |
| 107 | /** Prevent instances of this class from being moved (As this class contains non movable objects) */ |
| 108 | NEConvolutionLayerReshapeWeightsTransform(NEConvolutionLayerReshapeWeightsTransform &&) = delete; |
| 109 | /** Prevent instances of this class from being moved (As this class contains non movable objects) */ |
| 110 | NEConvolutionLayerReshapeWeightsTransform &operator=(NEConvolutionLayerReshapeWeightsTransform &&) = delete; |
| 111 | /** Default destructor */ |
| 112 | ~NEConvolutionLayerReshapeWeightsTransform() = default; |
Michalis Spyrou | 1a569a3 | 2019-09-10 17:20:34 +0100 | [diff] [blame] | 113 | void configure(const ITensor *input, const ITensor *biases) |
| 114 | { |
| 115 | _bias_bit = (biases != nullptr) ? 1 : 0; |
| 116 | _func.configure(input, biases, &_output); |
| 117 | } |
| 118 | |
| 119 | void run() override |
| 120 | { |
| 121 | _output.allocator()->allocate(); |
| 122 | _func.run(); |
| 123 | _reshape_run = true; |
| 124 | } |
| 125 | |
| 126 | ITensor *get_weights() override |
| 127 | { |
| 128 | return &_output; |
| 129 | } |
| 130 | |
| 131 | void release() override |
| 132 | { |
| 133 | _output.allocator()->free(); |
| 134 | } |
| 135 | |
| 136 | uint32_t uid() override |
| 137 | { |
| 138 | return ((0x8) | (_bias_bit << 7)); |
| 139 | } |
| 140 | |
| 141 | bool is_reshape_run() |
| 142 | { |
| 143 | return _reshape_run; |
| 144 | } |
| 145 | |
| 146 | private: |
| 147 | Tensor _output{}; |
| 148 | NEConvolutionLayerReshapeWeights _func{}; |
| 149 | int32_t _bias_bit{ 0 }; |
| 150 | }; |
| 151 | } // namespace weights_transformations |
| 152 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 153 | /** Basic function to compute the convolution layer. This function calls the following NEON kernels/functions: |
| 154 | * |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 155 | * -# @ref NEIm2ColKernel |
Michele Di Giorgio | a602f03 | 2020-03-12 19:34:33 +0000 | [diff] [blame] | 156 | * -# @ref NEGEMM (if the data type is BFLOAT16/FP16/FP32) |
Georgios Pinitas | 6e1791b | 2019-12-02 19:01:25 +0000 | [diff] [blame] | 157 | * -# @ref NEGEMMLowpMatrixMultiplyCore (if the data type is QASYMM8/QASYMM8_SIGNED) |
| 158 | * -# @ref NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint (if the data type is QASYMM8/QASYMM8_SIGNED) |
Michele Di Giorgio | bd2c8e1 | 2021-01-19 15:29:02 +0000 | [diff] [blame] | 159 | * -# @ref NEArithmeticAddition (if biases != nullptr and we have a 1x1 convolution with the NHWC data layout) |
Georgios Pinitas | 932491f | 2018-09-21 16:33:15 +0100 | [diff] [blame] | 160 | * -# @ref NECol2ImKernel (if NCHW data layout) |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 161 | * |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 162 | */ |
| 163 | class NEGEMMConvolutionLayer : public IFunction |
| 164 | { |
| 165 | public: |
| 166 | /** Constructor */ |
Michalis Spyrou | 1a569a3 | 2019-09-10 17:20:34 +0100 | [diff] [blame] | 167 | NEGEMMConvolutionLayer(const std::shared_ptr<IMemoryManager> &memory_manager = nullptr, IWeightsManager *weights_manager = nullptr); |
Georgios Pinitas | 1562be3 | 2018-03-08 19:09:19 +0000 | [diff] [blame] | 168 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 169 | NEGEMMConvolutionLayer(const NEGEMMConvolutionLayer &) = delete; |
Michalis Spyrou | 770dfeb | 2020-11-04 18:55:34 +0000 | [diff] [blame] | 170 | /** Prevent instances of this class from being moved (As this class contains non movable objects) */ |
| 171 | NEGEMMConvolutionLayer(NEGEMMConvolutionLayer &&) = delete; |
Georgios Pinitas | 1562be3 | 2018-03-08 19:09:19 +0000 | [diff] [blame] | 172 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 173 | NEGEMMConvolutionLayer &operator=(const NEGEMMConvolutionLayer &) = delete; |
Michalis Spyrou | 770dfeb | 2020-11-04 18:55:34 +0000 | [diff] [blame] | 174 | /** Prevent instances of this class from being moved (As this class contains non movable objects) */ |
| 175 | NEGEMMConvolutionLayer &operator=(NEGEMMConvolutionLayer &&) = delete; |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 176 | /** Default destructor */ |
| 177 | ~NEGEMMConvolutionLayer(); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 178 | /** Set the input and output tensors. |
| 179 | * |
| 180 | * @param[in] input Source tensor. 3 lower dimensions represent a single input [width, height, IFM], |
| 181 | * while every optional dimension from 4 and above represent a batch of inputs. |
Georgios Pinitas | c7b183a | 2020-03-06 18:12:09 +0000 | [diff] [blame] | 182 | * Data types supported: QASYMM8/QASYMM8_SIGNED/BFLOAT16/F16/F32. |
| 183 | * @param[in] weights Weights tensor. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM]. |
| 184 | * Data type supported: QASYMM8/QASYMM8_SIGNED/QSYMM8_PER_CHANNEL/BFLOAT16/F16/F32. |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 185 | * @param[in] biases Biases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM]. |
Georgios Pinitas | 6e1791b | 2019-12-02 19:01:25 +0000 | [diff] [blame] | 186 | * 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 Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 187 | * @param[out] output Destination tensor. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs. |
| 188 | * Data types supported: Same as @p input. |
| 189 | * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo. |
| 190 | * @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 |
| 191 | * tensor has also been transposed with NEGEMMTranspose1xWKernel. Data type supported: Same as @p input. |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 192 | * @param[in] dilation (Optional) Dilation, in elements, across x and y. Defaults to (1, 1). |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 193 | * @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 Iodice | 916d1bc | 2018-08-13 11:20:41 +0100 | [diff] [blame] | 194 | * @param[in] num_groups (Optional) Number of groups when performing a grouped convolution. num_groups != 1 is not supported |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 195 | */ |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 196 | void configure(const ITensor *input, const ITensor *weights, const ITensor *biases, ITensor *output, const PadStrideInfo &conv_info, const WeightsInfo &weights_info = WeightsInfo(), |
Gian Marco Iodice | 916d1bc | 2018-08-13 11:20:41 +0100 | [diff] [blame] | 197 | const Size2D &dilation = Size2D(1U, 1U), const ActivationLayerInfo &act_info = ActivationLayerInfo(), unsigned int num_groups = 1); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 198 | /** Static function to check if given info will lead to a valid configuration of @ref NEGEMMConvolutionLayer |
| 199 | * |
Georgios Pinitas | 6e1791b | 2019-12-02 19:01:25 +0000 | [diff] [blame] | 200 | * @param[in] input Source tensor info. 3 lower dimensions represent a single input [width, height, IFM], |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 201 | * while every optional dimension from 4 and above represent a batch of inputs. |
Georgios Pinitas | c7b183a | 2020-03-06 18:12:09 +0000 | [diff] [blame] | 202 | * Data types supported: QASYMM8/QASYMM8_SIGNED/BFLOAT16/F16/F32. |
| 203 | * @param[in] weights Weights tensor info. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM]. |
| 204 | * Data type supported: QASYMM8/QASYMM8_SIGNED/QSYMM8_PER_CHANNEL/BFLOAT16/F16/F32. |
Georgios Pinitas | 6e1791b | 2019-12-02 19:01:25 +0000 | [diff] [blame] | 205 | * @param[in] biases Biases tensor info. Shared biases supported. Biases are 1D tensor with dimensions [OFM]. |
| 206 | * Data type supported: Should match @p input data type, except for input of QASYMM8/QASYMM8_SIGNED type where biases should be of S32 type. |
| 207 | * @param[in] output Destination tensor info. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs. |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 208 | * Data types supported: Same as @p input. |
| 209 | * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo. |
| 210 | * @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 |
| 211 | * tensor has also been transposed with NEGEMMTranspose1xWKernel. Data type supported: Same as @p input. |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 212 | * @param[in] dilation (Optional) Dilation, in elements, across x and y. Defaults to (1, 1). |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 213 | * @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 Iodice | 916d1bc | 2018-08-13 11:20:41 +0100 | [diff] [blame] | 214 | * @param[in] num_groups (Optional) Number of groups when performing a grouped convolution. num_groups != 1 is not supported |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 215 | * |
| 216 | * @return a status |
| 217 | */ |
| 218 | static Status validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info, |
Gian Marco Iodice | 916d1bc | 2018-08-13 11:20:41 +0100 | [diff] [blame] | 219 | const WeightsInfo &weights_info = WeightsInfo(), const Size2D &dilation = Size2D(1U, 1U), const ActivationLayerInfo &act_info = ActivationLayerInfo(), unsigned int num_groups = 1); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 220 | |
| 221 | // Inherited methods overridden: |
| 222 | void run() override; |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 223 | void prepare() override; |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 224 | |
| 225 | private: |
| 226 | /** Configures the appropriate matrix multiply routine |
| 227 | * |
Georgios Pinitas | c7b183a | 2020-03-06 18:12:09 +0000 | [diff] [blame] | 228 | * @param[in] input Input tensor. Data types supported: QASYMM8/QASYMM8_SIGNED/BFLOAT16/F16/F32. |
| 229 | * @param[in] weights Weights tensor. Data type supported: QASYMM8/QASYMM8_SIGNED/QSYMM8_PER_CHANNEL/BFLOAT16/F16/F32. |
George Wort | 2d7e683 | 2019-02-22 16:37:41 +0000 | [diff] [blame] | 230 | * @param[in] biases Biases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM]. |
Georgios Pinitas | 6e1791b | 2019-12-02 19:01:25 +0000 | [diff] [blame] | 231 | * Data type supported: Should match @p input data type, except for input of QASYMM8/QASYMM8_SIGNED type where biases should be of S32 type. |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 232 | * @param[out] output Output tensor. Data types supported: Same as @p input, |
Georgios Pinitas | 6e1791b | 2019-12-02 19:01:25 +0000 | [diff] [blame] | 233 | * except for input of QASYMM8/QASYMM8_SIGNED type where output should be of S32 type. |
George Wort | 2d7e683 | 2019-02-22 16:37:41 +0000 | [diff] [blame] | 234 | * @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 Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 235 | * @param[in] gemm_3d_depth (Optional) Depth of GEMM 3D (Defaults to 1) |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 236 | */ |
George Wort | 2d7e683 | 2019-02-22 16:37:41 +0000 | [diff] [blame] | 237 | void configure_mm(const ITensor *input, const ITensor *weights, const ITensor *biases, ITensor *output, const ActivationLayerInfo &act_info = ActivationLayerInfo(), int gemm_3d_depth = 1); |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 238 | /** Static function to check if given info will lead to a valid configuration of @ref NEGEMMConvolutionLayer matrix multiply routines |
| 239 | * |
Georgios Pinitas | c7b183a | 2020-03-06 18:12:09 +0000 | [diff] [blame] | 240 | * @param[in] input Input tensor info. Data types supported: QASYMM8/QASYMM8_SIGNED/BFLOAT16/F16/F32. |
| 241 | * @param[in] weights Weights tensor info. Data type supported: QASYMM8/QASYMM8_SIGNED/QSYMM8_PER_CHANNEL/BFLOAT16/F16/F32. |
Georgios Pinitas | 6e1791b | 2019-12-02 19:01:25 +0000 | [diff] [blame] | 242 | * @param[in] biases Biases tensor info. Shared biases supported. Biases are 1D tensor with dimensions [OFM]. |
| 243 | * Data type supported: Should match @p input data type, except for input of QASYMM8/QASYMM8_SIGNED type where biases should be of S32 type. |
| 244 | * @param[in] output Output tensor info. Data types supported: Same as @p input, |
| 245 | * except for input of QASYMM8/QASYMM8_SIGNED type where output should be of S32 type. |
George Wort | 2d7e683 | 2019-02-22 16:37:41 +0000 | [diff] [blame] | 246 | * @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 Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 247 | * @param[in] gemm_3d_depth (Optional) Depth of GEMM 3D (Defaults to 1) |
| 248 | * @param[in] skip_im2col (Optional) Flag which specifies if im2col has to be skipped. i.e. 1x1 convolution with NHWC data layout. (Default to false) |
| 249 | * |
| 250 | * @return a status |
| 251 | */ |
George Wort | 2d7e683 | 2019-02-22 16:37:41 +0000 | [diff] [blame] | 252 | static Status validate_mm(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const ActivationLayerInfo &act_info = ActivationLayerInfo(), |
| 253 | int gemm_3d_depth = 1, bool skip_im2col = false); |
Gian Marco Iodice | db9d46d | 2018-08-08 12:29:38 +0100 | [diff] [blame] | 254 | /** Static function to check if GEMM3D is supported in @ref NEGEMM or in @ref NEGEMMLowpMatrixMultiplyCore |
| 255 | * |
Georgios Pinitas | c7b183a | 2020-03-06 18:12:09 +0000 | [diff] [blame] | 256 | * @param[in] input_info Input tensor info. Data types supported: QASYMM8/QASYMM8_SIGNED/BFLOAT16/F16/F32. |
| 257 | * @param[in] weights_info Weights tensor info. Data types supported: QASYMM8/QASYMM8_SIGNED/BFLOAT16/F16/F32. |
George Wort | 2d7e683 | 2019-02-22 16:37:41 +0000 | [diff] [blame] | 258 | * @param[in] act_info Activation layer information in case of a fused activation. Only RELU, BOUNDED_RELU and LU_BOUNDED_RELU supported. |
Gian Marco Iodice | db9d46d | 2018-08-08 12:29:38 +0100 | [diff] [blame] | 259 | * @param[in] gemm_3d_depth Depth of GEMM 3D |
| 260 | * @param[in] skip_im2col Flag which specifies if im2col has to be skipped. i.e. 1x1 convolution with NHWC data layout |
| 261 | * |
| 262 | * @return a status |
| 263 | */ |
Giorgio Arena | 7a669a8 | 2019-11-13 17:07:13 +0000 | [diff] [blame] | 264 | static Status validate_gemm3d(const ITensorInfo *input_info, const ITensorInfo *weights_info, const ActivationLayerInfo &act_info, int gemm_3d_depth, bool skip_im2col); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 265 | |
| 266 | private: |
Michalis Spyrou | 1a569a3 | 2019-09-10 17:20:34 +0100 | [diff] [blame] | 267 | MemoryGroup _memory_group; |
| 268 | IWeightsManager *_weights_manager; |
| 269 | NEConvolutionLayerReshapeWeights _reshape_weights; |
| 270 | weights_transformations::NEConvolutionLayerReshapeWeightsTransform _reshape_weights_managed; |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 271 | std::unique_ptr<NEIm2ColKernel> _im2col_kernel; |
Michalis Spyrou | 1a569a3 | 2019-09-10 17:20:34 +0100 | [diff] [blame] | 272 | NEGEMM _mm_gemm; |
| 273 | NEGEMMLowpMatrixMultiplyCore _mm_gemmlowp; |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 274 | std::unique_ptr<NECol2ImKernel> _col2im_kernel; |
Michalis Spyrou | 1a569a3 | 2019-09-10 17:20:34 +0100 | [diff] [blame] | 275 | NEReshapeLayer _reshape_layer; |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 276 | |
Georgios Pinitas | 1562be3 | 2018-03-08 19:09:19 +0000 | [diff] [blame] | 277 | const ITensor *_original_weights; |
Georgios Pinitas | 2ee9801 | 2021-02-15 20:42:39 +0000 | [diff] [blame^] | 278 | const ITensor *_original_output; |
Georgios Pinitas | 1562be3 | 2018-03-08 19:09:19 +0000 | [diff] [blame] | 279 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 280 | Tensor _im2col_output; |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 281 | Tensor _weights_reshaped; |
| 282 | Tensor _gemm_output; |
Georgios Pinitas | 2ee9801 | 2021-02-15 20:42:39 +0000 | [diff] [blame^] | 283 | Tensor _gemm_output_3d; |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 284 | Tensor _tmp_output; |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 285 | |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 286 | DataLayout _data_layout; |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 287 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 288 | bool _skip_im2col; |
| 289 | bool _skip_col2im; |
| 290 | bool _is_quantized; |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 291 | bool _is_prepared; |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 292 | }; |
Georgios Pinitas | 041f36d | 2018-09-18 18:38:37 +0100 | [diff] [blame] | 293 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 294 | #endif /* ARM_COMPUTE_NECONVOLUTIONGEMMLAYER_H */ |