Debian Codegraph @

arm_compute/runtime/NEON/functions/NEWinogradConvolutionLayer.h

raw
1 /*
2 * Copyright (c) 2017-2024 Arm Limited.
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 */
24 #ifndef ACL_ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NEWINOGRADCONVOLUTIONLAYER_H
25 #define ACL_ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NEWINOGRADCONVOLUTIONLAYER_H
26
27 #include "arm_compute/core/Types.h"
28 #include "arm_compute/function_info/ActivationLayerInfo.h"
29 #include "arm_compute/runtime/IFunction.h"
30 #include "arm_compute/runtime/MemoryManagerOnDemand.h"
31 #include "arm_compute/runtime/Tensor.h"
32
33 #include <memory>
34
35 namespace arm_compute
36 {
37 // Forward declarations
38 class ITensor;
39
40 /** Basic function to simulate a convolution layer. This function calls the following kernels:
41 *
42 * -# cpu::CpuWinogradConv2dTransformInputKernel
43 * -# cpu::CpuWinogradConv2dTransformOutputKernel
44 * -# cpu::CpuGemmAssemblyDispatch
45 * -# @ref CPPPermute (three times: weights, input and output)
46 *
47 * @note Some Winograd configurations (i.e. F(2x2, 5x5), F(4x4, 5x5)) are supported only with enable_fast_math = true
48 */
49 class NEWinogradConvolutionLayer : public IFunction
50 {
51 public:
52 /** Constructor */
53 NEWinogradConvolutionLayer(const std::shared_ptr<IMemoryManager> &memory_manager);
54 NEWinogradConvolutionLayer() : NEWinogradConvolutionLayer(MemoryManagerOnDemand::make_default())
55 {
56 }
57 /** Prevent instances of this class from being copied (As this class contains pointers) */
58 NEWinogradConvolutionLayer(const NEWinogradConvolutionLayer &) = delete;
59 /** Default move constructor */
60 NEWinogradConvolutionLayer(NEWinogradConvolutionLayer &&) = default;
61 /** Prevent instances of this class from being copied (As this class contains pointers) */
62 NEWinogradConvolutionLayer &operator=(const NEWinogradConvolutionLayer &) = delete;
63 /** Default move assignment operator */
64 NEWinogradConvolutionLayer &operator=(NEWinogradConvolutionLayer &&) = default;
65 /** Destructor */
66 ~NEWinogradConvolutionLayer();
67
68 /** Set the input and output tensors.
69 *
70 * Valid data layouts:
71 * - NHWC
72 * - NCHW
73 *
74 * Valid data type configurations:
75 * |src0 |src1 |src2 |dst |
76 * |:--------------|:--------------|:------|:--------------|
77 * |F16 |F16 |F16 |F16 |
78 * |F32 |F32 |F32 |F32 |
79 *
80 * @param[in] input Source tensor. 3 lower dimensions represent a single input [width, height, IFM],
81 * while every optional dimension from 4 and above represent a batch of inputs.
82 * Data types supported: F16/F32.
83 * @param[in] weights Weights tensor. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM]. Data type supported: Same as @p input.
84 * Supported kernel sizes: (height, width) -> 3x3, 1x3, 3x1, 5x5, 1x5, 5x1 for Fp32
85 * -> 3x3 for Fp16
86 * @param[in] biases Biases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM]. Data type supported: Same as @p weights.
87 * @param[out] output Destination tensor. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs.
88 * Data types supported: Same as @p input.
89 * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo. Currently only unit strides are supported.
90 * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
91 * @param[in] enable_fast_math (Optional) Enable fast math computation. In case this flag were set, the function could dispatch the fastest implementation
92 * available which may introduce a drop of accuracy as well. Default is false
93 */
94 void configure(const ITensor *input,
95 const ITensor *weights,
96 const ITensor *biases,
97 ITensor *output,
98 const PadStrideInfo &conv_info,
99 const ActivationLayerInfo &act_info = ActivationLayerInfo(),
100 bool enable_fast_math = false);
101
102 // Inherited methods overridden:
103 void run() override;
104 void prepare() override;
105
106 /** Static function to check if given info will lead to a valid configuration of @ref NEWinogradConvolutionLayer
107 *
108 * Similar to @ref NEWinogradConvolutionLayer::configure()
109 *
110 * @return a status
111 */
112 static Status validate(const ITensorInfo *input,
113 const ITensorInfo *weights,
114 const ITensorInfo *biases,
115 const ITensorInfo *output,
116 const PadStrideInfo &conv_info,
117 const ActivationLayerInfo &act_info = ActivationLayerInfo(),
118 bool enable_fast_math = false);
119
120 private:
121 struct Impl;
122 std::unique_ptr<Impl> _impl;
123 };
124 } // namespace arm_compute
125 #endif // ACL_ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NEWINOGRADCONVOLUTIONLAYER_H