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 #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 32 namespace arm_compute 33 { 34 namespace cpu 35 { 36 /** Basic function to run @ref kernels::CpuAddMulAddKernel */ 37 class CpuAddMulAdd : public ICpuOperator 38 { 39 public: 40 /** Initialize the operator's inputs and outputs. 41 * 42 * Similar to @ref NEAddMulAdd::configure() 43 * 44 */ 45 void configure(const ITensorInfo *input1, const ITensorInfo *input2, 46 const ITensorInfo *bn_mul, const ITensorInfo *bn_add, 47 ITensorInfo *add_output, ITensorInfo *final_output, 48 ConvertPolicy policy, const ActivationLayerInfo &act_info); 49 /** Static function to check if given info will lead to a valid configuration 50 * 51 * Similar to @ref CpuAddMulAdd::configure() 52 * 53 * @return a status 54 */ 55 static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, 56 const ITensorInfo *bn_mul, const ITensorInfo *bn_add, 57 const ITensorInfo *add_output, const ITensorInfo *final_output, 58 ConvertPolicy policy, const ActivationLayerInfo &act_info); 59 60 // Inherited methods overridden: 61 void run(ITensorPack &tensors) override; 62 63 // We need auxilary memory to dequantize batchnorm coefficients 64 experimental::MemoryRequirements workspace() const override; 65 66 private: 67 enum AuxTensorIdx 68 { 69 DequantizedBnMul = 0, 70 DequantizedBnAdd, 71 Count 72 }; 73 74 CpuDequantize _dequantize_bn_mul{}; 75 CpuDequantize _dequantize_bn_add{}; 76 77 TensorInfo _dequantized_bn_mul{}; 78 TensorInfo _dequantized_bn_add{}; 79 80 experimental::MemoryRequirements _aux_mem{ Count }; 81 }; 82 } // namespace cpu 83 } // namespace arm_compute 84 #endif /* SRC_CPU_OPERATORS_CPUADDMULADD */ 85