Debian Codegraph @

arm_compute/runtime/NEON/functions/NEGEMMConv2d.h

raw
1 /*
2 * Copyright (c) 2020-2021, 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_NEGEMMCONV2D_H
25 #define ACL_ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NEGEMMCONV2D_H
26
27 #include "arm_compute/runtime/FunctionDescriptors.h"
28 #include "arm_compute/runtime/IFunction.h"
29 #include "arm_compute/runtime/IMemoryManager.h"
30 #include "arm_compute/runtime/MemoryManagerOnDemand.h"
31
32 #include <memory>
33
34 namespace arm_compute
35 {
36 // Forward declarations
37 class ITensor;
38 class ITensorInfo;
39
40 /** Basic function to compute the convolution layer. This function calls the following kernels/functions:
41 *
42 * Supports only NHWC data layout
43 *
44 * -# cpu::CpuGemmAssemblyDispatch
45 * -# @ref NEActivationLayer, in case activation cannot be fused in the assembly dispatch
46 *
47 * Weights are transformed from OHWI to HWIO format using the following kernels:
48 * -# @ref NEPermute
49 */
50 class NEGEMMConv2d : public IFunction
51 {
52 public:
53 /** Constructor */
54 NEGEMMConv2d(const std::shared_ptr<IMemoryManager> &memory_manager);
55 NEGEMMConv2d() : NEGEMMConv2d(MemoryManagerOnDemand::make_default())
56 {
57 }
58 /** Prevent instances of this class from being copied (As this class contains pointers) */
59 NEGEMMConv2d(const NEGEMMConv2d &) = delete;
60 /** Default move constructor */
61 NEGEMMConv2d(NEGEMMConv2d &&) = default;
62 /** Prevent instances of this class from being copied (As this class contains pointers) */
63 NEGEMMConv2d &operator=(const NEGEMMConv2d &) = delete;
64 /** Default move assignment operator */
65 NEGEMMConv2d &operator=(NEGEMMConv2d &&) = default;
66 /** Destructor */
67 ~NEGEMMConv2d();
68 /** Set the input and output tensors.
69 *
70 * Valid data layouts:
71 * - All
72 *
73 * Valid data type configurations:
74 * |src0 |src1 |src2 |dst |
75 * |:--------------|:--------------|:--------------|:--------------|
76 * |QASYMM8 |QASYMM8 |S32 |QASYMM8 |
77 * |QASYMM8_SIGNED |QASYMM8_SIGNED |S32 |QASYMM8_SIGNED |
78 * |F16 |F16 |F16 |F16 |
79 * |F32 |F32 |F32 |F32 |
80 * |BFLOAT16 |BFLOAT16 |BFLOAT16 |BFLOAT16 |
81 *
82 * @param[in] input Source tensor. 3 lower dimensions represent a single input [width, height, IFM],
83 * while every optional dimension from 4 and above represent a batch of inputs.
84 * Data types supported: QASYMM8/QASYMM8_SIGNED/BFLOAT16/F16/F32.
85 * @param[in] weights Weights tensor. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM].
86 * Data type supported: QASYMM8/QASYMM8_SIGNED/QSYMM8_PER_CHANNEL/BFLOAT16/F16/F32.
87 * @param[in] biases Biases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM].
88 * Data type supported: Should match @p input data type, except for input of QASYMM8/QASYMM8_SIGNED type where biases should be of S32 type.
89 * @param[out] output Destination tensor. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs.
90 * Data types supported: Same as @p input.
91 * @param[in] info Convolution layer descriptor
92 */
93 void
94 configure(ITensor *input, const ITensor *weights, const ITensor *biases, ITensor *output, const Conv2dInfo &info);
95 /** Static function to check if given info will lead to a valid configuration of @ref NEGEMMConv2d
96 *
97 * @param[in] input Source tensor info. 3 lower dimensions represent a single input [width, height, IFM],
98 * while every optional dimension from 4 and above represent a batch of inputs.
99 * Data types supported: QASYMM8/QASYMM8_SIGNED/BFLOAT16/F16/F32.
100 * @param[in] weights Weights tensor info. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM].
101 * Data type supported: QASYMM8/QASYMM8_SIGNED/QSYMM8_PER_CHANNEL/BFLOAT16/F16/F32.
102 * @param[in] biases Biases tensor info. Shared biases supported. Biases are 1D tensor with dimensions [OFM].
103 * Data type supported: Should match @p input data type, except for input of QASYMM8/QASYMM8_SIGNED type where biases should be of S32 type.
104 * @param[in] output Destination tensor info. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs.
105 * Data types supported: Same as @p input.
106 * @param[in] info Contains padding and stride information described in @ref PadStrideInfo.
107 *
108 * @return a status
109 */
110 static Status validate(const ITensorInfo *input,
111 const ITensorInfo *weights,
112 const ITensorInfo *biases,
113 const ITensorInfo *output,
114 const Conv2dInfo &info);
115
116 // Inherited methods overridden:
117 void run() override;
118 void prepare() override;
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_NEGEMMCONV2D_H