giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 1 | /* |
Sang-Hoon Park | 5db75c3 | 2021-01-07 16:59:32 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2021 Arm Limited. |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 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 | */ |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 24 | #include "src/core/cpu/kernels/CpuElementwiseKernel.h" |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 25 | |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 26 | #include "arm_compute/core/Helpers.h" |
| 27 | #include "arm_compute/core/IAccessWindow.h" |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame] | 28 | #include "src/core/CPP/Validate.h" |
Sang-Hoon Park | d2447bb | 2021-01-18 09:41:37 +0000 | [diff] [blame] | 29 | #include "src/core/common/Registrars.h" |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 30 | #include "src/core/cpu/kernels/elementwise/neon/elementwise_list.h" |
| 31 | #include "src/core/cpu/kernels/elementwise/neon/elementwise_quantized_list.h" |
| 32 | #include "src/core/cpu/kernels/elementwise/sve/elementwise_list.h" |
| 33 | #include "src/core/cpu/kernels/elementwise/sve/elementwise_quantized_list.h" |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame] | 34 | #include "src/core/helpers/AutoConfiguration.h" |
| 35 | #include "src/core/helpers/WindowHelpers.h" |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 36 | |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 37 | #include <arm_neon.h> |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 38 | |
| 39 | namespace arm_compute |
| 40 | { |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 41 | namespace cpu |
| 42 | { |
| 43 | namespace kernels |
| 44 | { |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 45 | namespace |
| 46 | { |
Sang-Hoon Park | d2447bb | 2021-01-18 09:41:37 +0000 | [diff] [blame] | 47 | using ElementwiseSelector = std::add_pointer<bool(DataType)>::type; |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 48 | using UKernelType = CpuElementwiseKernel::ElementwiseFunction; |
Sang-Hoon Park | d2447bb | 2021-01-18 09:41:37 +0000 | [diff] [blame] | 49 | struct ElementwiseKernel |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 50 | { |
Sang-Hoon Park | d2447bb | 2021-01-18 09:41:37 +0000 | [diff] [blame] | 51 | const char *name; |
| 52 | const ElementwiseSelector is_selected; |
| 53 | UKernelType *ukernel; |
| 54 | }; |
| 55 | |
| 56 | template <DataType dt> |
| 57 | inline bool is_selected(DataType data_type) |
| 58 | { |
| 59 | return dt == data_type; |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 60 | } |
| 61 | |
Sang-Hoon Park | d2447bb | 2021-01-18 09:41:37 +0000 | [diff] [blame] | 62 | template <DataType input_data_type, DataType output_data_type = input_data_type> |
| 63 | static ElementwiseKernel generate_kernel(UKernelType *ukernel) |
Michalis Spyrou | 8d4d1b8 | 2019-11-28 11:31:23 +0000 | [diff] [blame] | 64 | { |
Sang-Hoon Park | d2447bb | 2021-01-18 09:41:37 +0000 | [diff] [blame] | 65 | std::string kernel_name("op_"); |
| 66 | kernel_name += string_from_data_type(input_data_type) + "_"; |
| 67 | kernel_name += string_from_data_type(input_data_type) + "_"; |
| 68 | kernel_name += string_from_data_type(output_data_type); |
Michalis Spyrou | 8d4d1b8 | 2019-11-28 11:31:23 +0000 | [diff] [blame] | 69 | |
Sang-Hoon Park | d2447bb | 2021-01-18 09:41:37 +0000 | [diff] [blame] | 70 | return { kernel_name.c_str(), is_selected<input_data_type>, ukernel }; |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | template <ArithmeticOperation op> |
| 74 | std::function<void(const ITensor *, const ITensor *, ITensor *, const Window &)> |
Michalis Spyrou | ce0c675 | 2020-06-18 10:14:57 +0100 | [diff] [blame] | 75 | configure_arithm_func(const ITensorInfo *input1, const ITensorInfo *input2, ITensorInfo *output) |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 76 | { |
Sang-Hoon Park | d2447bb | 2021-01-18 09:41:37 +0000 | [diff] [blame] | 77 | ARM_COMPUTE_UNUSED(input2, output); |
| 78 | static ElementwiseKernel kernels[] = |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 79 | { |
Sang-Hoon Park | 5db75c3 | 2021-01-07 16:59:32 +0000 | [diff] [blame] | 80 | #if defined(__ARM_FEATURE_SVE) |
Sang-Hoon Park | d2447bb | 2021-01-18 09:41:37 +0000 | [diff] [blame] | 81 | generate_kernel<DataType::F32>(REGISTER_FP32_SVE((arm_compute::cpu::sve::elementwise_arithmetic_op<op, float32_t>))), |
| 82 | generate_kernel<DataType::S32>(REGISTER_INTEGER_SVE((arm_compute::cpu::sve::elementwise_arithmetic_op<op, int32_t>))), |
Sang-Hoon Park | 5db75c3 | 2021-01-07 16:59:32 +0000 | [diff] [blame] | 83 | #else /* defined(__ARM_FEATURE_SVE) */ |
Sang-Hoon Park | d2447bb | 2021-01-18 09:41:37 +0000 | [diff] [blame] | 84 | generate_kernel<DataType::F32>(REGISTER_FP32_NEON((arm_compute::cpu::elementwise_arithm_op<op, typename wrapper::traits::neon_vector<float, 4>>))), |
| 85 | generate_kernel<DataType::S32>(REGISTER_INTEGER_NEON((arm_compute::cpu::elementwise_arithm_op<op, typename wrapper::traits::neon_vector<int32_t, 4>>))), |
Sang-Hoon Park | 5db75c3 | 2021-01-07 16:59:32 +0000 | [diff] [blame] | 86 | #endif /* defined(__ARM_FEATURE_SVE) */ |
Sang-Hoon Park | d23a251 | 2021-01-11 22:19:49 +0000 | [diff] [blame] | 87 | #if defined(__ARM_FEATURE_SVE2) |
Sang-Hoon Park | d2447bb | 2021-01-18 09:41:37 +0000 | [diff] [blame] | 88 | generate_kernel<DataType::QASYMM8>(REGISTER_QASYMM8_SVE((arm_compute::cpu::sve::elementwise_arithmetic_quantized_op<op, uint8_t>))), |
| 89 | generate_kernel<DataType::QASYMM8_SIGNED>(REGISTER_QASYMM8_SIGNED_SVE((arm_compute::cpu::sve::elementwise_arithmetic_quantized_op<op, int8_t>))), |
Sang-Hoon Park | d23a251 | 2021-01-11 22:19:49 +0000 | [diff] [blame] | 90 | #else /* defined(__ARM_FEATURE_SVE2) */ |
Sang-Hoon Park | d2447bb | 2021-01-18 09:41:37 +0000 | [diff] [blame] | 91 | generate_kernel<DataType::QASYMM8>(REGISTER_QASYMM8_NEON((arm_compute::cpu::elementwise_arithm_op_quantized<op>))), |
| 92 | generate_kernel<DataType::QASYMM8_SIGNED>(REGISTER_QASYMM8_SIGNED_NEON((arm_compute::cpu::elementwise_arithm_op_quantized_signed<op>))), |
Sang-Hoon Park | d23a251 | 2021-01-11 22:19:49 +0000 | [diff] [blame] | 93 | #endif /* defined(__ARM_FEATURE_SVE2) */ |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 94 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Sang-Hoon Park | 5db75c3 | 2021-01-07 16:59:32 +0000 | [diff] [blame] | 95 | #if defined(__ARM_FEATURE_SVE) |
Sang-Hoon Park | d2447bb | 2021-01-18 09:41:37 +0000 | [diff] [blame] | 96 | generate_kernel<DataType::F16>(REGISTER_FP16_SVE((arm_compute::cpu::sve::elementwise_arithmetic_op<op, float16_t>))), |
Sang-Hoon Park | 5db75c3 | 2021-01-07 16:59:32 +0000 | [diff] [blame] | 97 | #else /* defined(__ARM_FEATURE_SVE) */ |
Sang-Hoon Park | d2447bb | 2021-01-18 09:41:37 +0000 | [diff] [blame] | 98 | generate_kernel<DataType::F16>(REGISTER_FP16_NEON((arm_compute::cpu::elementwise_arithm_op<op, typename wrapper::traits::neon_vector<float16_t, 8>>))), |
Sang-Hoon Park | 5db75c3 | 2021-01-07 16:59:32 +0000 | [diff] [blame] | 99 | #endif /* defined(__ARM_FEATURE_SVE) */ |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 100 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Sang-Hoon Park | d2447bb | 2021-01-18 09:41:37 +0000 | [diff] [blame] | 101 | generate_kernel<DataType::S16>(REGISTER_INTEGER_NEON((arm_compute::cpu::elementwise_arithm_op<op, typename wrapper::traits::neon_vector<int16_t, 8>>))), |
| 102 | }; |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 103 | |
Sang-Hoon Park | d2447bb | 2021-01-18 09:41:37 +0000 | [diff] [blame] | 104 | for(const auto &uk : kernels) |
| 105 | { |
| 106 | if(uk.is_selected(input1->data_type())) |
| 107 | { |
| 108 | return uk.ukernel; |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | return nullptr; |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | template <ComparisonOperation op> |
| 116 | std::function<void(const ITensor *input1, const ITensor *input2, ITensor *output, const Window &window)> |
Michalis Spyrou | ce0c675 | 2020-06-18 10:14:57 +0100 | [diff] [blame] | 117 | configure_comp_func(const ITensorInfo *input1, const ITensorInfo *input2, ITensorInfo *output) |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 118 | { |
Sang-Hoon Park | d2447bb | 2021-01-18 09:41:37 +0000 | [diff] [blame] | 119 | ARM_COMPUTE_UNUSED(input2, output); |
| 120 | static ElementwiseKernel kernels[] = |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 121 | { |
Sang-Hoon Park | 5db75c3 | 2021-01-07 16:59:32 +0000 | [diff] [blame] | 122 | #if defined(__ARM_FEATURE_SVE) |
Sang-Hoon Park | d2447bb | 2021-01-18 09:41:37 +0000 | [diff] [blame] | 123 | generate_kernel<DataType::U8, DataType::U8>(REGISTER_INTEGER_SVE((arm_compute::cpu::sve::elementwise_comparison_op<op, uint8_t>))), |
| 124 | generate_kernel<DataType::F32, DataType::U8>(REGISTER_FP32_SVE((arm_compute::cpu::sve::elementwise_comparison_op<op, float>))), |
| 125 | generate_kernel<DataType::S16, DataType::U8>(REGISTER_INTEGER_SVE((arm_compute::cpu::sve::elementwise_comparison_op<op, int16_t>))), |
| 126 | generate_kernel<DataType::S32, DataType::U8>(REGISTER_INTEGER_SVE((arm_compute::cpu::sve::elementwise_comparison_op<op, int32_t>))), |
Sang-Hoon Park | 5db75c3 | 2021-01-07 16:59:32 +0000 | [diff] [blame] | 127 | #else /* defined(__ARM_FEATURE_SVE) */ |
Sang-Hoon Park | d2447bb | 2021-01-18 09:41:37 +0000 | [diff] [blame] | 128 | generate_kernel<DataType::U8, DataType::U8>(REGISTER_INTEGER_NEON((arm_compute::cpu::elementwise_comp_op_8<op, uint8_t, uint8x16_t>))), |
| 129 | generate_kernel<DataType::F32, DataType::U8>(REGISTER_FP32_NEON((arm_compute::cpu::elementwise_comp_op_32<op, float, float32x4_t>))), |
| 130 | generate_kernel<DataType::S16, DataType::U8>(REGISTER_INTEGER_NEON((arm_compute::cpu::elementwise_comp_op_16<op, int16_t, int16x8_t>))), |
| 131 | generate_kernel<DataType::S32, DataType::U8>(REGISTER_INTEGER_NEON((arm_compute::cpu::elementwise_comp_op_32<op, int32_t, int32x4_t>))), |
Sang-Hoon Park | 5db75c3 | 2021-01-07 16:59:32 +0000 | [diff] [blame] | 132 | #endif /* defined(__ARM_FEATURE_SVE) */ |
Sang-Hoon Park | d23a251 | 2021-01-11 22:19:49 +0000 | [diff] [blame] | 133 | #if defined(__ARM_FEATURE_SVE2) |
Sang-Hoon Park | d2447bb | 2021-01-18 09:41:37 +0000 | [diff] [blame] | 134 | generate_kernel<DataType::QASYMM8_SIGNED, DataType::U8>(REGISTER_QASYMM8_SIGNED_SVE((arm_compute::cpu::sve::elementwise_comparison_quantized_op<op, int8_t>))), |
| 135 | generate_kernel<DataType::QASYMM8, DataType::U8>(REGISTER_QASYMM8_SVE((arm_compute::cpu::sve::elementwise_comparison_quantized_op<op, uint8_t>))), |
Sang-Hoon Park | d23a251 | 2021-01-11 22:19:49 +0000 | [diff] [blame] | 136 | #else /* defined(__ARM_FEATURE_SVE2) */ |
Sang-Hoon Park | d2447bb | 2021-01-18 09:41:37 +0000 | [diff] [blame] | 137 | generate_kernel<DataType::QASYMM8_SIGNED, DataType::U8>(REGISTER_QASYMM8_SIGNED_NEON((arm_compute::cpu::elementwise_comp_op_quantized_signed<op>))), |
| 138 | generate_kernel<DataType::QASYMM8, DataType::U8>(REGISTER_QASYMM8_NEON((arm_compute::cpu::elementwise_comp_op_quantized<op>))), |
Sang-Hoon Park | d23a251 | 2021-01-11 22:19:49 +0000 | [diff] [blame] | 139 | #endif /* defined(__ARM_FEATURE_SVE2) */ |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 140 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Sang-Hoon Park | 5db75c3 | 2021-01-07 16:59:32 +0000 | [diff] [blame] | 141 | #if defined(__ARM_FEATURE_SVE) |
Sang-Hoon Park | d2447bb | 2021-01-18 09:41:37 +0000 | [diff] [blame] | 142 | generate_kernel<DataType::F16, DataType::U8>(REGISTER_FP16_SVE((arm_compute::cpu::sve::elementwise_comparison_op<op, float16_t>))), |
Sang-Hoon Park | 5db75c3 | 2021-01-07 16:59:32 +0000 | [diff] [blame] | 143 | #else /* defined(__ARM_FEATURE_SVE) */ |
Sang-Hoon Park | d2447bb | 2021-01-18 09:41:37 +0000 | [diff] [blame] | 144 | generate_kernel<DataType::F16, DataType::U8>(REGISTER_FP16_NEON((arm_compute::cpu::elementwise_comp_op_16<op, float16_t, float16x8_t>))), |
Sang-Hoon Park | 5db75c3 | 2021-01-07 16:59:32 +0000 | [diff] [blame] | 145 | #endif /* defined(__ARM_FEATURE_SVE) */ |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 146 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Sang-Hoon Park | d2447bb | 2021-01-18 09:41:37 +0000 | [diff] [blame] | 147 | }; |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 148 | |
Sang-Hoon Park | d2447bb | 2021-01-18 09:41:37 +0000 | [diff] [blame] | 149 | for(const auto &uk : kernels) |
| 150 | { |
| 151 | if(uk.is_selected(input1->data_type())) |
| 152 | { |
| 153 | return uk.ukernel; |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | return nullptr; |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 158 | } |
| 159 | } // namespace |
| 160 | |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 161 | Status CpuElementwiseKernel::validate_arguments_common(const ITensorInfo &input1, const ITensorInfo &input2, const ITensorInfo &output) |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 162 | { |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 163 | ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(&input1); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 164 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(&input1, &input2); |
| 165 | |
| 166 | const TensorShape out_shape = TensorShape::broadcast_shape(input1.tensor_shape(), input2.tensor_shape()); |
| 167 | |
| 168 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(out_shape.total_size() == 0, "Inputs are not broadcast compatible"); |
| 169 | |
| 170 | // Validate in case of configured output |
| 171 | if(output.total_size() > 0) |
| 172 | { |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 173 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(detail::have_different_dimensions(out_shape, output.tensor_shape(), 0), |
| 174 | "Wrong shape for output"); |
| 175 | } |
| 176 | |
| 177 | return Status{}; |
| 178 | } |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 179 | |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 180 | void CpuElementwiseKernel::configure_common(const ITensorInfo *input1, const ITensorInfo *input2, ITensorInfo *output) |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 181 | { |
| 182 | ARM_COMPUTE_ERROR_ON_NULLPTR(input1, input2, output); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 183 | |
| 184 | // Configure kernel window |
Michalis Spyrou | ce0c675 | 2020-06-18 10:14:57 +0100 | [diff] [blame] | 185 | const std::pair<TensorShape, ValidRegion> broadcast_pair = ITensorInfo::broadcast_shape_and_valid_region(*input1, *input2); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 186 | const TensorShape &out_shape = broadcast_pair.first; |
| 187 | const ValidRegion &valid_region = broadcast_pair.second; |
| 188 | |
| 189 | // Auto initialize output if not initialized |
Michalis Spyrou | ce0c675 | 2020-06-18 10:14:57 +0100 | [diff] [blame] | 190 | auto_init_if_empty(*output, out_shape, 1, input1->data_type()); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 191 | |
| 192 | Window win = calculate_max_window(valid_region); |
| 193 | |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 194 | ICpuKernel::configure(win); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 195 | } |
| 196 | |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 197 | void CpuElementwiseKernel::run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 198 | { |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 199 | ARM_COMPUTE_UNUSED(info, window); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 200 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 201 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(ICpuKernel::window(), window); |
| 202 | |
| 203 | auto src0 = tensors.get_const_tensor(TensorType::ACL_SRC_0); |
| 204 | auto src1 = tensors.get_const_tensor(TensorType::ACL_SRC_1); |
| 205 | auto dst = tensors.get_tensor(TensorType::ACL_DST); |
| 206 | |
| 207 | auto function = get_implementation(src0->info(), src1->info(), dst->info()); |
| 208 | ARM_COMPUTE_ERROR_ON(function == nullptr); |
| 209 | function(src0, src1, dst, window); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | /** Arithmetic operators (min, max, squared_diff) */ |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 213 | void CpuArithmeticKernel::configure(ArithmeticOperation op, const ITensorInfo *input1, const ITensorInfo *input2, ITensorInfo *output) |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 214 | { |
Michalis Spyrou | ce0c675 | 2020-06-18 10:14:57 +0100 | [diff] [blame] | 215 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(*input1, *input2, *output)); |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 216 | configure_common(input1, input2, output); |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 217 | _op = op; |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 218 | } |
| 219 | |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 220 | Status CpuArithmeticKernel::validate_arguments(const ITensorInfo &input1, const ITensorInfo &input2, const ITensorInfo &output) |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 221 | { |
Michele Di Giorgio | 1c76c1d | 2020-08-28 13:25:31 +0100 | [diff] [blame] | 222 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(&input1, 1, DataType::QASYMM8, DataType::QASYMM8_SIGNED, DataType::S16, DataType::F16, DataType::S32, DataType::F32); |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 223 | // Validate in case of configured output |
| 224 | if(output.total_size() > 0) |
| 225 | { |
| 226 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(&input1, &output); |
| 227 | } |
| 228 | return validate_arguments_common(input1, input2, output); |
| 229 | } |
| 230 | |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 231 | Status CpuArithmeticKernel::validate(ArithmeticOperation op, const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output) |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 232 | { |
| 233 | ARM_COMPUTE_UNUSED(op); |
| 234 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input1, input2, output); |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 235 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(*input1, *input2, *output)); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 236 | return Status{}; |
| 237 | } |
| 238 | |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 239 | std::function<CpuElementwiseKernel::ElementwiseFunction> |
| 240 | CpuArithmeticKernel::get_implementation(const ITensorInfo *input1, const ITensorInfo *input2, ITensorInfo *output) |
| 241 | { |
| 242 | switch(_op) |
| 243 | { |
| 244 | case ArithmeticOperation::MAX: |
| 245 | return configure_arithm_func<ArithmeticOperation::MAX>(input1, input2, output); |
| 246 | case ArithmeticOperation::MIN: |
| 247 | return configure_arithm_func<ArithmeticOperation::MIN>(input1, input2, output); |
| 248 | case ArithmeticOperation::SQUARED_DIFF: |
| 249 | return configure_arithm_func<ArithmeticOperation::SQUARED_DIFF>(input1, input2, output); |
| 250 | case ArithmeticOperation::PRELU: |
| 251 | return configure_arithm_func<ArithmeticOperation::PRELU>(input1, input2, output); |
| 252 | case ArithmeticOperation::DIV: |
| 253 | return configure_arithm_func<ArithmeticOperation::DIV>(input1, input2, output); |
| 254 | case ArithmeticOperation::POWER: |
| 255 | return configure_arithm_func<ArithmeticOperation::POWER>(input1, input2, output); |
| 256 | default: |
| 257 | ARM_COMPUTE_ERROR("NOT_SUPPORTED!"); |
| 258 | } |
| 259 | return nullptr; |
| 260 | } |
| 261 | |
George Wort | a1e7e28 | 2019-01-15 11:00:29 +0000 | [diff] [blame] | 262 | /** The division operator */ |
| 263 | |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 264 | void CpuDivisionKernel::configure(const ITensorInfo *input1, const ITensorInfo *input2, ITensorInfo *output) |
George Wort | a1e7e28 | 2019-01-15 11:00:29 +0000 | [diff] [blame] | 265 | { |
Michalis Spyrou | ce0c675 | 2020-06-18 10:14:57 +0100 | [diff] [blame] | 266 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(*input1, *input2, *output)); |
George Wort | a1e7e28 | 2019-01-15 11:00:29 +0000 | [diff] [blame] | 267 | configure_common(input1, input2, output); |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 268 | _op = ArithmeticOperation::DIV; |
George Wort | a1e7e28 | 2019-01-15 11:00:29 +0000 | [diff] [blame] | 269 | } |
| 270 | |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 271 | Status CpuDivisionKernel::validate_arguments(const ITensorInfo &input1, const ITensorInfo &input2, const ITensorInfo &output) |
George Wort | a1e7e28 | 2019-01-15 11:00:29 +0000 | [diff] [blame] | 272 | { |
Georgios Pinitas | 1813422 | 2020-09-03 21:00:23 +0100 | [diff] [blame] | 273 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(&input1, 1, DataType::S32, DataType::F16, DataType::F32); |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 274 | return CpuArithmeticKernel::validate_arguments(input1, input2, output); |
George Wort | a1e7e28 | 2019-01-15 11:00:29 +0000 | [diff] [blame] | 275 | } |
| 276 | |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 277 | Status CpuDivisionKernel::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output) |
George Wort | a1e7e28 | 2019-01-15 11:00:29 +0000 | [diff] [blame] | 278 | { |
| 279 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input1, input2, output); |
| 280 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(*input1, *input2, *output)); |
| 281 | return Status{}; |
| 282 | } |
| 283 | |
Usama Arif | 81e671e | 2019-05-13 13:33:14 +0100 | [diff] [blame] | 284 | /** The power operator */ |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 285 | void CpuPowerKernel::configure(const ITensorInfo *input1, const ITensorInfo *input2, ITensorInfo *output) |
Usama Arif | 81e671e | 2019-05-13 13:33:14 +0100 | [diff] [blame] | 286 | { |
Michalis Spyrou | ce0c675 | 2020-06-18 10:14:57 +0100 | [diff] [blame] | 287 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(*input1, *input2, *output)); |
Usama Arif | 81e671e | 2019-05-13 13:33:14 +0100 | [diff] [blame] | 288 | configure_common(input1, input2, output); |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 289 | _op = ArithmeticOperation::POWER; |
Usama Arif | 81e671e | 2019-05-13 13:33:14 +0100 | [diff] [blame] | 290 | } |
| 291 | |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 292 | Status CpuPowerKernel::validate_arguments(const ITensorInfo &input1, const ITensorInfo &input2, const ITensorInfo &output) |
Usama Arif | 81e671e | 2019-05-13 13:33:14 +0100 | [diff] [blame] | 293 | { |
| 294 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(&input1, 1, DataType::F16, DataType::F32); |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 295 | return CpuArithmeticKernel::validate_arguments(input1, input2, output); |
Usama Arif | 81e671e | 2019-05-13 13:33:14 +0100 | [diff] [blame] | 296 | } |
| 297 | |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 298 | Status CpuPowerKernel::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output) |
Usama Arif | 81e671e | 2019-05-13 13:33:14 +0100 | [diff] [blame] | 299 | { |
| 300 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input1, input2, output); |
| 301 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(*input1, *input2, *output)); |
| 302 | return Status{}; |
| 303 | } |
| 304 | |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 305 | /** Comparison operators (equal, not equal, less than, greater than, less than or equal, greater than or equal) */ |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 306 | void CpuComparisonKernel::configure(ComparisonOperation op, const ITensorInfo *input1, const ITensorInfo *input2, ITensorInfo *output) |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 307 | { |
Michalis Spyrou | ce0c675 | 2020-06-18 10:14:57 +0100 | [diff] [blame] | 308 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(*input1, *input2, *output)); |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 309 | configure_common(input1, input2, output); |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 310 | _op = op; |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 311 | } |
| 312 | |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 313 | Status CpuComparisonKernel::validate_arguments(const ITensorInfo &input1, const ITensorInfo &input2, const ITensorInfo &output) |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 314 | { |
Michele Di Giorgio | 1c76c1d | 2020-08-28 13:25:31 +0100 | [diff] [blame] | 315 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(&input1, 1, DataType::U8, DataType::QASYMM8, DataType::QASYMM8_SIGNED, DataType::S16, DataType::F16, DataType::S32, DataType::F32); |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 316 | // Validate in case of configured output |
| 317 | if(output.total_size() > 0) |
| 318 | { |
| 319 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(&output, 1, DataType::U8); |
| 320 | } |
| 321 | return validate_arguments_common(input1, input2, output); |
| 322 | } |
| 323 | |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 324 | Status CpuComparisonKernel::validate(ComparisonOperation op, const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output) |
George Wort | d88590f | 2018-12-12 17:39:58 +0000 | [diff] [blame] | 325 | { |
| 326 | ARM_COMPUTE_UNUSED(op); |
| 327 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input1, input2, output); |
| 328 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(*input1, *input2, *output)); |
| 329 | return Status{}; |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 330 | } |
Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame^] | 331 | |
| 332 | std::function<CpuElementwiseKernel::ElementwiseFunction> |
| 333 | CpuComparisonKernel::get_implementation(const ITensorInfo *input1, const ITensorInfo *input2, ITensorInfo *output) |
| 334 | { |
| 335 | switch(_op) |
| 336 | { |
| 337 | case ComparisonOperation::Equal: |
| 338 | return configure_comp_func<ComparisonOperation::Equal>(input1, input2, output); |
| 339 | case ComparisonOperation::NotEqual: |
| 340 | return configure_comp_func<ComparisonOperation::NotEqual>(input1, input2, output); |
| 341 | case ComparisonOperation::Greater: |
| 342 | return configure_comp_func<ComparisonOperation::Greater>(input1, input2, output); |
| 343 | case ComparisonOperation::GreaterEqual: |
| 344 | return configure_comp_func<ComparisonOperation::GreaterEqual>(input1, input2, output); |
| 345 | case ComparisonOperation::Less: |
| 346 | return configure_comp_func<ComparisonOperation::Less>(input1, input2, output); |
| 347 | case ComparisonOperation::LessEqual: |
| 348 | return configure_comp_func<ComparisonOperation::LessEqual>(input1, input2, output); |
| 349 | default: |
| 350 | ARM_COMPUTE_ERROR("NOT_SUPPORTED!"); |
| 351 | } |
| 352 | return nullptr; |
| 353 | } |
| 354 | } // namespace kernels |
| 355 | } // namespace cpu |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 356 | } // namespace arm_compute |