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