Debian Codegraph @

arm_compute/runtime/experimental/operators/CpuWinogradConv2d.h

raw
1 /*
2 * Copyright (c) 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_EXPERIMENTAL_OPERATORS_CPUWINOGRADCONV2D_H
25 #define ACL_ARM_COMPUTE_RUNTIME_EXPERIMENTAL_OPERATORS_CPUWINOGRADCONV2D_H
26
27 #include "arm_compute/core/ITensorInfo.h"
28 #include "arm_compute/runtime/IOperator.h"
29
30 #include <memory>
31
32 namespace arm_compute
33 {
34 namespace experimental
35 {
36 namespace op
37 {
38 /*
39 * A shallow wrapper for arm_compute::cpu::CpuWinogradConv2d.
40 * Any new features should be added to arm_compute::cpu::CpuWinogradConv2d and
41 * arm_compute::experimental::op::CpuWinogradConv2d should remain a shallow wrapper.
42 */
43 class CpuWinogradConv2d : public IOperator
44 {
45 public:
46 /** Constructors */
47 CpuWinogradConv2d();
48 /** Prevent instances of this class from being copied (As this class contains pointers) */
49 CpuWinogradConv2d(const CpuWinogradConv2d &) = delete;
50 /** Prevent instances of this class from being copied (As this class contains pointers) */
51 CpuWinogradConv2d &operator=(const CpuWinogradConv2d &) = delete;
52 /** Default move constructor */
53 CpuWinogradConv2d(CpuWinogradConv2d &&) = default;
54 /** Default move assignment */
55 CpuWinogradConv2d &operator=(CpuWinogradConv2d &&) = default;
56
57 /** Destructor */
58 ~CpuWinogradConv2d() override;
59
60 /** Set the input 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 * @param[in] src Source tensor Info. 3 lower dimensions represent a single input [width, height, IFM],
73 * while every optional dimension from 4 and above represent a batch of inputs.
74 * Data types supported: F16/F32.
75 * @param[in] weights Weights tensor Info. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM]. Data type supported: Same as @p input.
76 * For supported kernel sizes, see @ref arm_compute::NEWinogradConvolutionLayer
77 * @param[in] biases Biases tensor Info. Shared biases supported. Biases are 1D tensor with dimensions [OFM]. Data type supported: Same as @p weights.
78 * @param[out] dst Destination tensor Info. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs.
79 * Data types supported: Same as @p input.
80 * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo. Currently only unit strides are supported.
81 * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
82 * @param[in] enable_fast_math (Optional) Enable fast math computation. In case this flag were set, the function could dispatch the fastest implementation
83 * available which may introduce a drop of accuracy as well. Default is false
84 */
85 void configure(const ITensorInfo *src,
86 const ITensorInfo *weights,
87 const ITensorInfo *biases,
88 ITensorInfo *dst,
89 const PadStrideInfo &conv_info,
90 const ActivationLayerInfo &act_info = ActivationLayerInfo(),
91 bool enable_fast_math = false);
92 /** Static function to check if given info will lead to a valid configuration of @ref CpuWinogradConv2d
93 *
94 * Similar to CpuWinogradConv2d::configure()
95 *
96 * @return a status
97 */
98 static Status validate(const ITensorInfo *src,
99 const ITensorInfo *weights,
100 const ITensorInfo *biases,
101 const ITensorInfo *dst,
102 const PadStrideInfo &conv_info,
103 const ActivationLayerInfo &act_info = ActivationLayerInfo(),
104 bool enable_fast_math = false);
105
106 void run(ITensorPack &tensors) override;
107 void prepare(ITensorPack &constants) override;
108 experimental::MemoryRequirements workspace() const override;
109
110 private:
111 struct Impl;
112 std::unique_ptr<Impl> _impl;
113 };
114 } // namespace op
115 } // namespace experimental
116 } // namespace arm_compute
117
118 #endif // ACL_ARM_COMPUTE_RUNTIME_EXPERIMENTAL_OPERATORS_CPUWINOGRADCONV2D_H