blob: 47db75c37efafbf4c6fad2cb1cf1382afda54316 [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 SRC_CPU_OPERATORS_CPUADDMULADD
25#define SRC_CPU_OPERATORS_CPUADDMULADD
26
27#include "arm_compute/core/TensorInfo.h"
28
29#include "src/cpu/ICpuOperator.h"
30#include "src/cpu/operators/CpuDequantize.h"
31
32namespace arm_compute
33{
34namespace cpu
35{
36/** Basic function to run @ref kernels::CpuAddMulAddKernel */
37class CpuAddMulAdd : public ICpuOperator
38{
39public:
40 /** Initialize the operator's inputs and outputs.
41 *
42 * Similar to @ref NEAddMulAdd::configure()
43 *
44 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010045 void configure(const ITensorInfo *input1,
46 const ITensorInfo *input2,
47 const ITensorInfo *bn_mul,
48 const ITensorInfo *bn_add,
49 ITensorInfo *add_output,
50 ITensorInfo *final_output,
51 ConvertPolicy policy,
52 const ActivationLayerInfo &act_info);
Gunes Bayirae72a462023-01-29 13:24:24 +000053 /** Static function to check if given info will lead to a valid configuration
54 *
55 * Similar to @ref CpuAddMulAdd::configure()
56 *
57 * @return a status
58 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010059 static Status validate(const ITensorInfo *input1,
60 const ITensorInfo *input2,
61 const ITensorInfo *bn_mul,
62 const ITensorInfo *bn_add,
63 const ITensorInfo *add_output,
64 const ITensorInfo *final_output,
65 ConvertPolicy policy,
66 const ActivationLayerInfo &act_info);
Gunes Bayirae72a462023-01-29 13:24:24 +000067
68 // Inherited methods overridden:
69 void run(ITensorPack &tensors) override;
70
71 // We need auxilary memory to dequantize batchnorm coefficients
72 experimental::MemoryRequirements workspace() const override;
73
74private:
75 enum AuxTensorIdx
76 {
77 DequantizedBnMul = 0,
78 DequantizedBnAdd,
79 Count
80 };
81
82 CpuDequantize _dequantize_bn_mul{};
83 CpuDequantize _dequantize_bn_add{};
84
85 TensorInfo _dequantized_bn_mul{};
86 TensorInfo _dequantized_bn_add{};
87
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010088 experimental::MemoryRequirements _aux_mem{Count};
Gunes Bayirae72a462023-01-29 13:24:24 +000089};
90} // namespace cpu
91} // namespace arm_compute
92#endif /* SRC_CPU_OPERATORS_CPUADDMULADD */