Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 1 | /* |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame^] | 2 | * Copyright (c) 2017-2022 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 | */ |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_NEWINOGRADCONVOLUTIONLAYER_H |
| 25 | #define ARM_COMPUTE_NEWINOGRADCONVOLUTIONLAYER_H |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 26 | |
| 27 | #include "arm_compute/runtime/IFunction.h" |
| 28 | |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 29 | #include "arm_compute/core/Types.h" |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 30 | #include "arm_compute/runtime/Tensor.h" |
| 31 | |
| 32 | #include <memory> |
| 33 | |
| 34 | namespace arm_compute |
| 35 | { |
Georgios Pinitas | 5ce897f | 2020-04-29 11:44:10 +0100 | [diff] [blame] | 36 | // Forward declarations |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 37 | class ITensor; |
Georgios Pinitas | 5ce897f | 2020-04-29 11:44:10 +0100 | [diff] [blame] | 38 | |
Michele Di Giorgio | 33f41fa | 2021-03-09 14:09:08 +0000 | [diff] [blame] | 39 | /** Basic function to simulate a convolution layer. This function calls the following kernels: |
| 40 | * |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 41 | * -# @ref cpu::CpuWinogradConv2dTransformInputKernel |
| 42 | * -# @ref cpu::CpuWinogradConv2dTransformOutputKernel |
Sang-Hoon Park | 4f7693d | 2021-05-12 13:59:10 +0100 | [diff] [blame] | 43 | * -# @ref cpu::CpuGemmAssemblyDispatch |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 44 | * -# @ref CPPPermute (three times: weights, input and output) |
Giorgio Arena | a3221e6 | 2018-05-03 15:57:48 +0100 | [diff] [blame] | 45 | * |
| 46 | * @note Some Winograd configurations (i.e. F(2x2, 5x5), F(4x4, 5x5)) are supported only with enable_fast_math = true |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 47 | */ |
Georgios Pinitas | 9fb1159 | 2018-04-26 20:34:58 +0100 | [diff] [blame] | 48 | class NEWinogradConvolutionLayer : public IFunction |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 49 | { |
| 50 | public: |
| 51 | /** Constructor */ |
Michalis Spyrou | a4f378d | 2019-04-26 14:54:54 +0100 | [diff] [blame] | 52 | NEWinogradConvolutionLayer(const std::shared_ptr<IMemoryManager> &memory_manager = nullptr); |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 53 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 54 | NEWinogradConvolutionLayer(const NEWinogradConvolutionLayer &) = delete; |
| 55 | /** Default move constructor */ |
| 56 | NEWinogradConvolutionLayer(NEWinogradConvolutionLayer &&) = default; |
| 57 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 58 | NEWinogradConvolutionLayer &operator=(const NEWinogradConvolutionLayer &) = delete; |
| 59 | /** Default move assignment operator */ |
| 60 | NEWinogradConvolutionLayer &operator=(NEWinogradConvolutionLayer &&) = default; |
| 61 | /** Destructor */ |
| 62 | ~NEWinogradConvolutionLayer(); |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 63 | |
| 64 | /** Set the input and output tensors. |
| 65 | * |
Teresa Charlin | 6268742 | 2021-04-28 10:58:49 +0100 | [diff] [blame] | 66 | * Valid data layouts: |
| 67 | * - NHWC |
| 68 | * - NCHW |
| 69 | * |
| 70 | * Valid data type configurations: |
| 71 | * |src0 |src1 |src2 |dst | |
| 72 | * |:--------------|:--------------|:------|:--------------| |
| 73 | * |F16 |F16 |F16 |F16 | |
| 74 | * |F32 |F32 |F32 |F32 | |
| 75 | * |
Giorgio Arena | a3221e6 | 2018-05-03 15:57:48 +0100 | [diff] [blame] | 76 | * @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. |
Georgios Pinitas | 5ce897f | 2020-04-29 11:44:10 +0100 | [diff] [blame] | 78 | * Data types supported: F16/F32. |
Giorgio Arena | a3221e6 | 2018-05-03 15:57:48 +0100 | [diff] [blame] | 79 | * @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 | * Currently only 3x3 and 5x5 kernels are supported. |
| 81 | * @param[in] biases Biases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM]. Data type supported: Same as @p weights. |
| 82 | * @param[out] 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. Currently only unit strides are supported. |
| 85 | * @param[in] act_info (Optional) Activation layer information in case of a fused activation. |
| 86 | * @param[in] enable_fast_math (Optional) Enable fast math computation. In case this flag were set, the function could dispatch the fastest implementation |
| 87 | * available which may introduce a drop of accuracy as well. Default is false |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 88 | */ |
Giorgio Arena | a3221e6 | 2018-05-03 15:57:48 +0100 | [diff] [blame] | 89 | void configure(const ITensor *input, const ITensor *weights, const ITensor *biases, ITensor *output, const PadStrideInfo &conv_info, const ActivationLayerInfo &act_info = ActivationLayerInfo(), |
| 90 | bool enable_fast_math = false); |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 91 | |
| 92 | // Inherited methods overridden: |
| 93 | void run() override; |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 94 | void prepare() override; |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 95 | |
Michele Di Giorgio | d7316eb | 2021-06-16 11:14:41 +0100 | [diff] [blame] | 96 | /** Static function to check if given info will lead to a valid configuration of @ref NEWinogradConvolutionLayer |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 97 | * |
Michele Di Giorgio | d7316eb | 2021-06-16 11:14:41 +0100 | [diff] [blame] | 98 | * Similar to @ref NEWinogradConvolutionLayer::configure() |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 99 | * |
| 100 | * @return a status |
| 101 | */ |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 102 | static Status validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info, |
Giorgio Arena | a3221e6 | 2018-05-03 15:57:48 +0100 | [diff] [blame] | 103 | const ActivationLayerInfo &act_info = ActivationLayerInfo(), bool enable_fast_math = false); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 104 | |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 105 | private: |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 106 | struct Impl; |
| 107 | std::unique_ptr<Impl> _impl; |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 108 | }; |
Georgios Pinitas | 5ce897f | 2020-04-29 11:44:10 +0100 | [diff] [blame] | 109 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 110 | #endif /* ARM_COMPUTE_NEWINOGRADCONVOLUTIONLAYER_H */ |