blob: e5e85542f8526ba45058c25c7874ef862f85399f [file] [log] [blame]
Gunes Bayirae72a462023-01-29 13:24:24 +00001/*
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
33namespace arm_compute
34{
35class ITensor;
36class ITensorInfo;
Matthew Benthamf1aeab92023-05-30 13:35:34 +000037class ActivationLayerInfo;
Gunes Bayirae72a462023-01-29 13:24:24 +000038
39/** Function to compute Add+Mul+Add fused operation */
40class NEAddMulAdd : public IFunction
41{
42public:
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, ITensor *input2, ITensor *bn_mul, ITensor *bn_add,
85 ITensor *add_output, ITensor *final_output,
86 ConvertPolicy policy, const ActivationLayerInfo &act_info);
87 /** Static function to check if given info will lead to a valid configuration of @ref NEAddMulAdd
88 *
89 * Similar to @ref NEAddMulAdd::configure() except the arguments are @ref ITensorInfo * instead of @ref ITensor *
90 *
91 * @return a status
92 */
93 static Status validate(const ITensorInfo *input1, const ITensorInfo *input2,
94 const ITensorInfo *bn_mul, const ITensorInfo *bn_add,
95 const ITensorInfo *add_output, const ITensorInfo *final_output,
96 ConvertPolicy policy, const ActivationLayerInfo &act_info);
97
98 // Inherited methods overridden:
99 void run() override;
100
101private:
102 struct Impl;
103 std::unique_ptr<Impl> _impl;
104};
105} // namespace arm_compute
106#endif /* ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NEADDMULADD */