blob: 67ce6f029afef00aac5d8fa36f299d9d8de1ab6a [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"
Gunes Bayirae72a462023-01-29 13:24:24 +000029#include "src/core/common/Macros.h"
30#include "src/cpu/ICpuKernel.h"
31
32namespace arm_compute
33{
34namespace cpu
35{
36namespace kernels
37{
38/** Interface for the kernel to perform addition between two tensors */
39class CpuAddMulAddKernel : public ICpuKernel<CpuAddMulAddKernel>
40{
41private:
42 using AddMulAddKernelPtr =
43 std::add_pointer<void(const ITensor *, const ITensor *, const ITensor *, const ITensor *, ITensor *, ITensor *, ConvertPolicy, const ActivationLayerInfo &, const Window &)>::type;
44
45public:
46 struct AddMulAddKernel
47 {
48 const char *name;
49 const DataTypeISASelectorPtr is_selected;
50 AddMulAddKernelPtr ukernel;
51 };
52
53 CpuAddMulAddKernel() = default;
54 ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE(CpuAddMulAddKernel);
55 /** Initialize the kernel's inputs and outputs.
56 *
57 * Similar to @ref NEAddMulAdd::configure()
58 *
59 */
60 void configure(const ITensorInfo *input1, const ITensorInfo *input2,
61 const ITensorInfo *bn_mul, const ITensorInfo *bn_add,
62 ITensorInfo *add_output, ITensorInfo *final_output,
63 ConvertPolicy policy, const ActivationLayerInfo &act_info);
64 /** Static function to check if given info will lead to a valid configuration
65 *
66 * Similar to CpuAddMulAddKernel::configure()
67 *
68 * @return a status
69 */
70 static Status validate(const ITensorInfo *input1, const ITensorInfo *input2,
71 const ITensorInfo *bn_mul, const ITensorInfo *bn_add,
72 const ITensorInfo *add_output, const ITensorInfo *final_output,
73 ConvertPolicy policy, const ActivationLayerInfo &act_info);
74
75 // Inherited methods overridden:
76 void run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) override;
77 const char *name() const override;
78
79 static const std::vector<AddMulAddKernel> &get_available_kernels();
80
81private:
82 ConvertPolicy _policy{};
83 ActivationLayerInfo _act_info{};
84 AddMulAddKernelPtr _run_method{ nullptr };
85 std::string _name{};
86};
87} // namespace kernels
88} // namespace cpu
89} // namespace arm_compute
90#endif /* SRC_CPU_KERNELS_CPUADDMULADDKERNEL */