blob: 6caa2aeb594f088c7ca1027da3bd84fa12c2cbc6 [file] [log] [blame]
Pablo Tello89519332017-11-17 11:52:36 +00001/*
Matthew Benthamf1aeab92023-05-30 13:35:34 +00002 * Copyright (c) 2017-2023 Arm Limited.
Pablo Tello89519332017-11-17 11:52:36 +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 */
Gunes Bayirc2a51bd2023-09-28 10:30:18 +010024#ifndef ACL_ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NEWINOGRADCONVOLUTIONLAYER_H
25#define ACL_ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NEWINOGRADCONVOLUTIONLAYER_H
Pablo Tello89519332017-11-17 11:52:36 +000026
Pablo Tello89519332017-11-17 11:52:36 +000027#include "arm_compute/core/Types.h"
SiCong Li91295492023-07-21 18:16:13 +010028#include "arm_compute/function_info/ActivationLayerInfo.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010029#include "arm_compute/runtime/IFunction.h"
Pablo Tello89519332017-11-17 11:52:36 +000030#include "arm_compute/runtime/Tensor.h"
31
32#include <memory>
33
34namespace arm_compute
35{
Georgios Pinitas5ce897f2020-04-29 11:44:10 +010036// Forward declarations
Pablo Tello89519332017-11-17 11:52:36 +000037class ITensor;
Georgios Pinitas5ce897f2020-04-29 11:44:10 +010038
Michele Di Giorgio33f41fa2021-03-09 14:09:08 +000039/** Basic function to simulate a convolution layer. This function calls the following kernels:
40 *
Michalis Spyrou96f977e2021-07-01 12:20:56 +010041 * -# @ref cpu::CpuWinogradConv2dTransformInputKernel
42 * -# @ref cpu::CpuWinogradConv2dTransformOutputKernel
Sang-Hoon Park4f7693d2021-05-12 13:59:10 +010043 * -# @ref cpu::CpuGemmAssemblyDispatch
Pablo Tellof6c572c2018-02-14 12:47:30 +000044 * -# @ref CPPPermute (three times: weights, input and output)
Giorgio Arenaa3221e62018-05-03 15:57:48 +010045 *
46 * @note Some Winograd configurations (i.e. F(2x2, 5x5), F(4x4, 5x5)) are supported only with enable_fast_math = true
Pablo Tello89519332017-11-17 11:52:36 +000047 */
Georgios Pinitas9fb11592018-04-26 20:34:58 +010048class NEWinogradConvolutionLayer : public IFunction
Pablo Tello89519332017-11-17 11:52:36 +000049{
50public:
51 /** Constructor */
Michalis Spyroua4f378d2019-04-26 14:54:54 +010052 NEWinogradConvolutionLayer(const std::shared_ptr<IMemoryManager> &memory_manager = nullptr);
Michalis Spyrou96f977e2021-07-01 12:20:56 +010053 /** 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 Tello89519332017-11-17 11:52:36 +000063
64 /** Set the input and output tensors.
65 *
Teresa Charlin62687422021-04-28 10:58:49 +010066 * 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 Arenaa3221e62018-05-03 15:57:48 +010076 * @param[in] input Source tensor. 3 lower dimensions represent a single input [width, height, IFM],
77 * while every optional dimension from 4 and above represent a batch of inputs.
Georgios Pinitas5ce897f2020-04-29 11:44:10 +010078 * Data types supported: F16/F32.
Giorgio Arenaa3221e62018-05-03 15:57:48 +010079 * @param[in] weights Weights tensor. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM]. Data type supported: Same as @p input.
Gunes Bayirc2a51bd2023-09-28 10:30:18 +010080 * Supported kernel sizes: (height, width) -> 3x3, 1x3, 3x1, 5x5, 1x5, 5x1 for Fp32
81 * -> 3x3 for Fp16
Giorgio Arenaa3221e62018-05-03 15:57:48 +010082 * @param[in] biases Biases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM]. Data type supported: Same as @p weights.
83 * @param[out] output Destination tensor. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs.
84 * Data types supported: Same as @p input.
85 * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo. Currently only unit strides are supported.
86 * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
87 * @param[in] enable_fast_math (Optional) Enable fast math computation. In case this flag were set, the function could dispatch the fastest implementation
88 * available which may introduce a drop of accuracy as well. Default is false
Pablo Tello89519332017-11-17 11:52:36 +000089 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010090 void configure(const ITensor *input,
91 const ITensor *weights,
92 const ITensor *biases,
93 ITensor *output,
94 const PadStrideInfo &conv_info,
95 const ActivationLayerInfo &act_info = ActivationLayerInfo(),
96 bool enable_fast_math = false);
Pablo Tello89519332017-11-17 11:52:36 +000097
98 // Inherited methods overridden:
99 void run() override;
Georgios Pinitas72219332018-06-05 14:56:06 +0100100 void prepare() override;
Pablo Tello89519332017-11-17 11:52:36 +0000101
Michele Di Giorgiod7316eb2021-06-16 11:14:41 +0100102 /** Static function to check if given info will lead to a valid configuration of @ref NEWinogradConvolutionLayer
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +0000103 *
Michele Di Giorgiod7316eb2021-06-16 11:14:41 +0100104 * Similar to @ref NEWinogradConvolutionLayer::configure()
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +0000105 *
106 * @return a status
107 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100108 static Status validate(const ITensorInfo *input,
109 const ITensorInfo *weights,
110 const ITensorInfo *biases,
111 const ITensorInfo *output,
112 const PadStrideInfo &conv_info,
113 const ActivationLayerInfo &act_info = ActivationLayerInfo(),
114 bool enable_fast_math = false);
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +0000115
Pablo Tello89519332017-11-17 11:52:36 +0000116private:
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100117 struct Impl;
118 std::unique_ptr<Impl> _impl;
Pablo Tello89519332017-11-17 11:52:36 +0000119};
Georgios Pinitas5ce897f2020-04-29 11:44:10 +0100120} // namespace arm_compute
Gunes Bayirc2a51bd2023-09-28 10:30:18 +0100121#endif // ACL_ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NEWINOGRADCONVOLUTIONLAYER_H