Debian Codegraph @

arm_compute/runtime/NEON/functions/NEAddMulAdd.h

raw
1 /*
2 * Copyright (c) 2023 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 ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NEADDMULADD
25 #define ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NEADDMULADD
26
27 #include "arm_compute/core/Types.h"
28 #include "arm_compute/runtime/IFunction.h"
29 #include "arm_compute/runtime/IMemoryManager.h"
30
31 #include <memory>
32
33 namespace arm_compute
34 {
35 class ITensor;
36 class ITensorInfo;
37 class ActivationLayerInfo;
38
39 /** Function to compute Add+Mul+Add fused operation */
40 class NEAddMulAdd : public IFunction
41 {
42 public:
43 /** Constructor */
44 NEAddMulAdd(std::shared_ptr<IMemoryManager> memory_manager = nullptr);
45 /** Prevent instances of this class from being copied (As this class contains pointers) */
46 NEAddMulAdd(const NEAddMulAdd &) = delete;
47 /** Prevent instances of this class from being moved (As this class contains non movable objects) */
48 NEAddMulAdd(NEAddMulAdd &&) = delete;
49 /** Prevent instances of this class from being copied (As this class contains pointers) */
50 NEAddMulAdd &operator=(const NEAddMulAdd &) = delete;
51 /** Prevent instances of this class from being moved (As this class contains non movable objects) */
52 NEAddMulAdd &operator=(NEAddMulAdd &&) = delete;
53 /** Destructor */
54 ~NEAddMulAdd();
55 /** Initialize the function's inputs and outputs.
56 *
57 * Valid data layouts:
58 * - Any
59 *
60 * Valid data type configurations:
61 * |input1 |input2 |bn_mul |bn_add |add_output |final_output |
62 * |:--------------|:--------------|:--------------|:--------------|:--------------|:--------------|
63 * |QASYMM8 |QASYMM8 |QASYMM8 |QASYMM8 |QASYMM8 |QASYMM8 |
64 * |QASYMM8_SIGNED |QASYMM8_SIGNED |QASYMM8_SIGNED |QASYMM8_SIGNED |QASYMM8_SIGNED |QASYMM8_SIGNED |
65 * |F16 |F16 |F16 |F16 |F16 |F16 |
66 * |F32 |F32 |F32 |F32 |F32 |F32 |
67 *
68 * This is what this composite function (tailored for add followed by a batch norm operation) does:
69 * add_output <- input1 + input2 (add)
70 * final_output <- add_output * bn_mul + bn_add (batch norm = mul+add)
71 *
72 * @param[in] input1 First tensor input. Data type supported: QASYMM8/QASYMM8_SIGNED/F16/F32.
73 * @param[in] input2 Second tensor input. Data types supported: Same as @p input.
74 * @param[in] bn_mul The multiplication coefficient on the feature dimension. Data types supported: Same as @p input.
75 * It's one dimensional tensor with size equal to the feature maps [FM]
76 * @param[in] bn_add The addition coefficient on the feature dimension. Data types supported: Same as @p input.
77 * It's one dimensional tensor with size equal to the feature maps [FM]
78 * @param[out] add_output Output of the first add. Data type supported: Same as @p input.
79 * @param[out] final_output Output of the add+mul+add+act composite operation. Data type supported: Same as @p input.
80 * @param[in] policy Policy to handle overflow
81 * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
82 *
83 */
84 void configure(ITensor *input1,
85 ITensor *input2,
86 ITensor *bn_mul,
87 ITensor *bn_add,
88 ITensor *add_output,
89 ITensor *final_output,
90 ConvertPolicy policy,
91 const ActivationLayerInfo &act_info);
92 /** Static function to check if given info will lead to a valid configuration of @ref NEAddMulAdd
93 *
94 * Similar to @ref NEAddMulAdd::configure() except the arguments are @ref ITensorInfo * instead of @ref ITensor *
95 *
96 * @return a status
97 */
98 static Status validate(const ITensorInfo *input1,
99 const ITensorInfo *input2,
100 const ITensorInfo *bn_mul,
101 const ITensorInfo *bn_add,
102 const ITensorInfo *add_output,
103 const ITensorInfo *final_output,
104 ConvertPolicy policy,
105 const ActivationLayerInfo &act_info);
106
107 // Inherited methods overridden:
108 void run() override;
109
110 private:
111 struct Impl;
112 std::unique_ptr<Impl> _impl;
113 };
114 } // namespace arm_compute
115 #endif /* ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NEADDMULADD */