Debian Codegraph @

arm_compute/runtime/experimental/operators/CpuDepthwiseConv2d.h

raw
1 /*
2 * Copyright (c) 2017-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
25 #ifndef ACL_ARM_COMPUTE_RUNTIME_EXPERIMENTAL_OPERATORS_CPUDEPTHWISECONV2D_H
26 #define ACL_ARM_COMPUTE_RUNTIME_EXPERIMENTAL_OPERATORS_CPUDEPTHWISECONV2D_H
27
28 #include "arm_compute/core/ITensorPack.h"
29 #include "arm_compute/core/TensorInfo.h"
30 #include "arm_compute/runtime/FunctionDescriptors.h"
31 #include "arm_compute/runtime/IOperator.h"
32
33 namespace arm_compute
34 {
35 namespace experimental
36 {
37 namespace op
38 {
39 /*
40 * A shallow wrapper for arm_compute::cpu::CpuDepthwiseConv2d.
41 * Any new features should be added to arm_compute::cpu::CpuDepthwiseConv2d and
42 * arm_compute::experimental::op::CpuDepthwiseConv2d should remain a shallow wrapper.
43 */
44 class CpuDepthwiseConv2d : public IOperator
45 {
46 public:
47 /** Constructor **/
48 CpuDepthwiseConv2d();
49 /** Prevent instances of this class from being copied (As this class contains pointers) */
50 CpuDepthwiseConv2d(const CpuDepthwiseConv2d &) = delete;
51 /** Prevent copy assignment */
52 CpuDepthwiseConv2d &operator=(const CpuDepthwiseConv2d &) = delete;
53 /** Default move constructor */
54 CpuDepthwiseConv2d(CpuDepthwiseConv2d &&) = default;
55 /** Default move assignment */
56 CpuDepthwiseConv2d &operator=(CpuDepthwiseConv2d &&) = default;
57 /** Default destructor */
58 ~CpuDepthwiseConv2d() override;
59
60 /** Initialize the function's source, destination, weights and convolution information.
61 *
62 * Valid data layouts:
63 * - NHWC
64 *
65 * Valid data type configurations:
66 * |src0 |src1 |src2 |dst |
67 * |:--------------|:------------------|:------|:--------------|
68 * |F16 |F16 |F16 |F16 |
69 * |F32 |F32 |F32 |F32 |
70 * |QASYMM8 |QASYMM8 |S32 |QASYMM8 |
71 * |QASYMM8 |QSYMM8_PER_CHANNEL |S32 |QASYMM8 |
72 * |QASYMM8_SIGNED |QASYMM8_SIGNED |S32 |QASYMM8_SIGNED |
73 * |QASYMM8_SIGNED |QSYMM8_PER_CHANNEL |S32 |QASYMM8_SIGNED |
74 *
75 * @param[in, out] input Source tensor. Data type supported: QASYMM8/QASYMM8_SIGNED/F16/F32
76 * @param[in] weights Weights tensor. These are 3D tensors with shape [kernel_x, kernel_y, IFM].
77 * Data type supported: Same as @p input or QASYMM8/QASYMM8_SIGNED/QSYMM8_PER_CHANNEL when @p input is QASYMM8/QASYMM8_SIGNED.
78 * @param[in] biases Biases tensor. A 1D tensor with shape [IFM]. Must be nullptr if not needed.
79 * Data type supported: Same as @p input, S32 when input is QASYMM8/QASYMM8_SIGNED.
80 * @param[out] output Destination tensor. Data type supported: same as @p input.
81 * @param[in] conv_info Padding and stride information to use for the convolution.
82 * @param[in] depth_multiplier (Optional) Multiplier to apply to the input's depth in order to retrieve the output's depth. Defaults to 1.
83 * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
84 * @param[in] dilation (Optional) Dilation, in elements, across x and y. Defaults to (1, 1).
85 */
86 void configure(ITensorInfo *input,
87 const ITensorInfo *weights,
88 const ITensorInfo *biases,
89 ITensorInfo *output,
90 const PadStrideInfo &conv_info,
91 unsigned int depth_multiplier = 1,
92 const ActivationLayerInfo &act_info = ActivationLayerInfo(),
93 const Size2D &dilation = Size2D(1, 1));
94
95 /** Static function to check if given info will lead to a valid configuration for @ref CpuDepthwiseConv2d::configure()
96 *
97 * Similar to @ref CpuDepthwiseConv2d::configure()
98 *
99 * @return a status
100 */
101 static Status validate(const ITensorInfo *input,
102 const ITensorInfo *weights,
103 const ITensorInfo *biases,
104 const ITensorInfo *output,
105 const PadStrideInfo &conv_info,
106 unsigned int depth_multiplier = 1,
107 const ActivationLayerInfo &act_info = ActivationLayerInfo(),
108 const Size2D &dilation = Size2D(1U, 1U));
109
110 // Inherited methods overridden:
111 void run(ITensorPack &tensors) override;
112 void prepare(ITensorPack &constants) override;
113 experimental::MemoryRequirements workspace() const override;
114
115 private:
116 struct Impl;
117 std::unique_ptr<Impl> _impl;
118 };
119 } // namespace op
120 } // namespace experimental
121 } // namespace arm_compute
122
123 #endif // ACL_ARM_COMPUTE_RUNTIME_EXPERIMENTAL_OPERATORS_CPUDEPTHWISECONV2D_H