Gunes Bayir | ae72a46 | 2023-01-29 13:24:24 +0000 | [diff] [blame] | 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 | |
| 25 | #ifndef SRC_CPU_KERNELS_CPUADDMULADDKERNEL |
| 26 | #define SRC_CPU_KERNELS_CPUADDMULADDKERNEL |
| 27 | |
SiCong Li | 9129549 | 2023-07-21 18:16:13 +0100 | [diff] [blame] | 28 | #include "arm_compute/function_info/ActivationLayerInfo.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 29 | |
Gunes Bayir | ae72a46 | 2023-01-29 13:24:24 +0000 | [diff] [blame] | 30 | #include "src/core/common/Macros.h" |
| 31 | #include "src/cpu/ICpuKernel.h" |
| 32 | |
| 33 | namespace arm_compute |
| 34 | { |
| 35 | namespace cpu |
| 36 | { |
| 37 | namespace kernels |
| 38 | { |
| 39 | /** Interface for the kernel to perform addition between two tensors */ |
| 40 | class CpuAddMulAddKernel : public ICpuKernel<CpuAddMulAddKernel> |
| 41 | { |
| 42 | private: |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 43 | 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 Bayir | ae72a46 | 2023-01-29 13:24:24 +0000 | [diff] [blame] | 52 | |
| 53 | public: |
| 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 Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 68 | 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 Bayir | ae72a46 | 2023-01-29 13:24:24 +0000 | [diff] [blame] | 76 | /** 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 Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 82 | 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 Bayir | ae72a46 | 2023-01-29 13:24:24 +0000 | [diff] [blame] | 90 | |
| 91 | // Inherited methods overridden: |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 92 | void run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) override; |
Gunes Bayir | ae72a46 | 2023-01-29 13:24:24 +0000 | [diff] [blame] | 93 | const char *name() const override; |
| 94 | |
| 95 | static const std::vector<AddMulAddKernel> &get_available_kernels(); |
| 96 | |
| 97 | private: |
| 98 | ConvertPolicy _policy{}; |
| 99 | ActivationLayerInfo _act_info{}; |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 100 | AddMulAddKernelPtr _run_method{nullptr}; |
Gunes Bayir | ae72a46 | 2023-01-29 13:24:24 +0000 | [diff] [blame] | 101 | std::string _name{}; |
| 102 | }; |
| 103 | } // namespace kernels |
| 104 | } // namespace cpu |
| 105 | } // namespace arm_compute |
| 106 | #endif /* SRC_CPU_KERNELS_CPUADDMULADDKERNEL */ |