blob: 7ac59c900cc1e2f12d8e721a8f0ba89f0a9c6b72 [file] [log] [blame]
Gian Marco Iodiced2fab732018-03-02 11:18:12 +00001/*
giuros013bfacb22019-04-01 12:07:02 +01002 * Copyright (c) 2018-2019 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
27#include "arm_compute/core/CL/kernels/CLWinogradFilterTransformKernel.h"
28#include "arm_compute/core/CL/kernels/CLWinogradOutputTransformKernel.h"
29#include "arm_compute/core/Types.h"
30#include "arm_compute/runtime/CL/functions/CLGEMM.h"
31#include "arm_compute/runtime/CL/functions/CLWinogradInputTransform.h"
32#include "arm_compute/runtime/IFunction.h"
33
34namespace arm_compute
35{
36class ICLTensor;
37
38/** Basic function to execute Winograd-based convolution on OpenCL. This function calls the following OpenCL functions/kernels:
39 *
40 * -# @ref CLWinogradInputTransform
41 * -# @ref CLWinogradFilterTransformKernel (only once)
42 * -# @ref CLGEMM
43 * -# @ref CLWinogradOutputTransformKernel
44 *
45 */
46class CLWinogradConvolutionLayer : public IFunction
47{
48public:
49 /** Default constructor */
50 CLWinogradConvolutionLayer(std::shared_ptr<IMemoryManager> memory_manager = nullptr);
Georgios Pinitase0437672018-05-02 14:07:55 +010051 /** Prevent instances of this class from being copied (As this class contains pointers) */
52 CLWinogradConvolutionLayer(const CLWinogradConvolutionLayer &) = delete;
53 /** Default move constructor */
54 CLWinogradConvolutionLayer(CLWinogradConvolutionLayer &&) = default;
55 /** Prevent instances of this class from being copied (As this class contains pointers) */
56 CLWinogradConvolutionLayer &operator=(const CLWinogradConvolutionLayer &) = delete;
57 /** Default move assignment operator */
58 CLWinogradConvolutionLayer &operator=(CLWinogradConvolutionLayer &&) = default;
Gian Marco Iodiced2fab732018-03-02 11:18:12 +000059 /** Set the input and output tensors.
60 *
giuros013bfacb22019-04-01 12:07:02 +010061 * @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 +010062 * @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 +000063 *
Gian Marco Iodice2213d4b2018-04-27 10:39:06 +010064 * @param[in] input Source tensor. 3 lower dimensions represent a single input [width, height, IFM],
65 * while every optional dimension from 4 and above represent a batch of inputs.
Vidhya Sudhan Loganathan71ecf392018-08-31 16:10:16 +010066 * Data types supported: F16/F32.
Gian Marco Iodice2213d4b2018-04-27 10:39:06 +010067 * @param[in] weights Weights tensor. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM]. Data type supported:Same as @p input.
68 * @param[in] biases Biases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM].Data type supported: Same as @p input
69 * @param[out] output Destination tensor. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs.
70 * Data types supported: Same as @p input.
71 * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo.
72 * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
73 * @param[in] enable_fast_math (Optional) Enable fast math computation. In case this flag were set, the function could dispatch the fastest implementation
74 * available which may introduce a drop of accuracy as well. Default is false
Gian Marco Iodiced2fab732018-03-02 11:18:12 +000075 */
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000076 void configure(ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output, const PadStrideInfo &conv_info,
Gian Marco Iodice2213d4b2018-04-27 10:39:06 +010077 const ActivationLayerInfo &act_info = ActivationLayerInfo(), bool enable_fast_math = false);
Gian Marco Iodiced2fab732018-03-02 11:18:12 +000078 /** Static function to check if given info will lead to a valid configuration of @ref CLWinogradConvolutionLayer
79 *
Gian Marco Iodiced28b7512018-07-06 12:59:28 +010080 * @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 +010081 * @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 +000082 *
Gian Marco Iodice2213d4b2018-04-27 10:39:06 +010083 * @param[in] input Source tensor. 3 lower dimensions represent a single input [width, height, IFM],
84 * while every optional dimension from 4 and above represent a batch of inputs.
Vidhya Sudhan Loganathan71ecf392018-08-31 16:10:16 +010085 * Data types supported: F16/F32.
Gian Marco Iodice2213d4b2018-04-27 10:39:06 +010086 * @param[in] weights Weights tensor. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM]. Data type supported:Same as @p input.
87 * @param[in] biases Biases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM].Data type supported: Same as @p input
88 * @param[out] output Destination tensor. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs.
89 * Data types supported: Same as @p input.
90 * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo.
91 * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
92 * @param[in] enable_fast_math (Optional) Enable fast math computation. In case this flag were set, the function could dispatch the fastest implementation
93 * available which may introduce a drop of accuracy as well. Default is false
Gian Marco Iodiced2fab732018-03-02 11:18:12 +000094 *
95 * @return a status
96 */
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000097 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 +010098 const ActivationLayerInfo &act_info = ActivationLayerInfo(), bool enable_fast_math = false);
Gian Marco Iodiced2fab732018-03-02 11:18:12 +000099
100 // Inherited methods overridden:
101 void run() override;
Georgios Pinitase0437672018-05-02 14:07:55 +0100102 void prepare() override;
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000103
104private:
Georgios Pinitas26014cf2019-09-09 19:00:57 +0100105 MemoryGroup _memory_group;
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000106 CLGEMM _batched_mm;
107 CLWinogradInputTransform _input_transform;
108 CLWinogradFilterTransformKernel _filter_transform;
109 CLWinogradOutputTransformKernel _output_transform;
110 CLTensor _input0;
111 CLTensor _input1;
112 CLTensor _batched_mm_output;
Georgios Pinitase0437672018-05-02 14:07:55 +0100113 const ICLTensor *_original_weights;
114 bool _is_prepared;
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000115};
Manuel Bottini0d0028c2018-10-02 16:41:52 +0100116} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000117#endif /* ARM_COMPUTE_CLWINOGRADCONVOLUTIONLAYER_H */