Debian Codegraph @

arm_compute/runtime/NEON/functions/NEDirectConvolutionLayer.h

raw
1 /*
2 * Copyright (c) 2017-2021, 2023-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_NEDIRECTCONVOLUTIONLAYER_H
25 #define ACL_ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NEDIRECTCONVOLUTIONLAYER_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/IMemoryManager.h"
31 #include "arm_compute/runtime/MemoryGroup.h"
32
33 #include <memory>
34
35 namespace arm_compute
36 {
37 class ITensor;
38 class ITensorInfo;
39 /** Function to run the direct convolution.
40 *
41 * This function calls the following:
42 *
43 * -# cpu::CpuDirectConv2d
44 */
45 class NEDirectConvolutionLayer : public IFunction
46 {
47 public:
48 /** Constructor */
49 NEDirectConvolutionLayer(std::shared_ptr<IMemoryManager> memory_manager = nullptr);
50 /** Prevent instances of this class from being copied (As this class contains pointers) */
51 NEDirectConvolutionLayer(const NEDirectConvolutionLayer &) = delete;
52 /** Prevent instances of this class from being copied (As this class contains pointers) */
53 NEDirectConvolutionLayer &operator=(const NEDirectConvolutionLayer &) = delete;
54 /** Prevent instances of this class from being moved (As this class contains non movable objects) */
55 NEDirectConvolutionLayer(NEDirectConvolutionLayer &&) = delete;
56 /** Prevent instances of this class from being moved (As this class contains non movable objects) */
57 NEDirectConvolutionLayer &operator=(NEDirectConvolutionLayer &&) = delete;
58 /** Default destructor */
59 ~NEDirectConvolutionLayer();
60 /** Set the input, weights, biases and output tensors.
61 *
62 * 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 *
72 * @note: DirectConvolution only works in the following configurations:
73 * 1x1 convolution with stride_x = 1/2/3, stride_y = 1/2/3 data type = F16/F32
74 * 3x3 convolution with stride_x = 1/2/3, stride_y = 1/2/3 data type = F16/F32
75 * 5x5 convolution with stride_x = 1/2/3, stride_y = 1/2/3 data type = F32
76 *
77 * @param[in, out] input Input tensor. Data types supported: F16/F32.
78 * @param[in] weights Set of kernels to convolve the input volume.
79 * Supported sizes: 1x1, 3x3 and 5x5.
80 * The 3rd dimension must be the same as the input's volume 3rd dimension.
81 * Data type supported: Same as @p input.
82 * @param[in] bias Set of biases. Can be nullptr. Data type supported: Same as @p input.
83 * @param[out] output Output tensor.
84 * The 3rd dimensions must be equal to the 4th dimension of the @p kernels tensor. Data types supported: Same as @p input.
85 * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo.
86 * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
87 */
88 void configure(ITensor *input,
89 const ITensor *weights,
90 const ITensor *bias,
91 ITensor *output,
92 const PadStrideInfo &conv_info,
93 const ActivationLayerInfo &act_info = ActivationLayerInfo());
94 /** Static function to check if given info will lead to a valid configuration of @ref NEDirectConvolutionLayer
95 *
96 * @note: DirectConvolution only works in the following configurations:
97 * 1x1 convolution with stride_x = 1/2/3, stride_y = 1/2/3 data type = F16/F32
98 * 3x3 convolution with stride_x = 1/2/3, stride_y = 1/2/3 data type = F16/F32
99 * 5x5 convolution with stride_x = 1/2/3, stride_y = 1/2/3 data type = F32
100 *
101 * @param[in] input Input tensor. Data types supported: F16/F32.
102 * @param[in] weights Set of kernels to convolve the input volume.
103 * Supported sizes: 1x1, 3x3 and 5x5.
104 * The 3rd dimension must be the same as the input's volume 3rd dimension.
105 * Data type supported: Same as @p input.
106 * @param[in] bias Set of biases. Can be nullptr. Data type supported: Same as @p input.
107 * @param[in] output Output tensor.
108 * The 3rd dimensions must be equal to the 4th dimension of the @p kernels tensor. Data types supported: Same as @p input.
109 * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo.
110 * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
111 *
112 * @return a status
113 */
114 static Status validate(const ITensorInfo *input,
115 const ITensorInfo *weights,
116 const ITensorInfo *bias,
117 const ITensorInfo *output,
118 const PadStrideInfo &conv_info,
119 const ActivationLayerInfo &act_info = ActivationLayerInfo());
120
121 // Inherited methods overridden:
122 void run() override;
123
124 private:
125 struct Impl;
126 std::shared_ptr<IMemoryManager> _memory_manager;
127 std::unique_ptr<Impl> _impl;
128 };
129 } // namespace arm_compute
130 #endif // ACL_ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NEDIRECTCONVOLUTIONLAYER_H