blob: 74ffe46690d5d8acb6d4fe585a0155661eced096 [file] [log] [blame]
Gian Marco Iodiced2fab732018-03-02 11:18:12 +00001/*
Matthew Benthamf1aeab92023-05-30 13:35:34 +00002 * Copyright (c) 2018-2021, 2023 Arm Limited.
Gian Marco Iodiced2fab732018-03-02 11:18:12 +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_CLWINOGRADCONVOLUTIONLAYER_H
25#define ARM_COMPUTE_CLWINOGRADCONVOLUTIONLAYER_H
Gian Marco Iodiced2fab732018-03-02 11:18:12 +000026
Matthew Benthamf1aeab92023-05-30 13:35:34 +000027#include "arm_compute/core/ActivationLayerInfo.h"
Gian Marco Iodiced2fab732018-03-02 11:18:12 +000028#include "arm_compute/core/Types.h"
Gian Marco Iodiced2fab732018-03-02 11:18:12 +000029#include "arm_compute/runtime/IFunction.h"
Manuel Bottinic6f4ec32021-05-18 18:41:56 +010030#include "arm_compute/runtime/IMemoryManager.h"
31
32#include <memory>
Gian Marco Iodiced2fab732018-03-02 11:18:12 +000033
34namespace arm_compute
35{
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +010036class CLCompileContext;
Gian Marco Iodiced2fab732018-03-02 11:18:12 +000037class ICLTensor;
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +010038class ITensorInfo;
Gian Marco Iodiced2fab732018-03-02 11:18:12 +000039
40/** Basic function to execute Winograd-based convolution on OpenCL. This function calls the following OpenCL functions/kernels:
41 *
Manuel Bottinic6f4ec32021-05-18 18:41:56 +010042 * -# @ref opencl::ClWinogradConv2d
Gian Marco Iodiced2fab732018-03-02 11:18:12 +000043 *
44 */
45class CLWinogradConvolutionLayer : public IFunction
46{
47public:
Manuel Bottinic6f4ec32021-05-18 18:41:56 +010048 /** Default Constructor */
Gian Marco Iodiced2fab732018-03-02 11:18:12 +000049 CLWinogradConvolutionLayer(std::shared_ptr<IMemoryManager> memory_manager = nullptr);
Manuel Bottinic6f4ec32021-05-18 18:41:56 +010050 /** Default Destructor */
51 ~CLWinogradConvolutionLayer();
Georgios Pinitase0437672018-05-02 14:07:55 +010052 /** Prevent instances of this class from being copied (As this class contains pointers) */
53 CLWinogradConvolutionLayer(const CLWinogradConvolutionLayer &) = delete;
54 /** Default move constructor */
55 CLWinogradConvolutionLayer(CLWinogradConvolutionLayer &&) = default;
56 /** Prevent instances of this class from being copied (As this class contains pointers) */
57 CLWinogradConvolutionLayer &operator=(const CLWinogradConvolutionLayer &) = delete;
58 /** Default move assignment operator */
59 CLWinogradConvolutionLayer &operator=(CLWinogradConvolutionLayer &&) = default;
Gian Marco Iodiced2fab732018-03-02 11:18:12 +000060 /** Set the input and output tensors.
61 *
Teresa Charlin62687422021-04-28 10:58:49 +010062 * Valid data layouts:
63 * - NHWC
64 * - NCHW
65 *
66 * Valid data type configurations:
67 * |src0 |src1 |src2 |dst |
68 * |:--------------|:--------------|:------|:--------------|
69 * |F16 |F16 |F16 |F16 |
70 * |F32 |F32 |F32 |F32 |
71 *
giuros013bfacb22019-04-01 12:07:02 +010072 * @note: This function only works with 3x3,3x1,1x3,5x5,5x1,1x5,7x1 and 1x7 kernels along with unit strides for both NCHW and NHWC data layout
Gian Marco Iodice876be2a2018-07-03 12:22:09 +010073 * @note Some Winograd configurations (i.e. F(4x4, 5x5)) are supported only with enable_fast_math = true
Gian Marco Iodiced2fab732018-03-02 11:18:12 +000074 *
Gian Marco Iodice2213d4b2018-04-27 10:39:06 +010075 * @param[in] input Source tensor. 3 lower dimensions represent a single input [width, height, IFM],
76 * while every optional dimension from 4 and above represent a batch of inputs.
Vidhya Sudhan Loganathan71ecf392018-08-31 16:10:16 +010077 * Data types supported: F16/F32.
Gian Marco Iodice2213d4b2018-04-27 10:39:06 +010078 * @param[in] weights Weights tensor. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM]. Data type supported:Same as @p input.
79 * @param[in] biases Biases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM].Data type supported: Same as @p input
80 * @param[out] output Destination tensor. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs.
81 * Data types supported: Same as @p input.
82 * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo.
83 * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
84 * @param[in] enable_fast_math (Optional) Enable fast math computation. In case this flag were set, the function could dispatch the fastest implementation
85 * available which may introduce a drop of accuracy as well. Default is false
Gian Marco Iodiced2fab732018-03-02 11:18:12 +000086 */
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000087 void configure(ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output, const PadStrideInfo &conv_info,
Gian Marco Iodice2213d4b2018-04-27 10:39:06 +010088 const ActivationLayerInfo &act_info = ActivationLayerInfo(), bool enable_fast_math = false);
Manuel Bottini2b84be52020-04-08 10:15:51 +010089 /** Set the input and output tensors.
90 *
91 * @note: This function only works with 3x3,3x1,1x3,5x5,5x1,1x5,7x1 and 1x7 kernels along with unit strides for both NCHW and NHWC data layout
92 * @note Some Winograd configurations (i.e. F(4x4, 5x5)) are supported only with enable_fast_math = true
93 *
94 * @param[in] compile_context The compile context to be used.
95 * @param[in] input Source tensor. 3 lower dimensions represent a single input [width, height, IFM],
96 * while every optional dimension from 4 and above represent a batch of inputs.
97 * Data types supported: F16/F32.
98 * @param[in] weights Weights tensor. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM]. Data type supported:Same as @p input.
99 * @param[in] biases Biases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM].Data type supported: Same as @p input
100 * @param[out] output Destination tensor. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs.
101 * Data types supported: Same as @p input.
102 * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo.
103 * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
104 * @param[in] enable_fast_math (Optional) Enable fast math computation. In case this flag were set, the function could dispatch the fastest implementation
105 * available which may introduce a drop of accuracy as well. Default is false
106 */
107 void configure(const CLCompileContext &compile_context, ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output, const PadStrideInfo &conv_info,
108 const ActivationLayerInfo &act_info = ActivationLayerInfo(), bool enable_fast_math = false);
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000109 /** Static function to check if given info will lead to a valid configuration of @ref CLWinogradConvolutionLayer
110 *
Gian Marco Iodiced28b7512018-07-06 12:59:28 +0100111 * @note: This function only works with 3x3,3x1,1x3,5x5,5x1 and 1x5 kernels along with unit strides for both NCHW and NHWC data layout
Gian Marco Iodice876be2a2018-07-03 12:22:09 +0100112 * @note Some Winograd configurations (i.e. F(4x4, 5x5)) are supported only with enable_fast_math = true
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000113 *
Gian Marco Iodice2213d4b2018-04-27 10:39:06 +0100114 * @param[in] input Source tensor. 3 lower dimensions represent a single input [width, height, IFM],
115 * while every optional dimension from 4 and above represent a batch of inputs.
Vidhya Sudhan Loganathan71ecf392018-08-31 16:10:16 +0100116 * Data types supported: F16/F32.
Gian Marco Iodice2213d4b2018-04-27 10:39:06 +0100117 * @param[in] weights Weights tensor. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM]. Data type supported:Same as @p input.
118 * @param[in] biases Biases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM].Data type supported: Same as @p input
119 * @param[out] output Destination tensor. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs.
120 * Data types supported: Same as @p input.
121 * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo.
122 * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
123 * @param[in] enable_fast_math (Optional) Enable fast math computation. In case this flag were set, the function could dispatch the fastest implementation
124 * available which may introduce a drop of accuracy as well. Default is false
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000125 *
126 * @return a status
127 */
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000128 static Status validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info,
Gian Marco Iodice2213d4b2018-04-27 10:39:06 +0100129 const ActivationLayerInfo &act_info = ActivationLayerInfo(), bool enable_fast_math = false);
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000130
131 // Inherited methods overridden:
132 void run() override;
Georgios Pinitase0437672018-05-02 14:07:55 +0100133 void prepare() override;
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000134
135private:
Manuel Bottinic6f4ec32021-05-18 18:41:56 +0100136 struct Impl;
137 std::unique_ptr<Impl> _impl;
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000138};
Manuel Bottini0d0028c2018-10-02 16:41:52 +0100139} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000140#endif /* ARM_COMPUTE_CLWINOGRADCONVOLUTIONLAYER_H */