blob: c5e31ec291bb651f3c052eaddbd511efdf3c1afe [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
25#ifndef SRC_CPU_KERNELS_CPUADDMULADDKERNEL
26#define SRC_CPU_KERNELS_CPUADDMULADDKERNEL
27
SiCong Li91295492023-07-21 18:16:13 +010028#include "arm_compute/function_info/ActivationLayerInfo.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010029
Gunes Bayirae72a462023-01-29 13:24:24 +000030#include "src/core/common/Macros.h"
31#include "src/cpu/ICpuKernel.h"
32
33namespace arm_compute
34{
35namespace cpu
36{
37namespace kernels
38{
39/** Interface for the kernel to perform addition between two tensors */
40class CpuAddMulAddKernel : public ICpuKernel<CpuAddMulAddKernel>
41{
42private:
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010043 using AddMulAddKernelPtr = std::add_pointer<void(const ITensor *,
44 const ITensor *,
45 const ITensor *,
46 const ITensor *,
47 ITensor *,
48 ITensor *,
49 ConvertPolicy,
50 const ActivationLayerInfo &,
51 const Window &)>::type;
Gunes Bayirae72a462023-01-29 13:24:24 +000052
53public:
54 struct AddMulAddKernel
55 {
56 const char *name;
57 const DataTypeISASelectorPtr is_selected;
58 AddMulAddKernelPtr ukernel;
59 };
60
61 CpuAddMulAddKernel() = default;
62 ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE(CpuAddMulAddKernel);
63 /** Initialize the kernel's inputs and outputs.
64 *
65 * Similar to @ref NEAddMulAdd::configure()
66 *
67 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010068 void configure(const ITensorInfo *input1,
69 const ITensorInfo *input2,
70 const ITensorInfo *bn_mul,
71 const ITensorInfo *bn_add,
72 ITensorInfo *add_output,
73 ITensorInfo *final_output,
74 ConvertPolicy policy,
75 const ActivationLayerInfo &act_info);
Gunes Bayirae72a462023-01-29 13:24:24 +000076 /** Static function to check if given info will lead to a valid configuration
77 *
78 * Similar to CpuAddMulAddKernel::configure()
79 *
80 * @return a status
81 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010082 static Status validate(const ITensorInfo *input1,
83 const ITensorInfo *input2,
84 const ITensorInfo *bn_mul,
85 const ITensorInfo *bn_add,
86 const ITensorInfo *add_output,
87 const ITensorInfo *final_output,
88 ConvertPolicy policy,
89 const ActivationLayerInfo &act_info);
Gunes Bayirae72a462023-01-29 13:24:24 +000090
91 // Inherited methods overridden:
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010092 void run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) override;
Gunes Bayirae72a462023-01-29 13:24:24 +000093 const char *name() const override;
94
95 static const std::vector<AddMulAddKernel> &get_available_kernels();
96
97private:
98 ConvertPolicy _policy{};
99 ActivationLayerInfo _act_info{};
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100100 AddMulAddKernelPtr _run_method{nullptr};
Gunes Bayirae72a462023-01-29 13:24:24 +0000101 std::string _name{};
102};
103} // namespace kernels
104} // namespace cpu
105} // namespace arm_compute
106#endif /* SRC_CPU_KERNELS_CPUADDMULADDKERNEL */