Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 1 | /* |
Pablo Tello | 8f43d74 | 2019-03-27 09:28:32 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2019 ARM Limited. |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +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 | */ |
Georgios Pinitas | 9fb1159 | 2018-04-26 20:34:58 +0100 | [diff] [blame] | 24 | #ifndef __ARM_COMPUTE_NEGEMMWINOGRADCONVOLUTIONLAYERKERNEL_H__ |
| 25 | #define __ARM_COMPUTE_NEGEMMWINOGRADCONVOLUTIONLAYERKERNEL_H__ |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 26 | |
| 27 | #include "arm_compute/core/NEON/INEKernel.h" |
Georgios Pinitas | 4074c99 | 2018-01-30 18:13:46 +0000 | [diff] [blame] | 28 | #include "arm_compute/core/NEON/kernels/convolution/common/convolution.hpp" |
| 29 | #include "arm_compute/core/NEON/kernels/convolution/common/tensor.hpp" |
Pablo Tello | 8f43d74 | 2019-03-27 09:28:32 +0000 | [diff] [blame] | 30 | #include "arm_compute/core/NEON/kernels/convolution/winograd/winograd_layer.hpp" |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 31 | |
| 32 | namespace arm_compute |
| 33 | { |
| 34 | class ITensor; |
Pablo Tello | 02541fb | 2017-12-15 09:48:59 +0000 | [diff] [blame] | 35 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 36 | /** Interface for the NEON kernel to perform Winograd input transform. */ |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 37 | template <typename T> |
| 38 | class INEWinogradLayerTransformInputKernel : public INEKernel |
Pablo Tello | 3d4968a | 2017-12-04 15:03:35 +0000 | [diff] [blame] | 39 | { |
| 40 | public: |
Pablo Tello | 8f43d74 | 2019-03-27 09:28:32 +0000 | [diff] [blame] | 41 | /** Get the working space required to perform the transformation. |
| 42 | * |
| 43 | * Note, the working space is only required when performing the |
| 44 | * transformation - hence it can be reused whenever the transformation is |
| 45 | * not running. |
| 46 | * |
| 47 | * @param num_threads The greatest number of threads that will be used to execute the transform. |
| 48 | * @return Size of working space required in bytes. |
| 49 | */ |
| 50 | virtual unsigned int get_working_space_size(unsigned int num_threads) const = 0; |
| 51 | |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 52 | /** Determine how much memory (in units of TIn) to allocate for the |
| 53 | * transformed input. |
Pablo Tello | 6c6e77a | 2018-01-23 10:03:27 +0000 | [diff] [blame] | 54 | * |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 55 | * @param[in] num_batches Number of batches in the input tensor. |
| 56 | * @param[in] num_channels Number of feature maps in the input tensor. |
| 57 | * @param[in] num_rows Number of rows in each feature map. |
| 58 | * @param[in] num_cols Number of columns in each feature map. |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 59 | * @param[in] same_padding Use "SAME" padding, otherwise use "VALID". |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 60 | * |
| 61 | * @return Storage size (in units of TIn) required. |
Pablo Tello | 6c6e77a | 2018-01-23 10:03:27 +0000 | [diff] [blame] | 62 | */ |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 63 | virtual unsigned int get_input_storage_size(int num_batches, int num_channels, int num_rows, int num_cols, bool same_padding) const = 0; |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 64 | |
| 65 | /** Gets the stride between matrices in the input worspace |
| 66 | * |
Pablo Tello | 5264b7d | 2019-10-21 14:25:41 +0100 | [diff] [blame] | 67 | * @param[in] num_batches Number of batches in the input tensor. |
| 68 | * @param[in] num_channels Number of feature maps in the input tensor. |
| 69 | * @param[in] num_rows Number of rows in each feature map. |
| 70 | * @param[in] num_cols Number of columns in each feature map. |
| 71 | * @param[in] same_padding Use "SAME" padding, otherwise use "VALID". |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 72 | * |
| 73 | * @return Stride expressed in bytes. |
| 74 | */ |
Pablo Tello | 5264b7d | 2019-10-21 14:25:41 +0100 | [diff] [blame] | 75 | virtual int get_matrix_stride(int num_batches, int num_channels, int num_rows, int num_cols, bool same_padding) const = 0; |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 76 | |
| 77 | /** Configure the output transform kernel. |
| 78 | * |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 79 | * @param[in] input_nhwc Input tensor in NHWC data layout format. |
| 80 | * @param[in] num_batches Number of batches in input tensor. |
| 81 | * @param[in] num_rows Number of rows in input tensor. |
| 82 | * @param[in] num_cols Number of columns in input tensor. |
| 83 | * @param[in] num_channels Number of channels in input tensor. |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 84 | * @param[in] padding Padding type. |
| 85 | * @param[out] output Base of output matrices. |
| 86 | * @param[in] matrix_stride Stride between output matrices. |
Pablo Tello | 8f43d74 | 2019-03-27 09:28:32 +0000 | [diff] [blame] | 87 | * @param[in] workspace Tensor to be used as the working space during the computation. |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 88 | */ |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 89 | virtual void configure(const ITensor *input_nhwc, const int num_batches, const int num_rows, const int num_cols, const int num_channels, |
Pablo Tello | 8f43d74 | 2019-03-27 09:28:32 +0000 | [diff] [blame] | 90 | const PaddingType padding, ITensor *output, const int matrix_stride, ITensor *workspace) = 0; |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 91 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 92 | /** Destructor */ |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 93 | virtual ~INEWinogradLayerTransformInputKernel() |
| 94 | { |
| 95 | } |
| 96 | }; |
| 97 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 98 | /** NEON kernel to perform Winograd input transform. */ |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 99 | template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols> |
| 100 | class NEWinogradLayerTransformInputKernel : public INEWinogradLayerTransformInputKernel<T> |
| 101 | { |
| 102 | public: |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 103 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 104 | NEWinogradLayerTransformInputKernel(const NEWinogradLayerTransformInputKernel &) = delete; |
| 105 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 106 | NEWinogradLayerTransformInputKernel &operator=(const NEWinogradLayerTransformInputKernel &) = delete; |
| 107 | /** Allow instances of this class to be moved */ |
| 108 | NEWinogradLayerTransformInputKernel(NEWinogradLayerTransformInputKernel &&) = default; |
| 109 | /** Allow instances of this class to be moved */ |
| 110 | NEWinogradLayerTransformInputKernel &operator=(NEWinogradLayerTransformInputKernel &&) = default; |
| 111 | /** Default destructor */ |
| 112 | ~NEWinogradLayerTransformInputKernel() = default; |
| 113 | |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 114 | /** Determine how much memory (in units of TIn) to allocate for the |
| 115 | * transformed input. |
| 116 | * |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 117 | * @param[in] num_batches Number of batches in the input tensor. |
| 118 | * @param[in] num_channels Number of feature maps in the input tensor. |
| 119 | * @param[in] num_rows Number of rows in each feature map. |
| 120 | * @param[in] num_cols Number of columns in each feature map. |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 121 | * @param[in] same_padding Use "SAME" padding, otherwise use "VALID". |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 122 | * |
| 123 | * @return Storage size (in units of TIn) required. |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 124 | */ |
| 125 | unsigned int get_input_storage_size( |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 126 | int num_batches, |
| 127 | int num_channels, |
| 128 | int num_rows, |
| 129 | int num_cols, |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 130 | bool same_padding) const override; |
| 131 | |
Pablo Tello | 8f43d74 | 2019-03-27 09:28:32 +0000 | [diff] [blame] | 132 | /** Get the working space required to perform the transformation. |
| 133 | * |
| 134 | * Note, the working space is only required when performing the |
| 135 | * transformation - hence it can be reused whenever the transformation is |
| 136 | * not running. |
| 137 | * |
| 138 | * @param[in] num_threads The greatest number of threads that will be used to execute the transform. |
| 139 | * |
| 140 | * @return Size of working space required in bytes. |
| 141 | */ |
| 142 | unsigned int get_working_space_size(unsigned int num_threads) const override; |
| 143 | |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 144 | /** Gets the stride between matrices in the input worspace |
| 145 | * |
Pablo Tello | 5264b7d | 2019-10-21 14:25:41 +0100 | [diff] [blame] | 146 | * @param[in] num_batches Number of batches in the input tensor. |
| 147 | * @param[in] num_channels Number of feature maps in the input tensor. |
| 148 | * @param[in] num_rows Number of rows in each feature map. |
| 149 | * @param[in] num_cols Number of columns in each feature map. |
| 150 | * @param[in] same_padding Use "SAME" padding, otherwise use "VALID". |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 151 | * |
| 152 | * @return Stride expressed in bytes. |
| 153 | */ |
Pablo Tello | 5264b7d | 2019-10-21 14:25:41 +0100 | [diff] [blame] | 154 | int get_matrix_stride( |
| 155 | int num_batches, |
| 156 | int num_channels, |
| 157 | int num_rows, |
| 158 | int num_cols, |
| 159 | bool same_padding) const override; |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 160 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 161 | /** Default constructor */ |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 162 | NEWinogradLayerTransformInputKernel(); |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 163 | |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 164 | const char *name() const override |
| 165 | { |
| 166 | return "NEWinogradLayerTransformInputKernel"; |
| 167 | } |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 168 | |
| 169 | /** Configure the output transform kernel. |
| 170 | * |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 171 | * @param[in] input_nhwc Input tensor. Data types supported: F32. Layout supported NHWC. |
| 172 | * @param[in] num_batches Number of batches in input tensor. |
| 173 | * @param[in] num_rows Number of rows in input tensor. |
| 174 | * @param[in] num_cols Number of columns in input tensor. |
| 175 | * @param[in] num_channels Number of channels in input tensor. |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 176 | * @param[in] padding Padding type. |
| 177 | * @param[out] output Base of output matrices. |
| 178 | * @param[in] matrix_stride Stride between output matrices. |
Pablo Tello | 8f43d74 | 2019-03-27 09:28:32 +0000 | [diff] [blame] | 179 | * @param[in] workspace Tensor to be used as the working space during the computation. |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 180 | */ |
| 181 | void configure( |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 182 | const ITensor *input_nhwc, |
| 183 | const int num_batches, |
| 184 | const int num_rows, |
| 185 | const int num_cols, |
| 186 | const int num_channels, |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 187 | const PaddingType padding, |
Anthony Barbier | e155337 | 2018-07-16 18:53:52 +0100 | [diff] [blame] | 188 | ITensor *output, |
Pablo Tello | 8f43d74 | 2019-03-27 09:28:32 +0000 | [diff] [blame] | 189 | const int matrix_stride, |
| 190 | ITensor *workspace) override; |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 191 | |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 192 | // Inherited methods overridden: |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 193 | void run(const Window &window, const ThreadInfo &info) override; |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 194 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 195 | /** Winograd base kernel */ |
Pablo Tello | 8f43d74 | 2019-03-27 09:28:32 +0000 | [diff] [blame] | 196 | using WinogradBase = winograd::WinogradGEMM<OutputTileRows, OutputTileCols, KernelRows, KernelCols, winograd::WinogradRoots::Integers>; |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 197 | /** Winograd convolution kernel */ |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 198 | using WinogradConv = typename WinogradBase::template Convolution<T, T>; |
| 199 | |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 200 | /** Static function to check if given info will lead to a valid configuration of @ref NEWinogradLayerTransformInputKernel |
| 201 | * |
Vidhya Sudhan Loganathan | 84ce1f9 | 2018-04-25 13:00:09 +0100 | [diff] [blame] | 202 | * @param[in] input First tensor input info. Data types supported: F32. |
| 203 | * @param[in] output Output tensor info. Data types supported: same as @p input. |
| 204 | * @param[in] winograd_info Contains Winograd's information described in @ref WinogradInfo |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 205 | * |
| 206 | * @return a status |
| 207 | */ |
Vidhya Sudhan Loganathan | 84ce1f9 | 2018-04-25 13:00:09 +0100 | [diff] [blame] | 208 | static Status validate(const ITensorInfo *input, const ITensorInfo *output, const WinogradInfo &winograd_info); |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 209 | |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 210 | private: |
Pablo Tello | 8f43d74 | 2019-03-27 09:28:32 +0000 | [diff] [blame] | 211 | using InputTransform = typename WinogradBase::template InputTransform<T, T>; |
| 212 | |
| 213 | std::unique_ptr<InputTransform> _transform{ nullptr }; |
| 214 | const ITensor *_input_nhwc; |
| 215 | int _num_batches; /**< Number of batches in input tensor. */ |
| 216 | int _num_rows; /**< Number of rows in input tensor. */ |
| 217 | int _num_cols; /**< Number of columns in input tensor. */ |
| 218 | int _num_channels; /**< Number of channels in input tensor. */ |
| 219 | PaddingType _padding; /**< Padding type. */ |
| 220 | ITensor *_output; /**< Base of output matrices. */ |
| 221 | int _matrix_stride; /**< Stride between output matrices. */ |
| 222 | int _padding_top; /**< Padding to apply to the top of the image. */ |
| 223 | int _padding_left; /**< Padding to apply to the left of the image. */ |
| 224 | int _padding_right; /**< Padding to apply to the right of the image. */ |
| 225 | int _padding_bottom; /**< Padding to apply to the bottom of the image. */ |
| 226 | ITensor *_workspace; |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 227 | }; |
| 228 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 229 | /** Interface for the NEON kernel to perform Winograd output transform. */ |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 230 | template <typename T> |
| 231 | class INEWinogradLayerTransformOutputKernel : public INEKernel |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 232 | { |
| 233 | public: |
Pablo Tello | 8f43d74 | 2019-03-27 09:28:32 +0000 | [diff] [blame] | 234 | /** Get the working space required to perform the transformation. |
| 235 | * |
| 236 | * Note, the working space is only required when performing the |
| 237 | * transformation - hence it can be reused whenever the transformation is |
| 238 | * not running. |
| 239 | * |
| 240 | * @param[in] num_threads The greatest number of threads that will be used to execute the transform. |
| 241 | * |
| 242 | * @return Size of working space required in bytes. |
| 243 | */ |
| 244 | virtual unsigned int get_working_space_size(unsigned int num_threads) const = 0; |
| 245 | |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 246 | /** Determine how much memory (in units of TOut) to allocate for the |
| 247 | * (Winograd domain) output. |
| 248 | * |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 249 | * @param[in] num_batches Number of batches in the output tensor. |
| 250 | * @param[in] num_rows Number of rows in each feature map of the input tensor. |
| 251 | * @param[in] num_cols Number of columns in each feature map of the input tensor. |
| 252 | * @param[in] num_output_channels Number of feature maps in the output tensor. |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 253 | * |
| 254 | * @return Storage size (in units of TOut) required. |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 255 | */ |
Pablo Tello | 5264b7d | 2019-10-21 14:25:41 +0100 | [diff] [blame] | 256 | virtual unsigned int get_output_storage_size(int num_batches, int num_rows, int num_cols, int num_output_channels) const = 0; |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 257 | |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 258 | /** Gets the stride between matrices in the output worspace |
| 259 | * |
Pablo Tello | 5264b7d | 2019-10-21 14:25:41 +0100 | [diff] [blame] | 260 | * @param[in] num_batches Number of batches in the output tensor. |
| 261 | * @param[in] num_rows Number of rows in each feature map of the input tensor. |
| 262 | * @param[in] num_cols Number of columns in each feature map of the input tensor. |
| 263 | * @param[in] num_output_channels Number of feature maps in the output tensor. |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 264 | * |
| 265 | * @return Stride expressed in bytes. |
| 266 | */ |
Pablo Tello | 5264b7d | 2019-10-21 14:25:41 +0100 | [diff] [blame] | 267 | virtual int get_matrix_stride(int num_batches, int num_rows, int num_cols, int num_output_channels) const = 0; |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 268 | |
| 269 | /** Get the output shape of a convolution. |
| 270 | * |
Pablo Tello | 5264b7d | 2019-10-21 14:25:41 +0100 | [diff] [blame] | 271 | * @param[in] num_rows Number of rows in each feature map of the input tensor. |
| 272 | * @param[in] num_cols Number of columns in each feature map of the input tensor. |
| 273 | * @param[in] padding_same True if padding is SAME, false otherwise |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 274 | * |
Pablo Tello | 5264b7d | 2019-10-21 14:25:41 +0100 | [diff] [blame] | 275 | * @return Shape of the output tensor |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 276 | */ |
Pablo Tello | 5264b7d | 2019-10-21 14:25:41 +0100 | [diff] [blame] | 277 | virtual std::pair<unsigned int, unsigned int> get_output_shape( |
| 278 | int num_rows, /* Number of rows in each feature map of the input tensor. */ |
| 279 | int num_cols, /* Number of columns in each feature map of the input tensor. */ |
| 280 | bool padding_same /* True if padding is SAME, false otherwise */ |
| 281 | ) const = 0; |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 282 | |
| 283 | /** Configure the output transform kernel. |
| 284 | * |
Pablo Tello | 8f43d74 | 2019-03-27 09:28:32 +0000 | [diff] [blame] | 285 | * @param[in] biases Pointer to the biases tensor. |
| 286 | * @param[in] transformed_output Pointer to working space for the output tensor in the Winograd domain. |
| 287 | * @param[in] matrix_stride Output matrix stride, can be computed with winograd::WinogradGEMM<2, 2, 3, 3>::Convolution<float, float>::get_output_matrix_stride() |
| 288 | * @param[out] output_nhwc Pointer to a tensor in NHWC data layout ordered output tensor, in the spatial domain. |
| 289 | * @param[in] num_batches Number of batches in the input tensor. |
| 290 | * @param[in] num_rows Number of rows in output tensor. |
| 291 | * @param[in] num_cols Number of columns in output tensor. |
| 292 | * @param[in] num_channels Number of feature maps in the output tensor. |
| 293 | * @param[in] workspace Tensor to be used as the working space during the computation. |
Pablo Tello | 5264b7d | 2019-10-21 14:25:41 +0100 | [diff] [blame] | 294 | * @param[in] activation Activation to be used |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 295 | */ |
| 296 | virtual void configure( |
Pablo Tello | 5264b7d | 2019-10-21 14:25:41 +0100 | [diff] [blame] | 297 | const ITensor *biases, |
| 298 | const ITensor *transformed_output, |
| 299 | const int matrix_stride, |
| 300 | ITensor *output_nhwc, |
| 301 | const int num_batches, |
| 302 | const int num_rows, |
| 303 | const int num_cols, |
| 304 | const int num_channels, |
| 305 | ITensor *workspace, |
| 306 | const arm_gemm::Activation &activation) = 0; |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 307 | |
| 308 | virtual ~INEWinogradLayerTransformOutputKernel() |
| 309 | { |
| 310 | } |
| 311 | }; |
| 312 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 313 | /** NEON kernel to perform Winograd output transform. */ |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 314 | template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols> |
| 315 | class NEWinogradLayerTransformOutputKernel : public INEWinogradLayerTransformOutputKernel<T> |
| 316 | { |
| 317 | public: |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 318 | const char *name() const override |
| 319 | { |
| 320 | return "NEWinogradLayerTransformOutputKernel"; |
| 321 | } |
| 322 | /** Constructor */ |
| 323 | NEWinogradLayerTransformOutputKernel(); |
| 324 | |
| 325 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 326 | NEWinogradLayerTransformOutputKernel(const NEWinogradLayerTransformOutputKernel &) = delete; |
| 327 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 328 | NEWinogradLayerTransformOutputKernel &operator=(const NEWinogradLayerTransformOutputKernel &) = delete; |
| 329 | /** Allow instances of this class to be moved */ |
| 330 | NEWinogradLayerTransformOutputKernel(NEWinogradLayerTransformOutputKernel &&) = default; |
| 331 | /** Allow instances of this class to be moved */ |
| 332 | NEWinogradLayerTransformOutputKernel &operator=(NEWinogradLayerTransformOutputKernel &&) = default; |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 333 | /** Default destructor */ |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 334 | ~NEWinogradLayerTransformOutputKernel() = default; |
| 335 | |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 336 | // Inherited methods overridden: |
| 337 | /** Determine how much memory (in units of TOut) to allocate for the |
| 338 | * (Winograd domain) output. |
| 339 | * |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 340 | * @param[in] num_batches Number of batches in the output tensor. |
| 341 | * @param[in] num_rows Number of rows in each feature map of the input tensor. |
| 342 | * @param[in] num_cols Number of columns in each feature map of the input tensor. |
| 343 | * @param[in] num_output_channels Number of feature maps in the output tensor. |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 344 | * |
| 345 | * @return Storage size (in units of TOut) required. |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 346 | */ |
Pablo Tello | 5264b7d | 2019-10-21 14:25:41 +0100 | [diff] [blame] | 347 | unsigned int get_output_storage_size(int num_batches, int num_rows, int num_cols, int num_output_channels) const override; |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 348 | |
| 349 | /** Gets the stride between matrices in the output worspace |
| 350 | * |
Pablo Tello | 5264b7d | 2019-10-21 14:25:41 +0100 | [diff] [blame] | 351 | * @param[in] num_batches Number of batches in the output tensor. |
| 352 | * @param[in] num_rows Number of rows in each feature map of the input tensor. |
| 353 | * @param[in] num_cols Number of columns in each feature map of the input tensor. |
| 354 | * @param[in] num_output_channels Number of feature maps in the output tensor. |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 355 | * |
| 356 | * @return Stride expressed in bytes. |
| 357 | */ |
Pablo Tello | 5264b7d | 2019-10-21 14:25:41 +0100 | [diff] [blame] | 358 | int get_matrix_stride(int num_batches, int num_rows, int num_cols, int num_output_channels) const override; |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 359 | /** Get the output shape of a convolution. |
| 360 | * |
Pablo Tello | 5264b7d | 2019-10-21 14:25:41 +0100 | [diff] [blame] | 361 | * @param[in] num_rows Number of rows in each feature map of the input tensor. |
| 362 | * @param[in] num_cols Number of columns in each feature map of the input tensor. |
| 363 | * @param[in] padding_same True if padding is SAME, false otherwise |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 364 | * |
Pablo Tello | 5264b7d | 2019-10-21 14:25:41 +0100 | [diff] [blame] | 365 | * @return Shape of the output tensor |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 366 | */ |
Pablo Tello | 5264b7d | 2019-10-21 14:25:41 +0100 | [diff] [blame] | 367 | std::pair<unsigned int, unsigned int> get_output_shape( |
| 368 | int num_rows, /* Number of rows in each feature map of the input tensor. */ |
| 369 | int num_cols, /* Number of columns in each feature map of the input tensor. */ |
| 370 | bool padding_same) const override; |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 371 | |
Pablo Tello | 8f43d74 | 2019-03-27 09:28:32 +0000 | [diff] [blame] | 372 | /** Get the working space required to perform the transformation. |
| 373 | * |
| 374 | * Note, the working space is only required when performing the |
| 375 | * transformation - hence it can be reused whenever the transformation is |
| 376 | * not running. |
| 377 | * |
| 378 | * @param[in] num_threads The greatest number of threads that will be used to execute the transform. |
| 379 | * |
| 380 | * @return Size of working space required in bytes. |
| 381 | */ |
| 382 | unsigned int get_working_space_size(unsigned int num_threads) const override; |
| 383 | |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 384 | /** Configure the output transform kernel. |
| 385 | * |
Pablo Tello | 8f43d74 | 2019-03-27 09:28:32 +0000 | [diff] [blame] | 386 | * @param[in] biases Pointer to the biases tensor. |
| 387 | * @param[in] transformed_output Pointer to working space for the output tensor in the Winograd domain. |
| 388 | * @param[in] matrix_stride Output matrix stride, can be computed with winograd::WinogradGEMM<2, 2, 3, 3>::Convolution<float, float>::get_output_matrix_stride() |
| 389 | * @param[out] output_nhwc Pointer to a tensor with NHWC data layout, in the spatial domain. |
| 390 | * @param[in] num_batches Number of batches in the input tensor. |
| 391 | * @param[in] num_rows Number of rows in output tensor. |
| 392 | * @param[in] num_cols Number of columns in output tensor. |
| 393 | * @param[in] num_channels Number of feature maps in the output tensor. |
| 394 | * @param[in] workspace Tensor to be used as the working space during the computation. |
Pablo Tello | 5264b7d | 2019-10-21 14:25:41 +0100 | [diff] [blame] | 395 | * @param[in] activation Activation to be used |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 396 | */ |
| 397 | void configure( |
Pablo Tello | 5264b7d | 2019-10-21 14:25:41 +0100 | [diff] [blame] | 398 | const ITensor *biases, |
| 399 | const ITensor *transformed_output, |
| 400 | const int matrix_stride, |
| 401 | ITensor *output_nhwc, |
| 402 | const int num_batches, |
| 403 | const int num_rows, |
| 404 | const int num_cols, |
| 405 | const int num_channels, |
| 406 | ITensor *workspace, |
| 407 | const arm_gemm::Activation &activation) override; |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 408 | |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 409 | void run(const Window &window, const ThreadInfo &info) override; |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 410 | |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 411 | /** Static function to check if given info will lead to a valid configuration of @ref NEWinogradLayerTransformOutputKernel |
| 412 | * |
Pablo Tello | 8f43d74 | 2019-03-27 09:28:32 +0000 | [diff] [blame] | 413 | * @param[in] input Source tensor info with shape [C, N, 16, batches] or [C, N, 36, batches]. Data types supported: F32. |
| 414 | * @param[in] bias Biases tensor info. Shared biases supported. Biases are 1D tensor with dimensions [OFM]. It can be a nullptr. Data type supported: as @p input |
| 415 | * @param[in] output Destination tensor info with shape [output_convolved_dims.width, output_convolved_dims.height, C, batches]. Data type supported: same as @p input |
| 416 | * @param[in] winograd_info Contains Winograd's information described in @ref WinogradInfo |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 417 | * |
| 418 | * @return a status |
| 419 | */ |
Vidhya Sudhan Loganathan | 84ce1f9 | 2018-04-25 13:00:09 +0100 | [diff] [blame] | 420 | static Status validate(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const WinogradInfo &winograd_info); |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 421 | |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 422 | private: |
Pablo Tello | 8f43d74 | 2019-03-27 09:28:32 +0000 | [diff] [blame] | 423 | using WinogradBase = winograd::WinogradGEMM<OutputTileRows, OutputTileCols, KernelRows, KernelCols, winograd::WinogradRoots::Integers>; |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 424 | using WinogradConv = typename WinogradBase::template Convolution<T, T>; |
Pablo Tello | 8f43d74 | 2019-03-27 09:28:32 +0000 | [diff] [blame] | 425 | using OutputTransform = typename WinogradBase::template OutputTransform<T, T>; |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 426 | |
Pablo Tello | 8f43d74 | 2019-03-27 09:28:32 +0000 | [diff] [blame] | 427 | std::unique_ptr<OutputTransform> _transform{ nullptr }; |
| 428 | const ITensor *_biases; |
| 429 | const ITensor *_transformed_output; |
| 430 | ITensor *_workspace; |
| 431 | int _matrix_stride; |
| 432 | int _matrix_row_stride; |
| 433 | ITensor *_output_nhwc; |
| 434 | int _num_batches; |
| 435 | int _num_rows; |
| 436 | int _num_cols; |
| 437 | int _num_channels; |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 438 | }; |
| 439 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 440 | /** Interface for the NEON kernel to perform Winograd weights transform. */ |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 441 | template <typename T> |
| 442 | class INEWinogradLayerTransformWeightsKernel : public INEKernel |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 443 | { |
| 444 | public: |
Pablo Tello | bda6e4b | 2018-08-22 11:40:33 +0100 | [diff] [blame] | 445 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 446 | INEWinogradLayerTransformWeightsKernel(const INEWinogradLayerTransformWeightsKernel &) = default; |
| 447 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 448 | INEWinogradLayerTransformWeightsKernel &operator=(const INEWinogradLayerTransformWeightsKernel &) = default; |
| 449 | /** Allow instances of this class to be moved */ |
| 450 | INEWinogradLayerTransformWeightsKernel(INEWinogradLayerTransformWeightsKernel &&) = default; |
| 451 | /** Allow instances of this class to be moved */ |
| 452 | INEWinogradLayerTransformWeightsKernel &operator=(INEWinogradLayerTransformWeightsKernel &&) = default; |
| 453 | |
| 454 | INEWinogradLayerTransformWeightsKernel() |
| 455 | { |
| 456 | } |
| 457 | virtual ~INEWinogradLayerTransformWeightsKernel() |
| 458 | { |
| 459 | } |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 460 | /** Determine how much memory (in units of T) to allocate for the |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 461 | * transformed weights. |
| 462 | * |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 463 | * @param[in] num_output_channels Number of output feature maps. |
| 464 | * @param[in] num_input_channels Number of input feature maps. |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 465 | * |
| 466 | * @return Storage size (in units of T) required. |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 467 | */ |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 468 | virtual unsigned int get_weight_storage_size(int num_output_channels, int num_input_channels) const = 0; |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 469 | /** Gets the stride between matrices in the kernel worspace |
| 470 | * |
Pablo Tello | 5264b7d | 2019-10-21 14:25:41 +0100 | [diff] [blame] | 471 | * @param[in] num_output_channels Number of output feature maps. |
| 472 | * @param[in] num_input_channels Number of input feature maps. |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 473 | * |
| 474 | * @return Stride expressed in bytes. |
| 475 | */ |
Pablo Tello | 5264b7d | 2019-10-21 14:25:41 +0100 | [diff] [blame] | 476 | virtual int get_matrix_stride(int num_output_channels, int num_input_channels) const = 0; |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 477 | |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 478 | /** Configure the weights transform kernel. |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 479 | * |
Anthony Barbier | e155337 | 2018-07-16 18:53:52 +0100 | [diff] [blame] | 480 | * @param[in] weights_hwio Pointer to the weights tensor |
| 481 | * @param[out] output Pointer to working space for the output tensor in the Winograd domain. |
| 482 | * @param[in] matrix_stride Stride across matrices in the output workspace. |
| 483 | * @param[in] num_output_channels Number of filters. |
| 484 | * @param[in] num_input_channels Number of channels in each filter. |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 485 | */ |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 486 | |
Anthony Barbier | e155337 | 2018-07-16 18:53:52 +0100 | [diff] [blame] | 487 | virtual void configure(const ITensor *weights_hwio, ITensor *output, const int matrix_stride, const int num_output_channels, const int num_input_channels) = 0; |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 488 | |
Pablo Tello | bda6e4b | 2018-08-22 11:40:33 +0100 | [diff] [blame] | 489 | /** Static function to check if given info will lead to a valid configuration of @ref NEWinogradLayerTransformWeightsKernel |
| 490 | * |
| 491 | * @param[in] input First tensor input info. Data types supported: F32. |
| 492 | * @param[in] weights Weights tensor info. Data types supported: same as @p input. |
| 493 | * |
| 494 | * @return a status |
| 495 | */ |
| 496 | static Status validate(const ITensorInfo *input, const ITensorInfo *weights); |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 497 | }; |
| 498 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 499 | /** NEON kernel to perform Winograd weights transform. */ |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 500 | template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols> |
| 501 | class NEWinogradLayerTransformWeightsKernel final : public INEWinogradLayerTransformWeightsKernel<T> |
| 502 | { |
| 503 | public: |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 504 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 505 | NEWinogradLayerTransformWeightsKernel(const NEWinogradLayerTransformWeightsKernel &) = delete; |
| 506 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 507 | NEWinogradLayerTransformWeightsKernel &operator=(const NEWinogradLayerTransformWeightsKernel &) = delete; |
| 508 | /** Allow instances of this class to be moved */ |
| 509 | NEWinogradLayerTransformWeightsKernel(NEWinogradLayerTransformWeightsKernel &&) = default; |
| 510 | /** Allow instances of this class to be moved */ |
| 511 | NEWinogradLayerTransformWeightsKernel &operator=(NEWinogradLayerTransformWeightsKernel &&) = default; |
| 512 | /** Default destructor */ |
| 513 | ~NEWinogradLayerTransformWeightsKernel() = default; |
| 514 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 515 | /** Default constructor. */ |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 516 | NEWinogradLayerTransformWeightsKernel(); |
| 517 | const char *name() const override |
| 518 | { |
| 519 | return "NEWinogradLayerTransformWeightsKernel"; |
| 520 | } |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 521 | |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 522 | /** Static function to check if given info will lead to a valid configuration of @ref NEWinogradLayerTransformWeightsKernel |
| 523 | * |
Vidhya Sudhan Loganathan | 84ce1f9 | 2018-04-25 13:00:09 +0100 | [diff] [blame] | 524 | * @param[in] input Source tensor info. The input is a 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM] (NCHW data layout). |
| 525 | * kernel_x must be 3 and equal to kernel_y. Data types supported: F32. |
| 526 | * @param[in] output Destination tensor info. The output is a 3D tensor with dimensions [OFM, IFM, 16] or [OFM, IFM, 36]. Data type supported: same as @p input |
| 527 | * @param[in] winograd_info Contains Winograd's information described in @ref WinogradInfo |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 528 | * |
| 529 | * @return a status |
| 530 | */ |
Vidhya Sudhan Loganathan | 84ce1f9 | 2018-04-25 13:00:09 +0100 | [diff] [blame] | 531 | static Status validate(const ITensorInfo *input, const ITensorInfo *output, const WinogradInfo &winograd_info); |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 532 | |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 533 | // Inherited methods overridden: |
Vidhya Sudhan Loganathan | d646ae1 | 2018-11-19 15:18:20 +0000 | [diff] [blame] | 534 | |
| 535 | #ifndef DOXYGEN_SKIP_THIS |
| 536 | /** Configure the weights transform kernel. |
| 537 | * |
| 538 | * @param[in] weights_hwio Pointer to the weights tensor |
| 539 | * @param[out] output Pointer to working space for the output tensor in the Winograd domain. |
| 540 | * @param[in] matrix_stride Stride across matrices in the output workspace. |
| 541 | * @param[in] num_output_channels Number of filters. |
| 542 | * @param[in] num_input_channels Number of channels in each filter. |
| 543 | */ |
Anthony Barbier | e155337 | 2018-07-16 18:53:52 +0100 | [diff] [blame] | 544 | void configure(const ITensor *weights_hwio, ITensor *output, const int matrix_stride, const int num_output_channels, const int num_input_channels) override; |
Vidhya Sudhan Loganathan | d646ae1 | 2018-11-19 15:18:20 +0000 | [diff] [blame] | 545 | #endif /* DOXYGEN_SKIP_THIS */ |
| 546 | |
| 547 | /** Determine how much memory (in units of T) to allocate for the |
| 548 | * transformed weights. |
| 549 | * |
| 550 | * @param[in] num_output_channels Number of output feature maps. |
| 551 | * @param[in] num_input_channels Number of input feature maps. |
| 552 | * |
| 553 | * @return Storage size (in units of T) required. |
| 554 | */ |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 555 | unsigned int get_weight_storage_size(int num_output_channels, int num_input_channels) const override; |
Vidhya Sudhan Loganathan | d646ae1 | 2018-11-19 15:18:20 +0000 | [diff] [blame] | 556 | |
| 557 | /** Gets the stride between matrices in the input worspace |
| 558 | * |
Pablo Tello | 5264b7d | 2019-10-21 14:25:41 +0100 | [diff] [blame] | 559 | * @param[in] num_output_channels Number of output feature maps. |
| 560 | * @param[in] num_input_channels Number of input feature maps. |
Vidhya Sudhan Loganathan | d646ae1 | 2018-11-19 15:18:20 +0000 | [diff] [blame] | 561 | * |
| 562 | * @return Stride expressed in bytes. |
| 563 | */ |
Pablo Tello | 5264b7d | 2019-10-21 14:25:41 +0100 | [diff] [blame] | 564 | int get_matrix_stride(int num_output_channels, int num_input_channels) const override; |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 565 | void run(const Window &window, const ThreadInfo &info) override; |
| 566 | bool is_parallelisable() const override; |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 567 | |
| 568 | private: |
Pablo Tello | 8f43d74 | 2019-03-27 09:28:32 +0000 | [diff] [blame] | 569 | using WinogradBase = winograd::WinogradGEMM<OutputTileRows, OutputTileCols, KernelRows, KernelCols, winograd::WinogradRoots::Integers>; |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 570 | using WinogradConv = typename WinogradBase::template Convolution<T, T>; |
Pablo Tello | 8f43d74 | 2019-03-27 09:28:32 +0000 | [diff] [blame] | 571 | using WeightsTransform = typename WinogradBase::template WeightsTransform<T, T>; |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 572 | |
Pablo Tello | 8f43d74 | 2019-03-27 09:28:32 +0000 | [diff] [blame] | 573 | std::unique_ptr<WeightsTransform> _transform{ nullptr }; |
| 574 | const ITensor *_weights_hwio; |
| 575 | ITensor *_output; |
| 576 | int _matrix_stride; |
| 577 | int _num_output_channels; |
| 578 | int _num_input_channels; |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 579 | }; |
| 580 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 581 | /** NEON kernel to perform Winograd. */ |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 582 | template <typename TIn, typename TOut, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols> |
Anthony Barbier | e155337 | 2018-07-16 18:53:52 +0100 | [diff] [blame] | 583 | class NEWinogradLayerConfiguration |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 584 | { |
| 585 | public: |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 586 | /** Winograd base kernel */ |
Pablo Tello | 8f43d74 | 2019-03-27 09:28:32 +0000 | [diff] [blame] | 587 | using WinogradBase = winograd::WinogradGEMM<OutputTileRows, OutputTileCols, KernelRows, KernelCols, winograd::WinogradRoots::Integers>; |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 588 | /** Winograd convolution kernel */ |
Anthony Barbier | e155337 | 2018-07-16 18:53:52 +0100 | [diff] [blame] | 589 | |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 590 | using WinogradConv = typename WinogradBase::template Convolution<TIn, TOut>; |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 591 | |
Anthony Barbier | e155337 | 2018-07-16 18:53:52 +0100 | [diff] [blame] | 592 | using TransformInputKernel = NEWinogradLayerTransformInputKernel<TIn, OutputTileRows, OutputTileCols, KernelRows, KernelCols>; |
| 593 | using TransformWeightsKernel = NEWinogradLayerTransformWeightsKernel<TIn, OutputTileRows, OutputTileCols, KernelRows, KernelCols>; |
| 594 | using TransformOutputKernel = NEWinogradLayerTransformOutputKernel<TOut, OutputTileRows, OutputTileCols, KernelRows, KernelCols>; |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 595 | }; |
| 596 | |
| 597 | } // namespace arm_compute |
Georgios Pinitas | 9fb1159 | 2018-04-26 20:34:58 +0100 | [diff] [blame] | 598 | #endif /*__ARM_COMPUTE_NEGEMMWINOGRADCONVOLUTIONLAYERKERNEL_H__*/ |