Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Viet-Hoa Do | 0d05b66 | 2022-09-09 15:39:05 +0100 | [diff] [blame] | 2 | * Copyright (c) 2016-2022 Arm Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [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 | */ |
Georgios Pinitas | 7891a73 | 2021-08-20 21:39:25 +0100 | [diff] [blame] | 24 | #include "src/cpu/kernels/CpuMulKernel.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 25 | |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 26 | #include "arm_compute/core/ITensor.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 27 | #include "arm_compute/core/TensorInfo.h" |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame] | 28 | #include "src/core/CPP/Validate.h" |
Georgios Pinitas | ddb93bb | 2020-10-02 16:38:59 +0100 | [diff] [blame] | 29 | #include "src/core/NEON/NEAsymm.h" |
| 30 | #include "src/core/NEON/NESymm.h" |
| 31 | #include "src/core/NEON/wrapper/wrapper.h" |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame] | 32 | #include "src/core/helpers/AutoConfiguration.h" |
| 33 | #include "src/core/helpers/WindowHelpers.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 34 | |
| 35 | #include <arm_neon.h> |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 36 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 37 | namespace arm_compute |
| 38 | { |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 39 | namespace cpu |
| 40 | { |
| 41 | namespace kernels |
| 42 | { |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 43 | namespace |
| 44 | { |
| 45 | const float scale255_constant = 1.f / 255.f; |
| 46 | const float32x4_t scale255_constant_f32q = vdupq_n_f32(scale255_constant); |
| 47 | const float32x4_t positive_round_f32q = vdupq_n_f32(0.5f); |
| 48 | |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 49 | inline Status validate_arguments(const ITensorInfo *src1, const ITensorInfo *src2, const ITensorInfo *dst, float scale, ConvertPolicy overflow_policy, RoundingPolicy rounding_policy) |
Ioan-Cristian Szabo | 754e952 | 2017-11-28 18:29:43 +0000 | [diff] [blame] | 50 | { |
| 51 | ARM_COMPUTE_UNUSED(overflow_policy); |
| 52 | ARM_COMPUTE_UNUSED(rounding_policy); |
| 53 | |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 54 | ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(src1); |
| 55 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(src1, 1, DataType::U8, DataType::QASYMM8, DataType::QASYMM8_SIGNED, DataType::S16, DataType::S32, DataType::QSYMM16, DataType::F16, |
SiCong Li | bb88f89 | 2020-08-28 11:18:47 +0100 | [diff] [blame] | 56 | DataType::F32); |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 57 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(src2, 1, DataType::U8, DataType::QASYMM8, DataType::QASYMM8_SIGNED, DataType::S16, DataType::S32, DataType::QSYMM16, DataType::F16, |
SiCong Li | bb88f89 | 2020-08-28 11:18:47 +0100 | [diff] [blame] | 58 | DataType::F32); |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 59 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(dst, 1, DataType::U8, DataType::QASYMM8, DataType::QASYMM8_SIGNED, |
Michele Di Giorgio | 9428a18 | 2020-03-30 14:10:20 +0100 | [diff] [blame] | 60 | DataType::S16, DataType::QSYMM16, |
| 61 | DataType::S32, DataType::F16, DataType::F32); |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 62 | if(is_data_type_quantized(src1->data_type()) || is_data_type_quantized(src2->data_type())) |
Pablo Tello | 52ea9c2 | 2019-12-10 11:28:53 +0000 | [diff] [blame] | 63 | { |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 64 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(src1, src2); |
Georgios Pinitas | d7d7e90 | 2019-12-18 15:40:54 +0000 | [diff] [blame] | 65 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(overflow_policy == ConvertPolicy::WRAP, "ConvertPolicy cannot be WRAP if datatype is quantized"); |
Pablo Tello | 52ea9c2 | 2019-12-10 11:28:53 +0000 | [diff] [blame] | 66 | } |
Manuel Bottini | 79fa9a2 | 2019-02-22 17:54:22 +0000 | [diff] [blame] | 67 | |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 68 | if(dst->total_size() > 0) |
Manuel Bottini | 79fa9a2 | 2019-02-22 17:54:22 +0000 | [diff] [blame] | 69 | { |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 70 | const TensorShape &out_shape = TensorShape::broadcast_shape(src1->tensor_shape(), src2->tensor_shape()); |
| 71 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(detail::have_different_dimensions(out_shape, dst->tensor_shape(), 0), "Wrong shape for dst"); |
Manuel Bottini | 79fa9a2 | 2019-02-22 17:54:22 +0000 | [diff] [blame] | 72 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(out_shape.total_size() == 0, "Inputs are not broadcast compatible"); |
SiCong Li | bb88f89 | 2020-08-28 11:18:47 +0100 | [diff] [blame] | 73 | // clang-format off |
| 74 | ARM_COMPUTE_RETURN_ERROR_ON_MSG( |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 75 | !(src1->data_type() == src2->data_type() && src2->data_type() == dst->data_type()) && |
| 76 | !(src1->data_type() == DataType::U8 && src2->data_type() == DataType::U8 && dst->data_type() == DataType::S16) && |
| 77 | !(src1->data_type() == DataType::U8 && src2->data_type() == DataType::S16 && dst->data_type() == DataType::S16) && |
| 78 | !(src1->data_type() == DataType::S16 && src2->data_type() == DataType::U8 && dst->data_type() == DataType::S16) && |
| 79 | !(src1->data_type() == DataType::S16 && src2->data_type() == DataType::U8 && dst->data_type() == DataType::S16) && |
| 80 | !(src1->data_type() == DataType::QSYMM16 && src2->data_type() == DataType::QSYMM16 && dst->data_type() == DataType::S32) |
SiCong Li | bb88f89 | 2020-08-28 11:18:47 +0100 | [diff] [blame] | 81 | , "Invalid data type combination"); |
| 82 | // clang-format on |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 83 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(src1->data_type() == DataType::S16 && dst->data_type() == DataType::S32 && scale != 1.f, "Unsupported scale for QSYMM16 inputs and S32 dst"); |
Manuel Bottini | 79fa9a2 | 2019-02-22 17:54:22 +0000 | [diff] [blame] | 84 | } |
Michalis Spyrou | 861f0db | 2018-02-26 16:47:58 +0000 | [diff] [blame] | 85 | |
Ioan-Cristian Szabo | 754e952 | 2017-11-28 18:29:43 +0000 | [diff] [blame] | 86 | if(std::abs(scale - scale255_constant) < 0.00001f) |
| 87 | { |
| 88 | ARM_COMPUTE_RETURN_ERROR_ON(rounding_policy != RoundingPolicy::TO_NEAREST_UP && rounding_policy != RoundingPolicy::TO_NEAREST_EVEN); |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 89 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(src1->data_type() == DataType::S32 && src2->data_type() == DataType::S32 && dst->data_type() == DataType::S32, |
| 90 | "Scale == 1/255 is not supported if input and dst are of data type S32"); |
Ioan-Cristian Szabo | 754e952 | 2017-11-28 18:29:43 +0000 | [diff] [blame] | 91 | } |
| 92 | else |
| 93 | { |
| 94 | ARM_COMPUTE_RETURN_ERROR_ON(rounding_policy != RoundingPolicy::TO_ZERO); |
| 95 | |
| 96 | int exponent = 0; |
| 97 | const float normalized_mantissa = std::frexp(scale, &exponent); |
| 98 | |
| 99 | // Use int scaling if factor is equal to 1/2^n for 0 <= n <= 15 |
| 100 | // frexp returns 0.5 as mantissa which means that the exponent will be in the range of -1 <= e <= 14 |
| 101 | // Moreover, it will be negative as we deal with 1/2^n |
| 102 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(!((normalized_mantissa == 0.5f) && (-14 <= exponent) && (exponent <= 1)), "Scale value not supported (Should be 1/(2^n) or 1/255"); |
| 103 | } |
| 104 | |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 105 | return Status{}; |
Ioan-Cristian Szabo | 754e952 | 2017-11-28 18:29:43 +0000 | [diff] [blame] | 106 | } |
| 107 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 108 | /* Scales a given vector by 1/255. |
| 109 | * |
| 110 | * @note This does not work for all cases. e.g. for float of 0.49999999999999994 and large floats. |
| 111 | * |
| 112 | * @param in Input vector to scale. |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 113 | * @return Scaled dst rounded to nearest (round half up). |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 114 | */ |
| 115 | inline int32x4_t scale255_S32_S32(int32x4_t in) |
| 116 | { |
| 117 | // Scale |
| 118 | const float32x4_t tmp = vmulq_f32(vcvtq_f32_s32(in), scale255_constant_f32q); |
| 119 | // Round to nearest (round half up) |
| 120 | // Add +0.5 for all values |
| 121 | // Afterwards vcvt rounds toward zero |
| 122 | return vcvtq_s32_f32(vaddq_f32(tmp, positive_round_f32q)); |
| 123 | } |
| 124 | |
| 125 | inline uint16x8_t scale255_U16_U16(uint16x8_t in) |
| 126 | { |
| 127 | const int32x4_t tmp_s1 = scale255_S32_S32(vreinterpretq_s32_u32(vmovl_u16(vget_high_u16(in)))); |
| 128 | const int32x4_t tmp_s2 = scale255_S32_S32(vreinterpretq_s32_u32(vmovl_u16(vget_low_u16(in)))); |
| 129 | return vreinterpretq_u16_s16(vcombine_s16(vmovn_s32(tmp_s2), vmovn_s32(tmp_s1))); |
| 130 | } |
| 131 | |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 132 | template <typename T> |
| 133 | inline typename std::enable_if<std::is_same<T, int8_t>::value, int8x16_t>::type |
| 134 | vquantize(float32x4x4_t val, const UniformQuantizationInfo &info) |
Manuel Bottini | 79fa9a2 | 2019-02-22 17:54:22 +0000 | [diff] [blame] | 135 | { |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 136 | return vquantize_signed(val, info); |
Manuel Bottini | 79fa9a2 | 2019-02-22 17:54:22 +0000 | [diff] [blame] | 137 | } |
| 138 | |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 139 | template <typename T> |
| 140 | inline typename std::enable_if<std::is_same<T, uint8_t>::value, uint8x16_t>::type |
| 141 | vquantize(float32x4x4_t val, const UniformQuantizationInfo &info) |
Pablo Tello | 52ea9c2 | 2019-12-10 11:28:53 +0000 | [diff] [blame] | 142 | { |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 143 | return vquantize(val, info); |
Pablo Tello | 52ea9c2 | 2019-12-10 11:28:53 +0000 | [diff] [blame] | 144 | } |
| 145 | |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 146 | template <typename T> |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 147 | void mul_saturate_quantized_8(const ITensor *src1, const ITensor *src2, ITensor *out, const Window &window, float scale) |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 148 | { |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 149 | // Create input windows |
| 150 | Window win = window; |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 151 | Window input1_win = window.broadcast_if_dimension_le_one(src1->info()->tensor_shape()); |
| 152 | Window input2_win = window.broadcast_if_dimension_le_one(src2->info()->tensor_shape()); |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 153 | |
| 154 | // Clear X Dimension on execution window as we handle manually |
| 155 | win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 156 | |
Sheri Zhang | a449a36 | 2020-07-16 15:52:25 +0100 | [diff] [blame] | 157 | const int window_step_x = 16 / sizeof(T); |
| 158 | const auto window_start_x = static_cast<int>(window.x().start()); |
| 159 | const auto window_end_x = static_cast<int>(window.x().end()); |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 160 | const bool is_broadcast_across_x = src1->info()->tensor_shape().x() != src2->info()->tensor_shape().x(); |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 161 | |
Sheri Zhang | a449a36 | 2020-07-16 15:52:25 +0100 | [diff] [blame] | 162 | const UniformQuantizationInfo output_qua_info = out->info()->quantization_info().uniform(); |
| 163 | const UniformQuantizationInfo tmp_qua_info = { output_qua_info.scale / scale, output_qua_info.offset }; |
Manuel Bottini | 7bb56c6 | 2019-06-26 15:17:09 +0100 | [diff] [blame] | 164 | |
Sheri Zhang | a449a36 | 2020-07-16 15:52:25 +0100 | [diff] [blame] | 165 | if(is_broadcast_across_x) |
Manuel Bottini | 7bb56c6 | 2019-06-26 15:17:09 +0100 | [diff] [blame] | 166 | { |
Sheri Zhang | a449a36 | 2020-07-16 15:52:25 +0100 | [diff] [blame] | 167 | const bool is_broadcast_input_2 = input2_win.x().step() == 0; |
| 168 | Window broadcast_win = is_broadcast_input_2 ? input2_win : input1_win; |
| 169 | Window non_broadcast_win = !is_broadcast_input_2 ? input2_win : input1_win; |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 170 | const ITensor *broadcast_tensor = is_broadcast_input_2 ? src2 : src1; |
| 171 | const ITensor *non_broadcast_tensor = !is_broadcast_input_2 ? src2 : src1; |
Sheri Zhang | a449a36 | 2020-07-16 15:52:25 +0100 | [diff] [blame] | 172 | const UniformQuantizationInfo broadcast_qinfo = broadcast_tensor->info()->quantization_info().uniform(); |
| 173 | const UniformQuantizationInfo non_broadcast_qinfo = non_broadcast_tensor->info()->quantization_info().uniform(); |
Manuel Bottini | 7bb56c6 | 2019-06-26 15:17:09 +0100 | [diff] [blame] | 174 | |
Sheri Zhang | a449a36 | 2020-07-16 15:52:25 +0100 | [diff] [blame] | 175 | // Clear X Dimension on execution window as we handle manually |
| 176 | non_broadcast_win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 177 | |
| 178 | Iterator broadcast_input(broadcast_tensor, broadcast_win); |
| 179 | Iterator non_broadcast_input(non_broadcast_tensor, non_broadcast_win); |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 180 | Iterator dst(out, win); |
Sheri Zhang | a449a36 | 2020-07-16 15:52:25 +0100 | [diff] [blame] | 181 | |
| 182 | using ExactTagType = typename wrapper::traits::neon_vector<T, window_step_x>::tag_type; |
| 183 | |
| 184 | execute_window_loop(win, [&](const Coordinates &) |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 185 | { |
Sheri Zhang | a449a36 | 2020-07-16 15:52:25 +0100 | [diff] [blame] | 186 | const auto non_broadcast_input_ptr = reinterpret_cast<const T *>(non_broadcast_input.ptr()); |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 187 | const auto output_ptr = reinterpret_cast<T *>(dst.ptr()); |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 188 | |
Sheri Zhang | a449a36 | 2020-07-16 15:52:25 +0100 | [diff] [blame] | 189 | const auto broadcast_value = *reinterpret_cast<const T *>(broadcast_input.ptr()); |
| 190 | const auto broadcast_value_vec = wrapper::vdup_n(broadcast_value, ExactTagType{}); |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 191 | |
Sheri Zhang | a449a36 | 2020-07-16 15:52:25 +0100 | [diff] [blame] | 192 | // Compute window_step_x elements per iteration |
| 193 | int x = window_start_x; |
| 194 | for(; x <= (window_end_x - window_step_x); x += window_step_x) |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 195 | { |
Sheri Zhang | a449a36 | 2020-07-16 15:52:25 +0100 | [diff] [blame] | 196 | const auto non_broadcast_v = wrapper::vloadq(non_broadcast_input_ptr + x); |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 197 | |
Sheri Zhang | a449a36 | 2020-07-16 15:52:25 +0100 | [diff] [blame] | 198 | // Dequantize inputs |
| 199 | const float32x4x4_t in1_f32x4x4 = vdequantize(non_broadcast_v, non_broadcast_qinfo); |
| 200 | const float32x4x4_t in2_f32x4x4 = vdequantize(broadcast_value_vec, broadcast_qinfo); |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 201 | |
Sheri Zhang | a449a36 | 2020-07-16 15:52:25 +0100 | [diff] [blame] | 202 | const float32x4x4_t out_f32x4x4 = |
| 203 | { |
| 204 | vmulq_f32(in1_f32x4x4.val[0], in2_f32x4x4.val[0]), |
| 205 | vmulq_f32(in1_f32x4x4.val[1], in2_f32x4x4.val[1]), |
| 206 | vmulq_f32(in1_f32x4x4.val[2], in2_f32x4x4.val[2]), |
| 207 | vmulq_f32(in1_f32x4x4.val[3], in2_f32x4x4.val[3]), |
| 208 | }; |
| 209 | |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 210 | // Quantize dst |
Sheri Zhang | a449a36 | 2020-07-16 15:52:25 +0100 | [diff] [blame] | 211 | const auto result = vquantize<T>(out_f32x4x4, tmp_qua_info); |
| 212 | wrapper::vstore(output_ptr + x, result); |
| 213 | } |
| 214 | |
| 215 | // Compute left-over elements |
| 216 | for(; x < window_end_x; ++x) |
| 217 | { |
| 218 | // Dequantize inputs |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 219 | const T src1 = *(non_broadcast_input_ptr + x); |
| 220 | const float tmp_in1 = Qasymm8QuantizationHelper<T>::dequantize(src1, non_broadcast_qinfo); |
Michele Di Giorgio | 40aad9b | 2020-07-22 15:17:43 +0100 | [diff] [blame] | 221 | const float tmp_in2 = Qasymm8QuantizationHelper<T>::dequantize(broadcast_value, broadcast_qinfo); |
| 222 | const float tmp_f = tmp_in1 * tmp_in2; |
Sheri Zhang | a449a36 | 2020-07-16 15:52:25 +0100 | [diff] [blame] | 223 | |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 224 | // Quantize dst |
Michele Di Giorgio | 40aad9b | 2020-07-22 15:17:43 +0100 | [diff] [blame] | 225 | const auto tmp_qua = Qasymm8QuantizationHelper<T>::quantize(tmp_f, tmp_qua_info); |
Sheri Zhang | a449a36 | 2020-07-16 15:52:25 +0100 | [diff] [blame] | 226 | *(output_ptr + x) = tmp_qua; |
| 227 | } |
| 228 | }, |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 229 | broadcast_input, non_broadcast_input, dst); |
Sheri Zhang | a449a36 | 2020-07-16 15:52:25 +0100 | [diff] [blame] | 230 | } |
| 231 | else |
| 232 | { |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 233 | const UniformQuantizationInfo input1_qua_info = src1->info()->quantization_info().uniform(); |
| 234 | const UniformQuantizationInfo input2_qua_info = src2->info()->quantization_info().uniform(); |
Sheri Zhang | a449a36 | 2020-07-16 15:52:25 +0100 | [diff] [blame] | 235 | |
| 236 | // Clear X Dimension on execution window as we handle manually |
| 237 | input1_win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 238 | input2_win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 239 | |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 240 | Iterator input1(src1, input1_win); |
| 241 | Iterator input2(src2, input2_win); |
| 242 | Iterator dst(out, win); |
Sheri Zhang | a449a36 | 2020-07-16 15:52:25 +0100 | [diff] [blame] | 243 | |
| 244 | execute_window_loop(win, [&](const Coordinates &) |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 245 | { |
Sheri Zhang | a449a36 | 2020-07-16 15:52:25 +0100 | [diff] [blame] | 246 | const auto input1_ptr = reinterpret_cast<const T *>(input1.ptr()); |
| 247 | const auto input2_ptr = reinterpret_cast<const T *>(input2.ptr()); |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 248 | const auto output_ptr = reinterpret_cast<T *>(dst.ptr()); |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 249 | |
Sheri Zhang | a449a36 | 2020-07-16 15:52:25 +0100 | [diff] [blame] | 250 | // Compute window_step_x elements per iteration |
| 251 | int x = window_start_x; |
| 252 | for(; x <= (window_end_x - window_step_x); x += window_step_x) |
| 253 | { |
| 254 | const auto input1_q = wrapper::vloadq(input1_ptr + x); |
| 255 | const auto input2_q = wrapper::vloadq(input2_ptr + x); |
| 256 | |
| 257 | // Dequantize inputs |
| 258 | const float32x4x4_t in1_f32x4x4 = vdequantize(input1_q, input1_qua_info); |
| 259 | const float32x4x4_t in2_f32x4x4 = vdequantize(input2_q, input2_qua_info); |
| 260 | |
| 261 | const float32x4x4_t out_f32x4x4 = |
| 262 | { |
| 263 | vmulq_f32(in1_f32x4x4.val[0], in2_f32x4x4.val[0]), |
| 264 | vmulq_f32(in1_f32x4x4.val[1], in2_f32x4x4.val[1]), |
| 265 | vmulq_f32(in1_f32x4x4.val[2], in2_f32x4x4.val[2]), |
| 266 | vmulq_f32(in1_f32x4x4.val[3], in2_f32x4x4.val[3]), |
| 267 | }; |
| 268 | |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 269 | // Quantize dst |
Sheri Zhang | a449a36 | 2020-07-16 15:52:25 +0100 | [diff] [blame] | 270 | const auto result = vquantize<T>(out_f32x4x4, tmp_qua_info); |
| 271 | wrapper::vstore(output_ptr + x, result); |
| 272 | } |
| 273 | |
| 274 | // Compute left-over elements |
| 275 | for(; x < window_end_x; ++x) |
| 276 | { |
| 277 | // Dequantize inputs |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 278 | const T src1 = *(input1_ptr + x); |
| 279 | const T src2 = *(input2_ptr + x); |
| 280 | const float tmp_in1 = Qasymm8QuantizationHelper<T>::dequantize(src1, input1_qua_info); |
| 281 | const float tmp_in2 = Qasymm8QuantizationHelper<T>::dequantize(src2, input2_qua_info); |
Michele Di Giorgio | 40aad9b | 2020-07-22 15:17:43 +0100 | [diff] [blame] | 282 | const float tmp_f = tmp_in1 * tmp_in2; |
Sheri Zhang | a449a36 | 2020-07-16 15:52:25 +0100 | [diff] [blame] | 283 | |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 284 | // Quantize dst |
Michele Di Giorgio | 40aad9b | 2020-07-22 15:17:43 +0100 | [diff] [blame] | 285 | const auto tmp_qua = Qasymm8QuantizationHelper<T>::quantize(tmp_f, tmp_qua_info); |
Sheri Zhang | a449a36 | 2020-07-16 15:52:25 +0100 | [diff] [blame] | 286 | *(output_ptr + x) = tmp_qua; |
| 287 | } |
| 288 | }, |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 289 | input1, input2, dst); |
Sheri Zhang | a449a36 | 2020-07-16 15:52:25 +0100 | [diff] [blame] | 290 | } |
Michele Di Giorgio | 9428a18 | 2020-03-30 14:10:20 +0100 | [diff] [blame] | 291 | } |
| 292 | |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 293 | void mul_saturate_QSYMM16_QSYMM16_QSYMM16(const ITensor *src1, const ITensor *src2, ITensor *out, const Window &window, float scale) |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 294 | { |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 295 | const UniformQuantizationInfo input1_qua_info = src1->info()->quantization_info().uniform(); |
| 296 | const UniformQuantizationInfo input2_qua_info = src2->info()->quantization_info().uniform(); |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 297 | const UniformQuantizationInfo output_qua_info = out->info()->quantization_info().uniform(); |
| 298 | |
| 299 | // Create input windows |
| 300 | Window win = window; |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 301 | Window input1_win = window.broadcast_if_dimension_le_one(src1->info()->tensor_shape()); |
| 302 | Window input2_win = window.broadcast_if_dimension_le_one(src2->info()->tensor_shape()); |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 303 | |
| 304 | // Clear X Dimension on execution window as we handle manually |
| 305 | win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 306 | input1_win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 307 | input2_win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 308 | |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 309 | Iterator input1(src1, input1_win); |
| 310 | Iterator input2(src2, input2_win); |
| 311 | Iterator dst(out, win); |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 312 | |
| 313 | const int window_step_x = 16; |
| 314 | const auto window_start_x = static_cast<int>(window.x().start()); |
| 315 | const auto window_end_x = static_cast<int>(window.x().end()); |
| 316 | |
| 317 | const UniformQuantizationInfo tmp_qua_info = { output_qua_info.scale / scale, output_qua_info.offset }; |
| 318 | |
| 319 | execute_window_loop(win, [&](const Coordinates &) |
| 320 | { |
| 321 | const auto input1_ptr = reinterpret_cast<const qsymm16_t *>(input1.ptr()); |
| 322 | const auto input2_ptr = reinterpret_cast<const qsymm16_t *>(input2.ptr()); |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 323 | const auto output_ptr = reinterpret_cast<qsymm16_t *>(dst.ptr()); |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 324 | |
| 325 | // Compute window_step_x elements per iteration |
| 326 | int x = window_start_x; |
| 327 | for(; x <= (window_end_x - window_step_x); x += window_step_x) |
| 328 | { |
| 329 | const qsymm16x8x2_t input1_q = |
| 330 | { |
| 331 | { |
| 332 | vld1q_s16(input1_ptr + x), |
| 333 | vld1q_s16(input1_ptr + x + 8), |
| 334 | } |
| 335 | }; |
| 336 | const qsymm16x8x2_t input2_q = |
| 337 | { |
| 338 | { |
| 339 | vld1q_s16(input2_ptr + x), |
| 340 | vld1q_s16(input2_ptr + x + 8), |
| 341 | } |
| 342 | }; |
| 343 | |
| 344 | // Dequantize inputs |
| 345 | const float32x4x4_t in1_f32x4x4 = vdequantize(input1_q, input1_qua_info); |
| 346 | const float32x4x4_t in2_f32x4x4 = vdequantize(input2_q, input2_qua_info); |
| 347 | |
| 348 | const float32x4x4_t out_f32x4x4 = |
| 349 | { |
| 350 | vmulq_f32(in1_f32x4x4.val[0], in2_f32x4x4.val[0]), |
| 351 | vmulq_f32(in1_f32x4x4.val[1], in2_f32x4x4.val[1]), |
| 352 | vmulq_f32(in1_f32x4x4.val[2], in2_f32x4x4.val[2]), |
| 353 | vmulq_f32(in1_f32x4x4.val[3], in2_f32x4x4.val[3]), |
| 354 | }; |
| 355 | |
| 356 | const qsymm16x8x2_t result = vquantize_qsymm16(out_f32x4x4, tmp_qua_info); |
| 357 | vst1q_s16(output_ptr + x, result.val[0]); |
| 358 | vst1q_s16(output_ptr + x + 8, result.val[1]); |
| 359 | } |
| 360 | |
| 361 | // Compute left-over elements |
| 362 | for(; x < window_end_x; ++x) |
| 363 | { |
| 364 | // Dequantize inputs |
| 365 | float tmp_in1 = static_cast<float>(*(input1_ptr + x)) * input1_qua_info.scale; |
| 366 | float tmp_in2 = static_cast<float>(*(input2_ptr + x)) * input2_qua_info.scale; |
| 367 | float tmp_f = tmp_in1 * tmp_in2; |
| 368 | |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 369 | // Quantize dst, lrintf() has same rounding mode as vcombine_s16 |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 370 | int32_t tmp = lrintf(tmp_f / tmp_qua_info.scale); |
| 371 | qsymm16_t tmp_qua = static_cast<qsymm16_t>(tmp > SHRT_MAX) ? SHRT_MAX : ((tmp < SHRT_MIN) ? SHRT_MIN : tmp); |
| 372 | *(output_ptr + x) = tmp_qua; |
| 373 | } |
| 374 | }, |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 375 | input1, input2, dst); |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 376 | } |
| 377 | |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 378 | void mul_QSYMM16_QSYMM16_S32(const ITensor *src1, const ITensor *src2, ITensor *out, const Window &window, int scale) |
Michele Di Giorgio | 9428a18 | 2020-03-30 14:10:20 +0100 | [diff] [blame] | 379 | { |
| 380 | ARM_COMPUTE_UNUSED(scale); |
Michele Di Giorgio | 9428a18 | 2020-03-30 14:10:20 +0100 | [diff] [blame] | 381 | |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 382 | // Create input windows |
| 383 | Window win = window; |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 384 | Window input1_win = window.broadcast_if_dimension_le_one(src1->info()->tensor_shape()); |
| 385 | Window input2_win = window.broadcast_if_dimension_le_one(src2->info()->tensor_shape()); |
Michele Di Giorgio | 9428a18 | 2020-03-30 14:10:20 +0100 | [diff] [blame] | 386 | |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 387 | // Clear X Dimension on execution window as we handle manually |
| 388 | win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 389 | input1_win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 390 | input2_win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
Michele Di Giorgio | 9428a18 | 2020-03-30 14:10:20 +0100 | [diff] [blame] | 391 | |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 392 | Iterator input1(src1, input1_win); |
| 393 | Iterator input2(src2, input2_win); |
| 394 | Iterator dst(out, win); |
Michele Di Giorgio | 9428a18 | 2020-03-30 14:10:20 +0100 | [diff] [blame] | 395 | |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 396 | const int window_step_x = 16; |
| 397 | const auto window_start_x = static_cast<int>(window.x().start()); |
| 398 | const auto window_end_x = static_cast<int>(window.x().end()); |
| 399 | |
| 400 | execute_window_loop(win, [&](const Coordinates &) |
| 401 | { |
| 402 | const auto input1_ptr = reinterpret_cast<const qsymm16_t *>(input1.ptr()); |
| 403 | const auto input2_ptr = reinterpret_cast<const qsymm16_t *>(input2.ptr()); |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 404 | const auto output_ptr = reinterpret_cast<int32_t *>(dst.ptr()); |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 405 | |
| 406 | // Compute window_step_x elements per iteration |
| 407 | int x = window_start_x; |
| 408 | for(; x <= (window_end_x - window_step_x); x += window_step_x) |
| 409 | { |
| 410 | const qsymm16x8x2_t input1_q = |
| 411 | { |
| 412 | { |
| 413 | vld1q_s16(input1_ptr + x), |
| 414 | vld1q_s16(input1_ptr + x + 8), |
| 415 | } |
| 416 | }; |
| 417 | const qsymm16x8x2_t input2_q = |
| 418 | { |
| 419 | { |
| 420 | vld1q_s16(input2_ptr + x), |
| 421 | vld1q_s16(input2_ptr + x + 8), |
| 422 | } |
| 423 | }; |
| 424 | |
| 425 | const int32x4x4_t in1_s32 = |
| 426 | { |
| 427 | { |
| 428 | vmovl_s16(vget_low_s16(input1_q.val[0])), |
| 429 | vmovl_s16(vget_high_s16(input1_q.val[0])), |
| 430 | vmovl_s16(vget_low_s16(input1_q.val[1])), |
| 431 | vmovl_s16(vget_high_s16(input1_q.val[1])), |
| 432 | } |
| 433 | }; |
| 434 | const int32x4x4_t in2_s32 = |
| 435 | { |
| 436 | { |
| 437 | vmovl_s16(vget_low_s16(input2_q.val[0])), |
| 438 | vmovl_s16(vget_high_s16(input2_q.val[0])), |
| 439 | vmovl_s16(vget_low_s16(input2_q.val[1])), |
| 440 | vmovl_s16(vget_high_s16(input2_q.val[1])), |
| 441 | } |
| 442 | }; |
| 443 | |
| 444 | const int32x4x4_t result = |
| 445 | { |
| 446 | { |
| 447 | vmulq_s32(in1_s32.val[0], in2_s32.val[0]), |
| 448 | vmulq_s32(in1_s32.val[1], in2_s32.val[1]), |
| 449 | vmulq_s32(in1_s32.val[2], in2_s32.val[2]), |
| 450 | vmulq_s32(in1_s32.val[3], in2_s32.val[3]), |
| 451 | } |
| 452 | }; |
| 453 | |
| 454 | vst1q_s32(output_ptr + x, result.val[0]); |
| 455 | vst1q_s32(output_ptr + x + 4, result.val[1]); |
| 456 | vst1q_s32(output_ptr + x + 8, result.val[2]); |
| 457 | vst1q_s32(output_ptr + x + 12, result.val[3]); |
| 458 | } |
| 459 | |
| 460 | // Compute left-over elements |
| 461 | for(; x < window_end_x; ++x) |
| 462 | { |
| 463 | int32_t tmp = static_cast<int32_t>(*(input1_ptr + x)) * static_cast<int32_t>(*(input2_ptr + x)); |
| 464 | *(output_ptr + x) = tmp; |
| 465 | } |
| 466 | }, |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 467 | input1, input2, dst); |
Manuel Bottini | 7bb56c6 | 2019-06-26 15:17:09 +0100 | [diff] [blame] | 468 | } |
| 469 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 470 | template <bool is_scale255, bool is_sat> |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 471 | void mul_U8_U8_U8(const ITensor *src1, const ITensor *src2, ITensor *out, const Window &window, int n) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 472 | { |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 473 | // Create input windows |
| 474 | Window win = window; |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 475 | Window input1_win = window.broadcast_if_dimension_le_one(src1->info()->tensor_shape()); |
| 476 | Window input2_win = window.broadcast_if_dimension_le_one(src2->info()->tensor_shape()); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 477 | |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 478 | // Clear X Dimension on execution window as we handle manually |
| 479 | win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 480 | input1_win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 481 | input2_win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 482 | |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 483 | Iterator input1(src1, input1_win); |
| 484 | Iterator input2(src2, input2_win); |
| 485 | Iterator dst(out, win); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 486 | |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 487 | const int window_step_x = 16 / sizeof(uint8_t); |
| 488 | const auto window_start_x = static_cast<int>(window.x().start()); |
| 489 | const auto window_end_x = static_cast<int>(window.x().end()); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 490 | |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 491 | execute_window_loop(win, [&](const Coordinates &) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 492 | { |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 493 | const auto input1_ptr = reinterpret_cast<const uint8_t *>(input1.ptr()); |
| 494 | const auto input2_ptr = reinterpret_cast<const uint8_t *>(input2.ptr()); |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 495 | const auto output_ptr = reinterpret_cast<uint8_t *>(dst.ptr()); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 496 | |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 497 | // Compute window_step_x elements per iteration |
| 498 | int x = window_start_x; |
| 499 | for(; x <= (window_end_x - window_step_x); x += window_step_x) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 500 | { |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 501 | const uint8x16_t ta1 = wrapper::vloadq(input1_ptr + x); |
| 502 | const uint8x16_t ta2 = wrapper::vloadq(input2_ptr + x); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 503 | |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 504 | uint16x8_t tmp1_high = vmovl_u8(vget_high_u8(ta1)); |
| 505 | const uint16x8_t tmp2_high = vmovl_u8(vget_high_u8(ta2)); |
| 506 | uint16x8_t tmp1_low = vmovl_u8(vget_low_u8(ta1)); |
| 507 | const uint16x8_t tmp2_low = vmovl_u8(vget_low_u8(ta2)); |
| 508 | |
| 509 | tmp1_high = vmulq_u16(tmp1_high, tmp2_high); |
| 510 | tmp1_low = vmulq_u16(tmp1_low, tmp2_low); |
| 511 | |
| 512 | if(is_scale255) |
| 513 | { |
| 514 | tmp1_high = scale255_U16_U16(tmp1_high); |
| 515 | tmp1_low = scale255_U16_U16(tmp1_low); |
| 516 | } |
| 517 | else |
| 518 | { |
| 519 | const int16x8_t vn = vdupq_n_s16(-n); |
| 520 | |
| 521 | if(is_sat) |
| 522 | { |
| 523 | tmp1_high = vqshlq_u16(tmp1_high, vn); |
| 524 | tmp1_low = vqshlq_u16(tmp1_low, vn); |
| 525 | } |
| 526 | else |
| 527 | { |
| 528 | tmp1_high = vshlq_u16(tmp1_high, vn); |
| 529 | tmp1_low = vshlq_u16(tmp1_low, vn); |
| 530 | } |
| 531 | } |
| 532 | if(is_sat) |
| 533 | { |
Viet-Hoa Do | 0d05b66 | 2022-09-09 15:39:05 +0100 | [diff] [blame] | 534 | vst1q_u8(output_ptr + x, vcombine_u8(vqmovn_u16(tmp1_low), vqmovn_u16(tmp1_high))); |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 535 | } |
| 536 | else |
| 537 | { |
Viet-Hoa Do | 0d05b66 | 2022-09-09 15:39:05 +0100 | [diff] [blame] | 538 | vst1q_u8(output_ptr + x, vcombine_u8(vmovn_u16(tmp1_low), vmovn_u16(tmp1_high))); |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 539 | } |
| 540 | } |
| 541 | |
| 542 | // Compute left-over elements |
| 543 | for(; x < window_end_x; ++x) |
| 544 | { |
| 545 | uint16_t tmp = static_cast<uint16_t>(*(input1_ptr + x)) * static_cast<uint16_t>(*(input2_ptr + x)); |
| 546 | |
| 547 | if(is_scale255) |
| 548 | { |
| 549 | float tmp_f = static_cast<float>(tmp) * scale255_constant; |
| 550 | tmp = static_cast<uint16_t>(tmp_f + 0.5f); |
| 551 | } |
| 552 | else |
| 553 | { |
| 554 | tmp >>= n; |
| 555 | } |
| 556 | if(is_sat && tmp > 255) |
| 557 | { |
| 558 | tmp = 255; |
| 559 | } |
| 560 | *(output_ptr + x) = static_cast<uint8_t>(tmp); |
| 561 | } |
| 562 | }, |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 563 | input1, input2, dst); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | template <bool is_scale255, bool is_sat> |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 567 | inline int16x8_t mul_S16_S16_S16_n_loop(const int16x8_t &src1, const int16x8_t &src2, int n) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 568 | { |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 569 | int32x4_t tmp1_high = vmovl_s16(vget_high_s16(src1)); |
| 570 | const int32x4_t tmp2_high = vmovl_s16(vget_high_s16(src2)); |
| 571 | int32x4_t tmp1_low = vmovl_s16(vget_low_s16(src1)); |
| 572 | const int32x4_t tmp2_low = vmovl_s16(vget_low_s16(src2)); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 573 | |
| 574 | tmp1_high = vmulq_s32(tmp1_high, tmp2_high); |
| 575 | tmp1_low = vmulq_s32(tmp1_low, tmp2_low); |
| 576 | |
| 577 | if(is_scale255) |
| 578 | { |
| 579 | tmp1_high = scale255_S32_S32(tmp1_high); |
| 580 | tmp1_low = scale255_S32_S32(tmp1_low); |
| 581 | } |
| 582 | else |
| 583 | { |
| 584 | // Right shift amount |
| 585 | const int32x4_t vn = vdupq_n_s32(-n); |
| 586 | // Left shift amount |
| 587 | const int32x4_t vnl = vdupq_n_s32(n); |
| 588 | // Calculate conversion bit |
| 589 | const uint32x4_t tmp1_high_u = vreinterpretq_u32_s32(tmp1_high); |
| 590 | const uint32x4_t tmp1_low_u = vreinterpretq_u32_s32(tmp1_low); |
| 591 | const uint32x4_t sign_high = vshrq_n_u32(tmp1_high_u, 31); |
| 592 | const uint32x4_t sign_low = vshrq_n_u32(tmp1_low_u, 31); |
| 593 | const int32x4_t sign_high_s = vreinterpretq_s32_u32(sign_high); |
| 594 | const int32x4_t sign_low_s = vreinterpretq_s32_u32(sign_low); |
| 595 | const int32x4_t convert_high = vsubq_s32(vshlq_s32(sign_high_s, vnl), sign_high_s); |
| 596 | const int32x4_t convert_low = vsubq_s32(vshlq_s32(sign_low_s, vnl), sign_low_s); |
| 597 | if(is_sat) |
| 598 | { |
| 599 | tmp1_high = vqshlq_s32(vaddq_s32(tmp1_high, convert_high), vn); |
| 600 | tmp1_low = vqshlq_s32(vaddq_s32(tmp1_low, convert_low), vn); |
| 601 | } |
| 602 | else |
| 603 | { |
| 604 | tmp1_high = vshlq_s32(vaddq_s32(tmp1_high, convert_high), vn); |
| 605 | tmp1_low = vshlq_s32(vaddq_s32(tmp1_low, convert_low), vn); |
| 606 | } |
| 607 | } |
| 608 | |
| 609 | if(is_sat) |
| 610 | { |
| 611 | return vcombine_s16(vqmovn_s32(tmp1_low), vqmovn_s32(tmp1_high)); |
| 612 | } |
| 613 | else |
| 614 | { |
| 615 | return vcombine_s16(vmovn_s32(tmp1_low), vmovn_s32(tmp1_high)); |
| 616 | } |
| 617 | } |
| 618 | |
| 619 | template <bool is_scale255, bool is_sat> |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 620 | inline int16x8x2_t mul_S16_S16_S16_n_k(const int16x8x2_t &src1, const int16x8x2_t &src2, int n) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 621 | { |
| 622 | const int16x8x2_t result = |
| 623 | { |
| 624 | { |
| 625 | // First 8 elements |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 626 | mul_S16_S16_S16_n_loop<is_scale255, is_sat>(src1.val[0], src2.val[0], n), |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 627 | // Second 8 elements |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 628 | mul_S16_S16_S16_n_loop<is_scale255, is_sat>(src1.val[1], src2.val[1], n) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 629 | } |
| 630 | }; |
| 631 | |
| 632 | return result; |
| 633 | } |
| 634 | |
| 635 | template <bool is_scale255, bool is_sat> |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 636 | void mul_S16_S16_S16(const ITensor *src1, const ITensor *src2, ITensor *out, const Window &window, int n) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 637 | { |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 638 | // Create input windows |
| 639 | Window win = window; |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 640 | Window input1_win = window.broadcast_if_dimension_le_one(src1->info()->tensor_shape()); |
| 641 | Window input2_win = window.broadcast_if_dimension_le_one(src2->info()->tensor_shape()); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 642 | |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 643 | // Clear X Dimension on execution window as we handle manually |
| 644 | win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 645 | input1_win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 646 | input2_win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 647 | |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 648 | Iterator input1(src1, input1_win); |
| 649 | Iterator input2(src2, input2_win); |
| 650 | Iterator dst(out, win); |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 651 | |
| 652 | const int window_step_x = 16; |
| 653 | const auto window_start_x = static_cast<int>(window.x().start()); |
| 654 | const auto window_end_x = static_cast<int>(window.x().end()); |
| 655 | |
| 656 | execute_window_loop(win, [&](const Coordinates &) |
| 657 | { |
| 658 | const auto input1_ptr = reinterpret_cast<const int16_t *>(input1.ptr()); |
| 659 | const auto input2_ptr = reinterpret_cast<const int16_t *>(input2.ptr()); |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 660 | const auto output_ptr = reinterpret_cast<int16_t *>(dst.ptr()); |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 661 | |
| 662 | // Compute window_step_x elements per iteration |
| 663 | int x = window_start_x; |
| 664 | for(; x <= (window_end_x - window_step_x); x += window_step_x) |
| 665 | { |
| 666 | const int16x8x2_t ta1 = |
| 667 | { |
| 668 | { |
| 669 | vld1q_s16(input1_ptr + x), |
| 670 | vld1q_s16(input1_ptr + x + 8), |
| 671 | } |
| 672 | }; |
| 673 | const int16x8x2_t ta2 = |
| 674 | { |
| 675 | { |
| 676 | vld1q_s16(input2_ptr + x), |
| 677 | vld1q_s16(input2_ptr + x + 8), |
| 678 | } |
| 679 | }; |
| 680 | const int16x8x2_t result = mul_S16_S16_S16_n_k<is_scale255, is_sat>(ta1, ta2, n); |
| 681 | |
| 682 | vst1q_s16(output_ptr + x, result.val[0]); |
| 683 | vst1q_s16(output_ptr + x + 8, result.val[1]); |
| 684 | } |
| 685 | |
| 686 | // Compute left-over elements |
| 687 | for(; x < window_end_x; ++x) |
| 688 | { |
| 689 | int32_t tmp = static_cast<int32_t>(*(input1_ptr + x)) * static_cast<int32_t>(*(input2_ptr + x)); |
| 690 | |
| 691 | if(is_scale255) |
| 692 | { |
| 693 | float tmp_f = static_cast<float>(tmp) * scale255_constant; |
| 694 | |
| 695 | tmp = static_cast<int32_t>(tmp_f + 0.5f); |
| 696 | } |
| 697 | else |
| 698 | { |
| 699 | if(tmp >= 0) |
| 700 | { |
| 701 | tmp >>= n; |
| 702 | } |
| 703 | else |
| 704 | { |
| 705 | uint32_t mask = (1u << n) - 1; |
| 706 | tmp = (tmp + static_cast<int32_t>(mask)) >> n; |
| 707 | } |
| 708 | } |
| 709 | if(is_sat) |
| 710 | { |
| 711 | tmp = (tmp > SHRT_MAX) ? SHRT_MAX : ((tmp < SHRT_MIN) ? SHRT_MIN : tmp); |
| 712 | } |
| 713 | *(output_ptr + x) = static_cast<int16_t>(tmp); |
| 714 | } |
| 715 | }, |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 716 | input1, input2, dst); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 717 | } |
| 718 | |
SiCong Li | bb88f89 | 2020-08-28 11:18:47 +0100 | [diff] [blame] | 719 | template <bool is_sat> |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 720 | inline int32x4_t mul_S32_S32_S32_n_loop(const int32x4_t &src1, const int32x4_t &src2, int n) |
SiCong Li | bb88f89 | 2020-08-28 11:18:47 +0100 | [diff] [blame] | 721 | { |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 722 | const int32x2_t input1_1 = vget_low_s32(src1); |
| 723 | const int32x2_t input2_1 = vget_low_s32(src2); |
| 724 | const int32x2_t input1_2 = vget_high_s32(src1); |
| 725 | const int32x2_t input2_2 = vget_high_s32(src2); |
SiCong Li | bb88f89 | 2020-08-28 11:18:47 +0100 | [diff] [blame] | 726 | |
| 727 | int64x2_t tmp_1 = vmull_s32(input1_1, input2_1); |
| 728 | int64x2_t tmp_2 = vmull_s32(input1_2, input2_2); |
| 729 | |
| 730 | // Apply scaling, conversion and rounding (round to zero) |
| 731 | // Right shift amount |
| 732 | const int64x2_t vn = vdupq_n_s64(-n); |
| 733 | // Left shift amount |
| 734 | const int64x2_t vnl = vdupq_n_s64(n); |
| 735 | // Calculate conversion bit |
| 736 | const uint64x2_t tmp_1_u = vreinterpretq_u64_s64(tmp_1); |
| 737 | const uint64x2_t sign_1 = vshrq_n_u64(tmp_1_u, 63); |
| 738 | const int64x2_t sign_1_s = vreinterpretq_s64_u64(sign_1); |
| 739 | const int64x2_t convert_1 = vsubq_s64(vshlq_s64(sign_1_s, vnl), sign_1_s); |
| 740 | |
| 741 | const uint64x2_t tmp_2_u = vreinterpretq_u64_s64(tmp_2); |
| 742 | const uint64x2_t sign_2 = vshrq_n_u64(tmp_2_u, 63); |
| 743 | const int64x2_t sign_2_s = vreinterpretq_s64_u64(sign_2); |
| 744 | const int64x2_t convert_2 = vsubq_s64(vshlq_s64(sign_2_s, vnl), sign_2_s); |
| 745 | if(is_sat) |
| 746 | { |
| 747 | tmp_1 = vqshlq_s64(vaddq_s64(tmp_1, convert_1), vn); |
| 748 | tmp_2 = vqshlq_s64(vaddq_s64(tmp_2, convert_2), vn); |
| 749 | return vcombine_s32(vqmovn_s64(tmp_1), vqmovn_s64(tmp_2)); |
| 750 | } |
| 751 | else |
| 752 | { |
| 753 | tmp_1 = vshlq_s64(vaddq_s64(tmp_1, convert_1), vn); |
| 754 | tmp_2 = vshlq_s64(vaddq_s64(tmp_2, convert_2), vn); |
| 755 | return vcombine_s32(vmovn_s64(tmp_1), vmovn_s64(tmp_2)); |
| 756 | } |
| 757 | } |
| 758 | |
| 759 | template <bool is_sat> |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 760 | inline int32x4x2_t mul_S32_S32_S32_n_k(const int32x4x2_t &src1, const int32x4x2_t &src2, int n) |
SiCong Li | bb88f89 | 2020-08-28 11:18:47 +0100 | [diff] [blame] | 761 | { |
| 762 | const int32x4x2_t result = |
| 763 | { |
| 764 | { |
| 765 | // First 4 elements |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 766 | mul_S32_S32_S32_n_loop<is_sat>(src1.val[0], src2.val[0], n), |
SiCong Li | bb88f89 | 2020-08-28 11:18:47 +0100 | [diff] [blame] | 767 | // Second 4 elements |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 768 | mul_S32_S32_S32_n_loop<is_sat>(src1.val[1], src2.val[1], n) |
SiCong Li | bb88f89 | 2020-08-28 11:18:47 +0100 | [diff] [blame] | 769 | } |
| 770 | }; |
| 771 | |
| 772 | return result; |
| 773 | } |
| 774 | |
| 775 | template <bool is_sat> |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 776 | void mul_S32_S32_S32(const ITensor *src1, const ITensor *src2, ITensor *out, const Window &window, int n) |
SiCong Li | bb88f89 | 2020-08-28 11:18:47 +0100 | [diff] [blame] | 777 | { |
| 778 | // Create input windows |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 779 | Window input1_win = window.broadcast_if_dimension_le_one(src1->info()->tensor_shape()); |
| 780 | Window input2_win = window.broadcast_if_dimension_le_one(src2->info()->tensor_shape()); |
SiCong Li | bb88f89 | 2020-08-28 11:18:47 +0100 | [diff] [blame] | 781 | |
| 782 | // Clear X Dimension on execution window as we handle manually |
SiCong Li | d6d1b36 | 2020-09-24 17:34:23 +0100 | [diff] [blame] | 783 | Window win = window; |
SiCong Li | bb88f89 | 2020-08-28 11:18:47 +0100 | [diff] [blame] | 784 | win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
SiCong Li | bb88f89 | 2020-08-28 11:18:47 +0100 | [diff] [blame] | 785 | |
SiCong Li | d6d1b36 | 2020-09-24 17:34:23 +0100 | [diff] [blame] | 786 | const int window_step_x = 8; |
| 787 | const auto window_start_x = static_cast<int>(window.x().start()); |
| 788 | const auto window_end_x = static_cast<int>(window.x().end()); |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 789 | const bool is_broadcast_across_x = src1->info()->tensor_shape().x() != src2->info()->tensor_shape().x(); |
SiCong Li | bb88f89 | 2020-08-28 11:18:47 +0100 | [diff] [blame] | 790 | |
SiCong Li | d6d1b36 | 2020-09-24 17:34:23 +0100 | [diff] [blame] | 791 | if(is_broadcast_across_x) |
SiCong Li | bb88f89 | 2020-08-28 11:18:47 +0100 | [diff] [blame] | 792 | { |
SiCong Li | d6d1b36 | 2020-09-24 17:34:23 +0100 | [diff] [blame] | 793 | const bool is_broadcast_input_2 = input2_win.x().step() == 0; |
| 794 | Window broadcast_win = is_broadcast_input_2 ? input2_win : input1_win; |
| 795 | Window non_broadcast_win = !is_broadcast_input_2 ? input2_win : input1_win; |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 796 | const ITensor *broadcast_tensor = is_broadcast_input_2 ? src2 : src1; |
| 797 | const ITensor *non_broadcast_tensor = !is_broadcast_input_2 ? src2 : src1; |
SiCong Li | bb88f89 | 2020-08-28 11:18:47 +0100 | [diff] [blame] | 798 | |
SiCong Li | d6d1b36 | 2020-09-24 17:34:23 +0100 | [diff] [blame] | 799 | // Clear X Dimension on execution window as we handle manually |
| 800 | non_broadcast_win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 801 | |
| 802 | Iterator broadcast_input(broadcast_tensor, broadcast_win); |
| 803 | Iterator non_broadcast_input(non_broadcast_tensor, non_broadcast_win); |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 804 | Iterator dst(out, win); |
SiCong Li | d6d1b36 | 2020-09-24 17:34:23 +0100 | [diff] [blame] | 805 | |
| 806 | execute_window_loop(win, [&](const Coordinates &) |
SiCong Li | bb88f89 | 2020-08-28 11:18:47 +0100 | [diff] [blame] | 807 | { |
SiCong Li | d6d1b36 | 2020-09-24 17:34:23 +0100 | [diff] [blame] | 808 | const auto non_broadcast_input_ptr = reinterpret_cast<const int32_t *>(non_broadcast_input.ptr()); |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 809 | const auto output_ptr = reinterpret_cast<int32_t *>(dst.ptr()); |
SiCong Li | bb88f89 | 2020-08-28 11:18:47 +0100 | [diff] [blame] | 810 | |
SiCong Li | d6d1b36 | 2020-09-24 17:34:23 +0100 | [diff] [blame] | 811 | const int32_t broadcast_value = *reinterpret_cast<const int32_t *>(broadcast_input.ptr()); |
| 812 | const auto broadcast_value_vec = vdupq_n_s32(broadcast_value); |
SiCong Li | bb88f89 | 2020-08-28 11:18:47 +0100 | [diff] [blame] | 813 | |
SiCong Li | d6d1b36 | 2020-09-24 17:34:23 +0100 | [diff] [blame] | 814 | // Compute window_step_x elements per iteration |
| 815 | int x = window_start_x; |
| 816 | for(; x <= (window_end_x - window_step_x); x += window_step_x) |
| 817 | { |
| 818 | const int32x4x2_t broadcast_v = |
| 819 | { |
| 820 | { |
| 821 | broadcast_value_vec, |
| 822 | broadcast_value_vec, |
| 823 | } |
| 824 | }; |
| 825 | const int32x4x2_t non_broadcast_v = |
| 826 | { |
| 827 | { |
| 828 | vld1q_s32(non_broadcast_input_ptr + x), |
| 829 | vld1q_s32(non_broadcast_input_ptr + x + 4), |
| 830 | } |
| 831 | }; |
| 832 | const int32x4x2_t result = mul_S32_S32_S32_n_k<is_sat>(broadcast_v, non_broadcast_v, n); |
| 833 | |
| 834 | vst1q_s32(output_ptr + x, result.val[0]); |
| 835 | vst1q_s32(output_ptr + x + 4, result.val[1]); |
| 836 | } |
| 837 | |
| 838 | // Compute left-over elements |
| 839 | for(; x < window_end_x; ++x) |
| 840 | { |
| 841 | int64_t tmp = static_cast<int64_t>(broadcast_value) * static_cast<int64_t>(*(non_broadcast_input_ptr + x)); |
| 842 | |
| 843 | if(tmp >= 0) |
| 844 | { |
| 845 | tmp >>= n; |
| 846 | } |
| 847 | else |
| 848 | { |
Michalis Spyrou | 7f8caf7 | 2021-05-13 13:35:30 +0100 | [diff] [blame] | 849 | uint64_t mask = ((uint64_t)1u << n) - 1; |
SiCong Li | d6d1b36 | 2020-09-24 17:34:23 +0100 | [diff] [blame] | 850 | tmp = (tmp + static_cast<int64_t>(mask)) >> n; |
| 851 | } |
| 852 | if(is_sat) |
| 853 | { |
| 854 | tmp = utility::clamp<int64_t, int32_t>(tmp); |
| 855 | } |
| 856 | *(output_ptr + x) = static_cast<int32_t>(tmp); |
| 857 | } |
| 858 | }, |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 859 | broadcast_input, non_broadcast_input, dst); |
SiCong Li | d6d1b36 | 2020-09-24 17:34:23 +0100 | [diff] [blame] | 860 | } |
| 861 | else |
| 862 | { |
| 863 | // Clear X Dimension on execution window as we handle manually |
| 864 | input1_win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 865 | input2_win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 866 | |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 867 | Iterator input1(src1, input1_win); |
| 868 | Iterator input2(src2, input2_win); |
| 869 | Iterator dst(out, win); |
SiCong Li | d6d1b36 | 2020-09-24 17:34:23 +0100 | [diff] [blame] | 870 | |
| 871 | execute_window_loop(win, [&](const Coordinates &) |
SiCong Li | bb88f89 | 2020-08-28 11:18:47 +0100 | [diff] [blame] | 872 | { |
SiCong Li | d6d1b36 | 2020-09-24 17:34:23 +0100 | [diff] [blame] | 873 | const auto input1_ptr = reinterpret_cast<const int32_t *>(input1.ptr()); |
| 874 | const auto input2_ptr = reinterpret_cast<const int32_t *>(input2.ptr()); |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 875 | const auto output_ptr = reinterpret_cast<int32_t *>(dst.ptr()); |
SiCong Li | bb88f89 | 2020-08-28 11:18:47 +0100 | [diff] [blame] | 876 | |
SiCong Li | d6d1b36 | 2020-09-24 17:34:23 +0100 | [diff] [blame] | 877 | // Compute window_step_x elements per iteration |
| 878 | int x = window_start_x; |
| 879 | for(; x <= (window_end_x - window_step_x); x += window_step_x) |
SiCong Li | bb88f89 | 2020-08-28 11:18:47 +0100 | [diff] [blame] | 880 | { |
SiCong Li | d6d1b36 | 2020-09-24 17:34:23 +0100 | [diff] [blame] | 881 | const int32x4x2_t ta1 = |
| 882 | { |
| 883 | { |
| 884 | vld1q_s32(input1_ptr + x), |
| 885 | vld1q_s32(input1_ptr + x + 4), |
| 886 | } |
| 887 | }; |
| 888 | const int32x4x2_t ta2 = |
| 889 | { |
| 890 | { |
| 891 | vld1q_s32(input2_ptr + x), |
| 892 | vld1q_s32(input2_ptr + x + 4), |
| 893 | } |
| 894 | }; |
| 895 | const int32x4x2_t result = mul_S32_S32_S32_n_k<is_sat>(ta1, ta2, n); |
| 896 | |
| 897 | vst1q_s32(output_ptr + x, result.val[0]); |
| 898 | vst1q_s32(output_ptr + x + 4, result.val[1]); |
SiCong Li | bb88f89 | 2020-08-28 11:18:47 +0100 | [diff] [blame] | 899 | } |
SiCong Li | d6d1b36 | 2020-09-24 17:34:23 +0100 | [diff] [blame] | 900 | |
| 901 | // Compute left-over elements |
| 902 | for(; x < window_end_x; ++x) |
SiCong Li | bb88f89 | 2020-08-28 11:18:47 +0100 | [diff] [blame] | 903 | { |
SiCong Li | d6d1b36 | 2020-09-24 17:34:23 +0100 | [diff] [blame] | 904 | int64_t tmp = static_cast<int64_t>(*(input1_ptr + x)) * static_cast<int64_t>(*(input2_ptr + x)); |
| 905 | |
| 906 | if(tmp >= 0) |
| 907 | { |
| 908 | tmp >>= n; |
| 909 | } |
| 910 | else |
| 911 | { |
Michalis Spyrou | 7f8caf7 | 2021-05-13 13:35:30 +0100 | [diff] [blame] | 912 | uint64_t mask = ((uint64_t)1u << n) - 1; |
SiCong Li | d6d1b36 | 2020-09-24 17:34:23 +0100 | [diff] [blame] | 913 | tmp = (tmp + static_cast<int64_t>(mask)) >> n; |
| 914 | } |
| 915 | if(is_sat) |
| 916 | { |
| 917 | tmp = utility::clamp<int64_t, int32_t>(tmp); |
| 918 | } |
| 919 | *(output_ptr + x) = static_cast<int32_t>(tmp); |
SiCong Li | bb88f89 | 2020-08-28 11:18:47 +0100 | [diff] [blame] | 920 | } |
SiCong Li | d6d1b36 | 2020-09-24 17:34:23 +0100 | [diff] [blame] | 921 | }, |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 922 | input1, input2, dst); |
SiCong Li | d6d1b36 | 2020-09-24 17:34:23 +0100 | [diff] [blame] | 923 | } |
SiCong Li | bb88f89 | 2020-08-28 11:18:47 +0100 | [diff] [blame] | 924 | } |
| 925 | |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 926 | void mul_F32_F32_F32(const ITensor *src1, const ITensor *src2, ITensor *out, const Window &window, float scale) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 927 | { |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 928 | // Create input windows |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 929 | Window input1_win = window.broadcast_if_dimension_le_one(src1->info()->tensor_shape()); |
| 930 | Window input2_win = window.broadcast_if_dimension_le_one(src2->info()->tensor_shape()); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 931 | |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 932 | // Clear X Dimension on execution window as we handle manually |
| 933 | Window win = window; |
| 934 | win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 935 | |
| 936 | constexpr int window_step_x = 16 / sizeof(float); |
| 937 | const auto window_start_x = static_cast<int>(window.x().start()); |
| 938 | const auto window_end_x = static_cast<int>(window.x().end()); |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 939 | const bool is_broadcast_across_x = src1->info()->tensor_shape().x() != src2->info()->tensor_shape().x(); |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 940 | |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 941 | using ExactTagType = typename wrapper::traits::neon_vector<float, window_step_x>::tag_type; |
| 942 | |
| 943 | if(is_broadcast_across_x) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 944 | { |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 945 | const bool is_broadcast_input_2 = input2_win.x().step() == 0; |
| 946 | Window broadcast_win = is_broadcast_input_2 ? input2_win : input1_win; |
| 947 | Window non_broadcast_win = !is_broadcast_input_2 ? input2_win : input1_win; |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 948 | const ITensor *broadcast_tensor = is_broadcast_input_2 ? src2 : src1; |
| 949 | const ITensor *non_broadcast_tensor = !is_broadcast_input_2 ? src2 : src1; |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 950 | |
| 951 | // Clear X Dimension on execution window as we handle manually |
| 952 | non_broadcast_win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 953 | |
| 954 | Iterator broadcast_input(broadcast_tensor, broadcast_win); |
| 955 | Iterator non_broadcast_input(non_broadcast_tensor, non_broadcast_win); |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 956 | Iterator dst(out, win); |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 957 | |
| 958 | execute_window_loop(win, [&](const Coordinates &) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 959 | { |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 960 | const auto non_broadcast_input_ptr = reinterpret_cast<const float *>(non_broadcast_input.ptr()); |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 961 | const auto output_ptr = reinterpret_cast<float *>(dst.ptr()); |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 962 | |
| 963 | const float broadcast_value = *reinterpret_cast<const float *>(broadcast_input.ptr()); |
| 964 | const auto broadcast_value_vec = wrapper::vdup_n(broadcast_value, ExactTagType{}); |
| 965 | const auto scale_vec = wrapper::vdup_n(scale, ExactTagType{}); |
| 966 | |
| 967 | // Compute window_step_x elements per iteration |
| 968 | int x = window_start_x; |
| 969 | for(; x <= (window_end_x - window_step_x); x += window_step_x) |
| 970 | { |
| 971 | const auto non_broadcast_v = wrapper::vloadq(non_broadcast_input_ptr + x); |
| 972 | auto res = wrapper::vmul(wrapper::vmul(broadcast_value_vec, non_broadcast_v), scale_vec); |
| 973 | wrapper::vstore(output_ptr + x, res); |
| 974 | } |
| 975 | |
| 976 | // Compute left-over elements |
| 977 | for(; x < window_end_x; ++x) |
| 978 | { |
| 979 | const auto non_broadcast_v = *(non_broadcast_input_ptr + x); |
| 980 | *(output_ptr + x) = broadcast_value * non_broadcast_v * scale; |
| 981 | } |
| 982 | }, |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 983 | broadcast_input, non_broadcast_input, dst); |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 984 | } |
| 985 | else |
| 986 | { |
| 987 | // Clear X Dimension on execution window as we handle manually |
| 988 | input1_win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 989 | input2_win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 990 | |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 991 | Iterator input1(src1, input1_win); |
| 992 | Iterator input2(src2, input2_win); |
| 993 | Iterator dst(out, win); |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 994 | |
| 995 | execute_window_loop(win, [&](const Coordinates &) |
| 996 | { |
| 997 | const auto input1_ptr = reinterpret_cast<const float *>(input1.ptr()); |
| 998 | const auto input2_ptr = reinterpret_cast<const float *>(input2.ptr()); |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 999 | const auto output_ptr = reinterpret_cast<float *>(dst.ptr()); |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 1000 | |
| 1001 | // Compute window_step_x elements per iteration |
| 1002 | int x = window_start_x; |
| 1003 | for(; x <= (window_end_x - window_step_x); x += window_step_x) |
| 1004 | { |
| 1005 | const auto ta1 = wrapper::vloadq(input1_ptr + x); |
| 1006 | const auto ta2 = wrapper::vloadq(input2_ptr + x); |
| 1007 | const auto scale_vec = wrapper::vdup_n(scale, ExactTagType{}); |
| 1008 | const auto res = wrapper::vmul(wrapper::vmul(ta1, ta2), scale_vec); |
| 1009 | wrapper::vstore(output_ptr + x, res); |
| 1010 | } |
| 1011 | |
| 1012 | // Compute left-over elements |
| 1013 | for(; x < window_end_x; ++x) |
| 1014 | { |
| 1015 | const auto ta1 = *(input1_ptr + x); |
| 1016 | const auto ta2 = *(input2_ptr + x); |
| 1017 | *(output_ptr + x) = ta1 * ta2 * scale; |
| 1018 | } |
| 1019 | }, |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1020 | input1, input2, dst); |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 1021 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1022 | } |
| 1023 | |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1024 | void c_mul_F32_F32_F32_n(const ITensor *src1, const ITensor *src2, ITensor *out, const Window &window) |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 1025 | { |
Sheri Zhang | 4d91dc6 | 2020-09-23 11:22:50 +0100 | [diff] [blame] | 1026 | // Create input windows |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1027 | Window input1_win = window.broadcast_if_dimension_le_one(src1->info()->tensor_shape()); |
| 1028 | Window input2_win = window.broadcast_if_dimension_le_one(src2->info()->tensor_shape()); |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 1029 | |
Sheri Zhang | 4d91dc6 | 2020-09-23 11:22:50 +0100 | [diff] [blame] | 1030 | // Clear X Dimension on execution window as we handle manually |
| 1031 | Window win = window; |
| 1032 | win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 1033 | |
Sheri Zhang | 4d91dc6 | 2020-09-23 11:22:50 +0100 | [diff] [blame] | 1034 | constexpr int window_step_x = 8 / sizeof(float); |
| 1035 | const auto window_start_x = static_cast<int>(window.x().start()); |
| 1036 | const auto window_end_x = static_cast<int>(window.x().end()); |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1037 | const bool is_broadcast_across_x = src1->info()->tensor_shape().x() != src2->info()->tensor_shape().x(); |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 1038 | |
Sheri Zhang | 2cb05d9 | 2020-11-09 15:12:32 +0000 | [diff] [blame] | 1039 | using ExactTagType = typename wrapper::traits::neon_vector<float, 2>::tag_type; |
| 1040 | |
Sheri Zhang | 4d91dc6 | 2020-09-23 11:22:50 +0100 | [diff] [blame] | 1041 | if(is_broadcast_across_x) |
| 1042 | { |
| 1043 | const bool is_broadcast_input_2 = input2_win.x().step() == 0; |
| 1044 | Window broadcast_win = is_broadcast_input_2 ? input2_win : input1_win; |
| 1045 | Window non_broadcast_win = !is_broadcast_input_2 ? input2_win : input1_win; |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1046 | const ITensor *broadcast_tensor = is_broadcast_input_2 ? src2 : src1; |
| 1047 | const ITensor *non_broadcast_tensor = !is_broadcast_input_2 ? src2 : src1; |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 1048 | |
Sheri Zhang | 4d91dc6 | 2020-09-23 11:22:50 +0100 | [diff] [blame] | 1049 | // Clear X Dimension on execution window as we handle manually |
| 1050 | non_broadcast_win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 1051 | |
Sheri Zhang | 4d91dc6 | 2020-09-23 11:22:50 +0100 | [diff] [blame] | 1052 | Iterator broadcast_input(broadcast_tensor, broadcast_win); |
| 1053 | Iterator non_broadcast_input(non_broadcast_tensor, non_broadcast_win); |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1054 | Iterator dst(out, win); |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 1055 | |
Sheri Zhang | 4d91dc6 | 2020-09-23 11:22:50 +0100 | [diff] [blame] | 1056 | execute_window_loop(win, [&](const Coordinates &) |
| 1057 | { |
| 1058 | const auto non_broadcast_input_ptr = reinterpret_cast<const float *>(non_broadcast_input.ptr()); |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1059 | const auto output_ptr = reinterpret_cast<float *>(dst.ptr()); |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 1060 | |
Sheri Zhang | 4d91dc6 | 2020-09-23 11:22:50 +0100 | [diff] [blame] | 1061 | const float broadcast_value = *reinterpret_cast<const float *>(broadcast_input.ptr()); |
| 1062 | |
Sheri Zhang | 2cb05d9 | 2020-11-09 15:12:32 +0000 | [diff] [blame] | 1063 | // Compute window_step_x elements per iteration |
Sheri Zhang | 4d91dc6 | 2020-09-23 11:22:50 +0100 | [diff] [blame] | 1064 | int x = window_start_x; |
Sheri Zhang | 2cb05d9 | 2020-11-09 15:12:32 +0000 | [diff] [blame] | 1065 | for(; x <= (window_end_x - window_step_x); x += window_step_x) |
| 1066 | { |
| 1067 | const auto a = wrapper::vloadq(non_broadcast_input_ptr + 2 * x); |
| 1068 | float32x4_t b = vdupq_n_f32(broadcast_value); |
| 1069 | |
| 1070 | const float32x4_t mask = { -1.0f, 1.0f, -1.0f, 1.0f }; |
| 1071 | const float32x2_t tmp00 = wrapper::vdup_n(wrapper::vgetlane(a, 0), ExactTagType{}); |
| 1072 | const float32x2_t tmp01 = wrapper::vdup_n(wrapper::vgetlane(a, 1), ExactTagType{}); |
| 1073 | const float32x2_t tmp10 = wrapper::vdup_n(wrapper::vgetlane(a, 2), ExactTagType{}); |
| 1074 | const float32x2_t tmp11 = wrapper::vdup_n(wrapper::vgetlane(a, 3), ExactTagType{}); |
| 1075 | |
| 1076 | const float32x4_t tmp0 = wrapper::vcombine(tmp00, tmp10); |
| 1077 | const float32x4_t tmp1 = wrapper::vcombine(tmp01, tmp11); |
| 1078 | |
| 1079 | float32x4_t res = wrapper::vmul(tmp0, b); |
| 1080 | b = wrapper::vmul(b, mask); |
| 1081 | |
| 1082 | res = wrapper::vmla(res, tmp1, b); |
| 1083 | wrapper::vstore(output_ptr + 2 * x, res); |
| 1084 | } |
| 1085 | |
Sheri Zhang | 4d91dc6 | 2020-09-23 11:22:50 +0100 | [diff] [blame] | 1086 | // Compute left-over elements |
| 1087 | for(; x < window_end_x; ++x) |
| 1088 | { |
Sheri Zhang | 2cb05d9 | 2020-11-09 15:12:32 +0000 | [diff] [blame] | 1089 | const auto non_broadcast_value0 = *(non_broadcast_input_ptr + 2 * x); |
| 1090 | const auto non_broadcast_value1 = *(non_broadcast_input_ptr + 2 * x + 1); |
| 1091 | auto res1 = broadcast_value * (non_broadcast_value0 - non_broadcast_value1); |
| 1092 | auto res2 = broadcast_value * (non_broadcast_value1 + non_broadcast_value0); |
| 1093 | *(output_ptr + 2 * x) = res1; |
| 1094 | *(output_ptr + 2 * x + 1) = res2; |
Sheri Zhang | 4d91dc6 | 2020-09-23 11:22:50 +0100 | [diff] [blame] | 1095 | } |
| 1096 | }, |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1097 | broadcast_input, non_broadcast_input, dst); |
Sheri Zhang | 4d91dc6 | 2020-09-23 11:22:50 +0100 | [diff] [blame] | 1098 | } |
| 1099 | else |
| 1100 | { |
| 1101 | // Clear X Dimension on execution window as we handle manually |
| 1102 | input1_win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 1103 | input2_win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 1104 | |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1105 | Iterator input1(src1, input1_win); |
| 1106 | Iterator input2(src2, input2_win); |
| 1107 | Iterator dst(out, win); |
Sheri Zhang | 4d91dc6 | 2020-09-23 11:22:50 +0100 | [diff] [blame] | 1108 | |
| 1109 | execute_window_loop(win, [&](const Coordinates &) |
| 1110 | { |
| 1111 | const auto input1_ptr = reinterpret_cast<const float *>(input1.ptr()); |
| 1112 | const auto input2_ptr = reinterpret_cast<const float *>(input2.ptr()); |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1113 | const auto output_ptr = reinterpret_cast<float *>(dst.ptr()); |
Sheri Zhang | 4d91dc6 | 2020-09-23 11:22:50 +0100 | [diff] [blame] | 1114 | |
Sheri Zhang | 4d91dc6 | 2020-09-23 11:22:50 +0100 | [diff] [blame] | 1115 | // Compute window_step_x elements per iteration |
| 1116 | int x = window_start_x; |
| 1117 | for(; x <= (window_end_x - window_step_x); x += window_step_x) |
| 1118 | { |
| 1119 | const float32x4_t a = wrapper::vloadq(input1_ptr + 2 * x); |
| 1120 | float32x4_t b = wrapper::vloadq(input2_ptr + 2 * x); |
| 1121 | |
| 1122 | const float32x4_t mask = { -1.0f, 1.0f, -1.0f, 1.0f }; |
| 1123 | const float32x2_t tmp00 = wrapper::vdup_n(wrapper::vgetlane(a, 0), ExactTagType{}); |
| 1124 | const float32x2_t tmp01 = wrapper::vdup_n(wrapper::vgetlane(a, 1), ExactTagType{}); |
| 1125 | const float32x2_t tmp10 = wrapper::vdup_n(wrapper::vgetlane(a, 2), ExactTagType{}); |
| 1126 | const float32x2_t tmp11 = wrapper::vdup_n(wrapper::vgetlane(a, 3), ExactTagType{}); |
| 1127 | |
| 1128 | const float32x4_t tmp0 = wrapper::vcombine(tmp00, tmp10); |
| 1129 | const float32x4_t tmp1 = wrapper::vcombine(tmp01, tmp11); |
| 1130 | |
| 1131 | float32x4_t res = wrapper::vmul(tmp0, b); |
| 1132 | |
| 1133 | b = wrapper::vrev64(b); |
| 1134 | b = wrapper::vmul(b, mask); |
| 1135 | |
| 1136 | res = wrapper::vmla(res, tmp1, b); |
| 1137 | wrapper::vstore(output_ptr + 2 * x, res); |
| 1138 | } |
| 1139 | |
| 1140 | // Compute left-over elements |
| 1141 | for(; x < window_end_x; ++x) |
| 1142 | { |
| 1143 | const auto a0 = *(input1_ptr + 2 * x); |
| 1144 | const auto a1 = *(input1_ptr + 2 * x + 1); |
| 1145 | const auto b0 = *(input2_ptr + 2 * x); |
| 1146 | const auto b1 = *(input2_ptr + 2 * x + 1); |
| 1147 | auto res1 = a0 * b0 - a1 * b1; |
| 1148 | auto res2 = a0 * b1 + a1 * b0; |
| 1149 | *(output_ptr + 2 * x) = res1; |
| 1150 | *(output_ptr + 2 * x + 1) = res2; |
| 1151 | } |
| 1152 | }, |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1153 | input1, input2, dst); |
Sheri Zhang | 4d91dc6 | 2020-09-23 11:22:50 +0100 | [diff] [blame] | 1154 | } |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 1155 | } |
| 1156 | |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 1157 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1158 | void mul_F16_F16_F16(const ITensor *src1, const ITensor *src2, ITensor *out, const Window &window, float scale) |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 1159 | { |
| 1160 | // Create input windows |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1161 | Window input1_win = window.broadcast_if_dimension_le_one(src1->info()->tensor_shape()); |
| 1162 | Window input2_win = window.broadcast_if_dimension_le_one(src2->info()->tensor_shape()); |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 1163 | |
| 1164 | // Clear X Dimension on execution window as we handle manually |
Pablo Marquez Tello | c727d52 | 2021-01-27 14:16:13 +0000 | [diff] [blame] | 1165 | Window win = window; |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 1166 | win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
Pablo Marquez Tello | c727d52 | 2021-01-27 14:16:13 +0000 | [diff] [blame] | 1167 | constexpr int window_step_x = 16; |
| 1168 | const auto window_start_x = static_cast<int>(window.x().start()); |
| 1169 | const auto window_end_x = static_cast<int>(window.x().end()); |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1170 | const bool is_broadcast_across_x = src1->info()->tensor_shape().x() != src2->info()->tensor_shape().x(); |
Pablo Marquez Tello | c727d52 | 2021-01-27 14:16:13 +0000 | [diff] [blame] | 1171 | if(is_broadcast_across_x) |
Michele Di Giorgio | 9428a18 | 2020-03-30 14:10:20 +0100 | [diff] [blame] | 1172 | { |
Pablo Marquez Tello | c727d52 | 2021-01-27 14:16:13 +0000 | [diff] [blame] | 1173 | const bool is_broadcast_input_2 = input2_win.x().step() == 0; |
| 1174 | Window broadcast_win = is_broadcast_input_2 ? input2_win : input1_win; |
| 1175 | Window non_broadcast_win = !is_broadcast_input_2 ? input2_win : input1_win; |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1176 | const ITensor *broadcast_tensor = is_broadcast_input_2 ? src2 : src1; |
| 1177 | const ITensor *non_broadcast_tensor = !is_broadcast_input_2 ? src2 : src1; |
Pablo Marquez Tello | c727d52 | 2021-01-27 14:16:13 +0000 | [diff] [blame] | 1178 | // Clear X Dimension on execution window as we handle manually |
| 1179 | non_broadcast_win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 1180 | Iterator broadcast_input(broadcast_tensor, broadcast_win); |
| 1181 | Iterator non_broadcast_input(non_broadcast_tensor, non_broadcast_win); |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1182 | Iterator dst(out, win); |
Pablo Marquez Tello | c727d52 | 2021-01-27 14:16:13 +0000 | [diff] [blame] | 1183 | execute_window_loop(win, [&](const Coordinates &) |
Michele Di Giorgio | 9428a18 | 2020-03-30 14:10:20 +0100 | [diff] [blame] | 1184 | { |
Pablo Marquez Tello | c727d52 | 2021-01-27 14:16:13 +0000 | [diff] [blame] | 1185 | const auto non_broadcast_input_ptr = reinterpret_cast<const float16_t *>(non_broadcast_input.ptr()); |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1186 | const auto output_ptr = reinterpret_cast<float16_t *>(dst.ptr()); |
Pablo Marquez Tello | c727d52 | 2021-01-27 14:16:13 +0000 | [diff] [blame] | 1187 | const auto broadcast_value = *reinterpret_cast<const float16_t *>(broadcast_input.ptr()); |
| 1188 | const float16x8x2_t broadcast_value_vec = |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 1189 | { |
| 1190 | { |
Pablo Marquez Tello | c727d52 | 2021-01-27 14:16:13 +0000 | [diff] [blame] | 1191 | vdupq_n_f16(broadcast_value), |
| 1192 | vdupq_n_f16(broadcast_value), |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 1193 | } |
| 1194 | }; |
Pablo Marquez Tello | c727d52 | 2021-01-27 14:16:13 +0000 | [diff] [blame] | 1195 | const auto scale_vec = vdupq_n_f16(scale); |
| 1196 | // Compute window_step_x elements per iteration |
| 1197 | int x = window_start_x; |
| 1198 | for(; x <= (window_end_x - window_step_x); x += window_step_x) |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 1199 | { |
Pablo Marquez Tello | c727d52 | 2021-01-27 14:16:13 +0000 | [diff] [blame] | 1200 | const float16x8x2_t non_broadcast_v = |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 1201 | { |
Pablo Marquez Tello | c727d52 | 2021-01-27 14:16:13 +0000 | [diff] [blame] | 1202 | { |
| 1203 | vld1q_f16(non_broadcast_input_ptr + x), |
| 1204 | vld1q_f16(non_broadcast_input_ptr + x + 8), |
| 1205 | } |
| 1206 | }; |
| 1207 | const float16x8x2_t result = |
| 1208 | { |
| 1209 | { |
| 1210 | vmulq_f16(vmulq_f16(broadcast_value_vec.val[0], non_broadcast_v.val[0]), scale_vec), |
| 1211 | vmulq_f16(vmulq_f16(broadcast_value_vec.val[1], non_broadcast_v.val[1]), scale_vec), |
| 1212 | } |
| 1213 | }; |
| 1214 | vst1q_f16(output_ptr + x, result.val[0]); |
| 1215 | vst1q_f16(output_ptr + x + 8, result.val[1]); |
| 1216 | } |
| 1217 | // Compute left-over elements |
| 1218 | for(; x < window_end_x; ++x) |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 1219 | { |
Pablo Marquez Tello | c727d52 | 2021-01-27 14:16:13 +0000 | [diff] [blame] | 1220 | const auto non_broadcast_v = *(non_broadcast_input_ptr + x); |
| 1221 | *(output_ptr + x) = broadcast_value * non_broadcast_v * scale; |
| 1222 | } |
| 1223 | }, |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1224 | broadcast_input, non_broadcast_input, dst); |
Pablo Marquez Tello | c727d52 | 2021-01-27 14:16:13 +0000 | [diff] [blame] | 1225 | } |
| 1226 | else |
| 1227 | { |
| 1228 | input1_win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 1229 | input2_win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1230 | Iterator input1(src1, input1_win); |
| 1231 | Iterator input2(src2, input2_win); |
| 1232 | Iterator dst(out, win); |
Pablo Marquez Tello | c727d52 | 2021-01-27 14:16:13 +0000 | [diff] [blame] | 1233 | execute_window_loop(win, [&](const Coordinates &) |
Michele Di Giorgio | 9428a18 | 2020-03-30 14:10:20 +0100 | [diff] [blame] | 1234 | { |
Pablo Marquez Tello | c727d52 | 2021-01-27 14:16:13 +0000 | [diff] [blame] | 1235 | const auto input1_ptr = reinterpret_cast<const float16_t *>(input1.ptr()); |
| 1236 | const auto input2_ptr = reinterpret_cast<const float16_t *>(input2.ptr()); |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1237 | const auto output_ptr = reinterpret_cast<float16_t *>(dst.ptr()); |
Pablo Marquez Tello | c727d52 | 2021-01-27 14:16:13 +0000 | [diff] [blame] | 1238 | // Compute window_step_x elements per iteration |
| 1239 | int x = window_start_x; |
| 1240 | for(; x <= (window_end_x - window_step_x); x += window_step_x) |
| 1241 | { |
| 1242 | const float16x8x2_t ta1 = |
| 1243 | { |
| 1244 | { |
| 1245 | vld1q_f16(input1_ptr + x), |
| 1246 | vld1q_f16(input1_ptr + x + 8), |
| 1247 | } |
| 1248 | }; |
| 1249 | const float16x8x2_t ta2 = |
| 1250 | { |
| 1251 | { |
| 1252 | vld1q_f16(input2_ptr + x), |
| 1253 | vld1q_f16(input2_ptr + x + 8), |
| 1254 | } |
| 1255 | }; |
| 1256 | const float16x8_t scale_vec = vdupq_n_f16(scale); |
| 1257 | const float16x8x2_t result = |
| 1258 | { |
| 1259 | { |
| 1260 | vmulq_f16(vmulq_f16(ta1.val[0], ta2.val[0]), scale_vec), |
| 1261 | vmulq_f16(vmulq_f16(ta1.val[1], ta2.val[1]), scale_vec), |
| 1262 | } |
| 1263 | }; |
| 1264 | vst1q_f16(output_ptr + x, result.val[0]); |
| 1265 | vst1q_f16(output_ptr + x + 8, result.val[1]); |
| 1266 | } |
| 1267 | // Compute left-over elements |
| 1268 | for(; x < window_end_x; ++x) |
| 1269 | { |
| 1270 | const auto ta1 = *(input1_ptr + x); |
| 1271 | const auto ta2 = *(input2_ptr + x); |
| 1272 | *(output_ptr + x) = ta1 * ta2 * scale; |
| 1273 | } |
| 1274 | }, |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1275 | input1, input2, dst); |
Pablo Marquez Tello | c727d52 | 2021-01-27 14:16:13 +0000 | [diff] [blame] | 1276 | } |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 1277 | } |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 1278 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Pablo Tello | df24618 | 2017-07-03 16:25:09 +0100 | [diff] [blame] | 1279 | |
| 1280 | template <bool is_scale255, bool is_sat> |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1281 | void mul_U8_U8_S16(const ITensor *src1, const ITensor *src2, ITensor *out, const Window &window, int n) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1282 | { |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 1283 | // Create input windows |
| 1284 | Window win = window; |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1285 | Window input1_win = window.broadcast_if_dimension_le_one(src1->info()->tensor_shape()); |
| 1286 | Window input2_win = window.broadcast_if_dimension_le_one(src2->info()->tensor_shape()); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1287 | |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 1288 | // Clear X Dimension on execution window as we handle manually |
| 1289 | win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 1290 | input1_win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 1291 | input2_win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1292 | |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1293 | Iterator input1(src1, input1_win); |
| 1294 | Iterator input2(src2, input2_win); |
| 1295 | Iterator dst(out, win); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1296 | |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 1297 | const int window_step_x = 16 / sizeof(uint8_t); |
| 1298 | const auto window_start_x = static_cast<int>(window.x().start()); |
| 1299 | const auto window_end_x = static_cast<int>(window.x().end()); |
| 1300 | |
| 1301 | execute_window_loop(win, [&](const Coordinates &) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1302 | { |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 1303 | const auto input1_ptr = reinterpret_cast<const uint8_t *>(input1.ptr()); |
| 1304 | const auto input2_ptr = reinterpret_cast<const uint8_t *>(input2.ptr()); |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1305 | const auto output_ptr = reinterpret_cast<int16_t *>(dst.ptr()); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1306 | |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 1307 | // Compute window_step_x elements per iteration |
| 1308 | int x = window_start_x; |
| 1309 | for(; x <= (window_end_x - window_step_x); x += window_step_x) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1310 | { |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 1311 | const uint8x16_t bv = wrapper::vloadq(input2_ptr + x); |
| 1312 | const uint8x16_t av = wrapper::vloadq(input1_ptr + x); |
| 1313 | |
| 1314 | uint16x8_t tmp_low = vmovl_u8(vget_low_u8(av)); |
| 1315 | uint16x8_t tmp_high = vmovl_u8(vget_high_u8(av)); |
| 1316 | tmp_low = vmulq_u16(tmp_low, vmovl_u8(vget_low_u8(bv))); |
| 1317 | tmp_high = vmulq_u16(tmp_high, vmovl_u8(vget_high_u8(bv))); |
| 1318 | |
| 1319 | if(is_scale255) |
| 1320 | { |
| 1321 | tmp_low = scale255_U16_U16(tmp_low); |
| 1322 | tmp_high = scale255_U16_U16(tmp_high); |
| 1323 | } |
| 1324 | else |
| 1325 | { |
| 1326 | const int16x8_t vn = vdupq_n_s16(-n); |
| 1327 | |
| 1328 | if(is_sat) |
| 1329 | { |
| 1330 | tmp_low = vqshlq_u16(tmp_low, vn); |
| 1331 | tmp_high = vqshlq_u16(tmp_high, vn); |
| 1332 | } |
| 1333 | else |
| 1334 | { |
| 1335 | tmp_low = vshlq_u16(tmp_low, vn); |
| 1336 | tmp_high = vshlq_u16(tmp_high, vn); |
| 1337 | } |
| 1338 | } |
| 1339 | |
| 1340 | if(is_sat) |
| 1341 | { |
| 1342 | static const uint16x8_t max = vdupq_n_u16(SHRT_MAX); |
| 1343 | |
| 1344 | tmp_low = vminq_u16(tmp_low, max); |
| 1345 | tmp_high = vminq_u16(tmp_high, max); |
| 1346 | } |
| 1347 | |
| 1348 | vst1q_s16(output_ptr + x, vreinterpretq_s16_u16(tmp_low)); |
| 1349 | vst1q_s16(output_ptr + x + 8, vreinterpretq_s16_u16(tmp_high)); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1350 | } |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 1351 | |
| 1352 | // Compute left-over elements |
| 1353 | for(; x < window_end_x; ++x) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1354 | { |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 1355 | int32_t tmp = static_cast<int32_t>(*(input1_ptr + x)) * static_cast<int32_t>(*(input2_ptr + x)); |
| 1356 | |
| 1357 | if(is_scale255) |
| 1358 | { |
| 1359 | float tmp_f = static_cast<float>(tmp) * scale255_constant; |
| 1360 | tmp = static_cast<int32_t>(tmp_f + 0.5f); |
| 1361 | } |
| 1362 | else |
| 1363 | { |
| 1364 | tmp >>= n; |
| 1365 | } |
| 1366 | |
| 1367 | if(is_sat) |
| 1368 | { |
| 1369 | tmp = (tmp > SHRT_MAX) ? SHRT_MAX : tmp; |
| 1370 | } |
| 1371 | |
| 1372 | *(output_ptr + x) = static_cast<int16_t>(tmp); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1373 | } |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 1374 | }, |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1375 | input1, input2, dst); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1376 | } |
| 1377 | |
| 1378 | template <bool is_scale255, bool is_sat> |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1379 | void mul_S16_U8_S16(const ITensor *src1, const ITensor *src2, ITensor *out, const Window &window, int n) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1380 | { |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 1381 | // Create input windows |
| 1382 | Window win = window; |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1383 | Window input1_win = window.broadcast_if_dimension_le_one(src1->info()->tensor_shape()); |
| 1384 | Window input2_win = window.broadcast_if_dimension_le_one(src2->info()->tensor_shape()); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1385 | |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 1386 | // Clear X Dimension on execution window as we handle manually |
| 1387 | win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 1388 | input1_win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 1389 | input2_win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1390 | |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1391 | Iterator input1(src1, input1_win); |
| 1392 | Iterator input2(src2, input2_win); |
| 1393 | Iterator dst(out, win); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1394 | |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 1395 | const int window_step_x = 16; |
| 1396 | const auto window_start_x = static_cast<int>(window.x().start()); |
| 1397 | const auto window_end_x = static_cast<int>(window.x().end()); |
| 1398 | |
| 1399 | execute_window_loop(win, [&](const Coordinates &) |
| 1400 | { |
| 1401 | const auto input1_ptr = reinterpret_cast<const int16_t *>(input1.ptr()); |
| 1402 | const auto input2_ptr = reinterpret_cast<const uint8_t *>(input2.ptr()); |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1403 | const auto output_ptr = reinterpret_cast<int16_t *>(dst.ptr()); |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 1404 | |
| 1405 | // Compute window_step_x elements per iteration |
| 1406 | int x = window_start_x; |
| 1407 | for(; x <= (window_end_x - window_step_x); x += window_step_x) |
| 1408 | { |
| 1409 | const int16x8x2_t ta1 = |
| 1410 | { |
| 1411 | { |
| 1412 | vld1q_s16(input1_ptr + x), |
| 1413 | vld1q_s16(input1_ptr + x + 8), |
| 1414 | } |
| 1415 | }; |
| 1416 | const uint8x8x2_t ta2u = |
| 1417 | { |
| 1418 | { |
| 1419 | vld1_u8(input2_ptr + x), |
| 1420 | vld1_u8(input2_ptr + x + 8), |
| 1421 | } |
| 1422 | }; |
| 1423 | const int16x8x2_t ta2 = |
| 1424 | { |
| 1425 | { |
| 1426 | vreinterpretq_s16_u16(vmovl_u8(ta2u.val[0])), |
| 1427 | vreinterpretq_s16_u16(vmovl_u8(ta2u.val[1])) |
| 1428 | } |
| 1429 | }; |
| 1430 | |
| 1431 | const int16x8x2_t result = mul_S16_S16_S16_n_k<is_scale255, is_sat>(ta1, ta2, n); |
| 1432 | |
| 1433 | vst1q_s16(output_ptr + x, result.val[0]); |
| 1434 | vst1q_s16(output_ptr + x + 8, result.val[1]); |
| 1435 | } |
| 1436 | |
| 1437 | // Compute left-over elements |
| 1438 | for(; x < window_end_x; ++x) |
| 1439 | { |
| 1440 | int32_t tmp = static_cast<int32_t>(*(input1_ptr + x)) * static_cast<int32_t>(*(input2_ptr + x)); |
| 1441 | |
| 1442 | if(is_scale255) |
| 1443 | { |
| 1444 | float tmp_f = static_cast<float>(tmp) * scale255_constant; |
| 1445 | |
| 1446 | tmp = static_cast<int32_t>(tmp_f + 0.5f); |
| 1447 | } |
| 1448 | else |
| 1449 | { |
| 1450 | if(tmp >= 0) |
| 1451 | { |
| 1452 | tmp >>= n; |
| 1453 | } |
| 1454 | else |
| 1455 | { |
| 1456 | uint32_t mask = (1u << n) - 1; |
| 1457 | tmp = (tmp + static_cast<int32_t>(mask)) >> n; |
| 1458 | } |
| 1459 | } |
| 1460 | if(is_sat) |
| 1461 | { |
| 1462 | tmp = (tmp > SHRT_MAX) ? SHRT_MAX : ((tmp < SHRT_MIN) ? SHRT_MIN : tmp); |
| 1463 | } |
| 1464 | *(output_ptr + x) = static_cast<int16_t>(tmp); |
| 1465 | } |
| 1466 | }, |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1467 | input1, input2, dst); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1468 | } |
| 1469 | |
| 1470 | template <bool is_scale255, bool is_sat> |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1471 | void mul_U8_S16_S16(const ITensor *src1, const ITensor *src2, ITensor *out, const Window &window, int n) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1472 | { |
| 1473 | // Simply swap the two input buffers |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1474 | mul_S16_U8_S16<is_scale255, is_sat>(src2, src1, out, window, n); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1475 | } |
| 1476 | } // namespace |
| 1477 | |
Georgios Pinitas | 0dc0d8e | 2021-04-30 03:18:37 +0100 | [diff] [blame] | 1478 | void CpuMulKernel::configure(ITensorInfo *src1, ITensorInfo *src2, ITensorInfo *dst, float scale, ConvertPolicy overflow_policy, RoundingPolicy rounding_policy) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1479 | { |
Ioan-Cristian Szabo | 754e952 | 2017-11-28 18:29:43 +0000 | [diff] [blame] | 1480 | ARM_COMPUTE_UNUSED(rounding_policy); |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1481 | ARM_COMPUTE_ERROR_ON_NULLPTR(src1, src2, dst); |
Georgios Pinitas | f0dea70 | 2017-07-03 18:17:28 +0100 | [diff] [blame] | 1482 | |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1483 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(src1, src2, dst, scale, overflow_policy, rounding_policy)); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1484 | |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1485 | const TensorShape &out_shape = TensorShape::broadcast_shape(src1->tensor_shape(), src2->tensor_shape()); |
Michalis Spyrou | 861f0db | 2018-02-26 16:47:58 +0000 | [diff] [blame] | 1486 | |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1487 | // Auto initialize dst if not initialized |
| 1488 | set_shape_if_empty(*dst, out_shape); |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 1489 | |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 1490 | _scale = scale; |
| 1491 | _scale_exponent = 0; |
| 1492 | _func_quantized = nullptr; |
| 1493 | _func_int = nullptr; |
| 1494 | _func_float = nullptr; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1495 | |
| 1496 | bool is_scale_255 = false; |
| 1497 | // Check and validate scaling factor |
| 1498 | if(std::abs(scale - scale255_constant) < 0.00001f) |
| 1499 | { |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1500 | is_scale_255 = true; |
| 1501 | } |
| 1502 | else |
| 1503 | { |
Ioan-Cristian Szabo | 754e952 | 2017-11-28 18:29:43 +0000 | [diff] [blame] | 1504 | int exponent = 0; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1505 | |
Ioan-Cristian Szabo | 754e952 | 2017-11-28 18:29:43 +0000 | [diff] [blame] | 1506 | std::frexp(scale, &exponent); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1507 | |
Ioan-Cristian Szabo | 754e952 | 2017-11-28 18:29:43 +0000 | [diff] [blame] | 1508 | // Store the positive exponent. We know that we compute 1/2^n |
| 1509 | // Additionally we need to subtract 1 to compensate that frexp used a mantissa of 0.5 |
| 1510 | _scale_exponent = std::abs(exponent - 1); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1511 | } |
| 1512 | |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1513 | const DataType dt_input1 = src1->data_type(); |
| 1514 | const DataType dt_input2 = src2->data_type(); |
| 1515 | const DataType dt_output = dst->data_type(); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1516 | const bool is_sat = (overflow_policy == ConvertPolicy::SATURATE); |
| 1517 | |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 1518 | switch(dt_input1) |
Manuel Bottini | 79fa9a2 | 2019-02-22 17:54:22 +0000 | [diff] [blame] | 1519 | { |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 1520 | case DataType::QASYMM8: |
| 1521 | if(dt_input2 == DataType::QASYMM8 && dt_output == DataType::QASYMM8) |
| 1522 | { |
| 1523 | _func_quantized = &mul_saturate_quantized_8<uint8_t>; |
| 1524 | } |
| 1525 | break; |
| 1526 | case DataType::QASYMM8_SIGNED: |
| 1527 | if(dt_input2 == DataType::QASYMM8_SIGNED) |
| 1528 | { |
| 1529 | _func_quantized = &mul_saturate_quantized_8<int8_t>; |
| 1530 | ; |
| 1531 | } |
| 1532 | break; |
| 1533 | case DataType::QSYMM16: |
| 1534 | if(dt_input2 == DataType::QSYMM16 && dt_output == DataType::QSYMM16) |
| 1535 | { |
| 1536 | _func_quantized = &mul_saturate_QSYMM16_QSYMM16_QSYMM16; |
| 1537 | } |
| 1538 | else if(dt_input2 == DataType::QSYMM16 && dt_output == DataType::S32) |
| 1539 | { |
| 1540 | _func_int = &mul_QSYMM16_QSYMM16_S32; |
| 1541 | } |
| 1542 | break; |
| 1543 | case DataType::S16: |
| 1544 | if(DataType::U8 == dt_input2 && DataType::S16 == dt_output) |
| 1545 | { |
| 1546 | if(is_scale_255) |
| 1547 | { |
| 1548 | _func_int = is_sat ? &mul_S16_U8_S16<true, true> : &mul_S16_U8_S16<true, false>; |
| 1549 | } |
| 1550 | else |
| 1551 | { |
| 1552 | _func_int = is_sat ? &mul_S16_U8_S16<false, true> : &mul_S16_U8_S16<false, false>; |
| 1553 | } |
| 1554 | } |
| 1555 | if(DataType::S16 == dt_input2 && DataType::S16 == dt_output) |
| 1556 | { |
| 1557 | if(is_scale_255) |
| 1558 | { |
| 1559 | _func_int = is_sat ? &mul_S16_S16_S16<true, true> : &mul_S16_S16_S16<true, false>; |
| 1560 | } |
| 1561 | else |
| 1562 | { |
| 1563 | _func_int = is_sat ? &mul_S16_S16_S16<false, true> : &mul_S16_S16_S16<false, false>; |
| 1564 | } |
| 1565 | } |
| 1566 | break; |
SiCong Li | bb88f89 | 2020-08-28 11:18:47 +0100 | [diff] [blame] | 1567 | case DataType::S32: |
| 1568 | if(DataType::S32 == dt_input2 && DataType::S32 == dt_output) |
| 1569 | { |
| 1570 | _func_int = is_sat ? &mul_S32_S32_S32<true> : &mul_S32_S32_S32<false>; |
| 1571 | } |
| 1572 | break; |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 1573 | case DataType::U8: |
| 1574 | if(DataType::U8 == dt_input2 && DataType::U8 == dt_output) |
| 1575 | { |
| 1576 | if(is_scale_255) |
| 1577 | { |
| 1578 | _func_int = is_sat ? &mul_U8_U8_U8<true, true> : &mul_U8_U8_U8<true, false>; |
| 1579 | } |
| 1580 | else |
| 1581 | { |
| 1582 | _func_int = is_sat ? &mul_U8_U8_U8<false, true> : &mul_U8_U8_U8<false, false>; |
| 1583 | } |
| 1584 | } |
| 1585 | else if(DataType::U8 == dt_input2 && DataType::S16 == dt_output) |
| 1586 | { |
| 1587 | if(is_scale_255) |
| 1588 | { |
| 1589 | _func_int = is_sat ? &mul_U8_U8_S16<true, true> : &mul_U8_U8_S16<true, false>; |
| 1590 | } |
| 1591 | else |
| 1592 | { |
| 1593 | _func_int = is_sat ? &mul_U8_U8_S16<false, true> : &mul_U8_U8_S16<false, false>; |
| 1594 | } |
| 1595 | } |
| 1596 | else if(DataType::S16 == dt_input2 && DataType::S16 == dt_output) |
| 1597 | { |
| 1598 | if(is_scale_255) |
| 1599 | { |
| 1600 | _func_int = is_sat ? &mul_U8_S16_S16<true, true> : &mul_U8_S16_S16<true, false>; |
| 1601 | } |
| 1602 | else |
| 1603 | { |
| 1604 | _func_int = is_sat ? &mul_U8_S16_S16<false, true> : &mul_U8_S16_S16<false, false>; |
| 1605 | } |
| 1606 | } |
| 1607 | break; |
| 1608 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 1609 | case DataType::F16: |
| 1610 | _func_float = &mul_F16_F16_F16; |
| 1611 | break; |
| 1612 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
| 1613 | case DataType::F32: |
| 1614 | _func_float = &mul_F32_F32_F32; |
| 1615 | break; |
| 1616 | default: |
| 1617 | ARM_COMPUTE_ERROR("You called with the wrong img formats"); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1618 | } |
| 1619 | |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 1620 | // Configure kernel window |
Viet-Hoa Do | 0d05b66 | 2022-09-09 15:39:05 +0100 | [diff] [blame] | 1621 | Window win; |
| 1622 | std::tie(win, _split_dimension) = calculate_squashed_or_max_window(*src1, *src2); |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 1623 | |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1624 | ICpuKernel::configure(win); |
Ioan-Cristian Szabo | 754e952 | 2017-11-28 18:29:43 +0000 | [diff] [blame] | 1625 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1626 | |
Georgios Pinitas | 0dc0d8e | 2021-04-30 03:18:37 +0100 | [diff] [blame] | 1627 | Status CpuMulKernel::validate(const ITensorInfo *src1, const ITensorInfo *src2, const ITensorInfo *dst, float scale, ConvertPolicy overflow_policy, |
| 1628 | RoundingPolicy rounding_policy) |
Ioan-Cristian Szabo | 754e952 | 2017-11-28 18:29:43 +0000 | [diff] [blame] | 1629 | { |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1630 | ARM_COMPUTE_ERROR_ON_NULLPTR(src1, src2, dst); |
| 1631 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(src1, src2, dst, scale, overflow_policy, rounding_policy)); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1632 | |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 1633 | return Status{}; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1634 | } |
| 1635 | |
Georgios Pinitas | 0dc0d8e | 2021-04-30 03:18:37 +0100 | [diff] [blame] | 1636 | void CpuMulKernel::run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1637 | { |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 1638 | ARM_COMPUTE_UNUSED(info); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1639 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1640 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(ICpuKernel::window(), window); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1641 | |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1642 | auto src1 = tensors.get_const_tensor(TensorType::ACL_SRC_0); |
| 1643 | auto src2 = tensors.get_const_tensor(TensorType::ACL_SRC_1); |
| 1644 | auto dst = tensors.get_tensor(TensorType::ACL_DST); |
Michalis Spyrou | 6eb7345 | 2020-07-02 17:39:25 +0100 | [diff] [blame] | 1645 | |
Sheri Zhang | fcf6f4e | 2020-06-25 20:01:00 +0100 | [diff] [blame] | 1646 | if(_func_quantized != nullptr) |
Michalis Spyrou | 861f0db | 2018-02-26 16:47:58 +0000 | [diff] [blame] | 1647 | { |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1648 | (*_func_quantized)(src1, src2, dst, window, _scale); |
Manuel Bottini | 79fa9a2 | 2019-02-22 17:54:22 +0000 | [diff] [blame] | 1649 | } |
| 1650 | else if(_func_int != nullptr) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1651 | { |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1652 | (*_func_int)(src1, src2, dst, window, _scale_exponent); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1653 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1654 | else |
| 1655 | { |
| 1656 | ARM_COMPUTE_ERROR_ON(_func_float == nullptr); |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1657 | (*_func_float)(src1, src2, dst, window, _scale); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1658 | } |
| 1659 | } |
Georgios Pinitas | 0dc0d8e | 2021-04-30 03:18:37 +0100 | [diff] [blame] | 1660 | const char *CpuMulKernel::name() const |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1661 | { |
Georgios Pinitas | 0dc0d8e | 2021-04-30 03:18:37 +0100 | [diff] [blame] | 1662 | return "CpuMulKernel"; |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1663 | } |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 1664 | namespace |
| 1665 | { |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1666 | Status validate_arguments_complex(const ITensorInfo *src1, const ITensorInfo *src2, const ITensorInfo *dst) |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 1667 | { |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1668 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(src1, 2, DataType::F32); |
| 1669 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(src2, 2, DataType::F32); |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 1670 | |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1671 | const TensorShape &out_shape = TensorShape::broadcast_shape(src1->tensor_shape(), src2->tensor_shape()); |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 1672 | |
| 1673 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(out_shape.total_size() == 0, "Inputs are not broadcast compatible"); |
| 1674 | |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1675 | // Validate in case of configured dst |
| 1676 | if(dst->total_size() > 0) |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 1677 | { |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1678 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(dst, 2, DataType::F32); |
| 1679 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(detail::have_different_dimensions(out_shape, dst->tensor_shape(), 0), "Wrong shape for dst"); |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 1680 | } |
| 1681 | |
| 1682 | return Status{}; |
| 1683 | } |
Sheri Zhang | 4d91dc6 | 2020-09-23 11:22:50 +0100 | [diff] [blame] | 1684 | } // namespace |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 1685 | |
Georgios Pinitas | 0dc0d8e | 2021-04-30 03:18:37 +0100 | [diff] [blame] | 1686 | void CpuComplexMulKernel::configure(ITensorInfo *src1, ITensorInfo *src2, ITensorInfo *dst) |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 1687 | { |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1688 | ARM_COMPUTE_ERROR_ON_NULLPTR(src1, src2, dst); |
| 1689 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments_complex(src1, src2, dst)); |
Sheri Zhang | 4d91dc6 | 2020-09-23 11:22:50 +0100 | [diff] [blame] | 1690 | |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1691 | const TensorShape &out_shape = TensorShape::broadcast_shape(src1->tensor_shape(), src2->tensor_shape()); |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 1692 | |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1693 | // Auto initialize dst if not initialized |
| 1694 | const TensorInfo out_info(out_shape, src1->num_channels(), src1->data_type()); |
| 1695 | auto_init_if_empty(*dst, out_info); |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 1696 | |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 1697 | // Configure kernel window |
SiCongLi | c7b1e84 | 2021-02-22 14:28:33 +0000 | [diff] [blame] | 1698 | Window win = calculate_max_window(out_shape); |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 1699 | |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1700 | ICpuKernel::configure(win); |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 1701 | } |
| 1702 | |
Georgios Pinitas | 0dc0d8e | 2021-04-30 03:18:37 +0100 | [diff] [blame] | 1703 | Status CpuComplexMulKernel::validate(const ITensorInfo *src1, const ITensorInfo *src2, const ITensorInfo *dst) |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 1704 | { |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1705 | ARM_COMPUTE_ERROR_ON_NULLPTR(src1, src2, dst); |
| 1706 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments_complex(src1, src2, dst)); |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 1707 | |
| 1708 | return Status{}; |
| 1709 | } |
| 1710 | |
Georgios Pinitas | 0dc0d8e | 2021-04-30 03:18:37 +0100 | [diff] [blame] | 1711 | void CpuComplexMulKernel::run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 1712 | { |
| 1713 | ARM_COMPUTE_UNUSED(info); |
| 1714 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1715 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(ICpuKernel::window(), window); |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 1716 | |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1717 | auto src1 = tensors.get_const_tensor(TensorType::ACL_SRC_0); |
| 1718 | auto src2 = tensors.get_const_tensor(TensorType::ACL_SRC_1); |
| 1719 | auto dst = tensors.get_tensor(TensorType::ACL_DST); |
Michalis Spyrou | 6eb7345 | 2020-07-02 17:39:25 +0100 | [diff] [blame] | 1720 | |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1721 | c_mul_F32_F32_F32_n(src1, src2, dst, window); |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 1722 | } |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1723 | |
Georgios Pinitas | 0dc0d8e | 2021-04-30 03:18:37 +0100 | [diff] [blame] | 1724 | const char *CpuComplexMulKernel::name() const |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1725 | { |
Georgios Pinitas | 0dc0d8e | 2021-04-30 03:18:37 +0100 | [diff] [blame] | 1726 | return "CpuComplexMulKernel"; |
Sheri Zhang | 1e3ab42 | 2021-03-16 17:35:08 +0000 | [diff] [blame] | 1727 | } |
| 1728 | } // namespace kernels |
| 1729 | } // namespace cpu |
Manuel Bottini | 79fa9a2 | 2019-02-22 17:54:22 +0000 | [diff] [blame] | 1730 | } // namespace arm_compute |