Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 1 | /* |
Georgios Pinitas | f72f936 | 2018-01-12 16:29:45 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 ARM Limited. |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
| 24 | #include "arm_compute/core/NEON/kernels/NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel.h" |
| 25 | |
| 26 | #include "arm_compute/core/AccessWindowStatic.h" |
| 27 | #include "arm_compute/core/Error.h" |
| 28 | #include "arm_compute/core/Helpers.h" |
| 29 | #include "arm_compute/core/ITensor.h" |
| 30 | #include "arm_compute/core/NEON/NEAsymm.h" |
Georgios Pinitas | 932491f | 2018-09-21 16:33:15 +0100 | [diff] [blame] | 31 | #include "arm_compute/core/TensorInfo.h" |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 32 | #include "arm_compute/core/Types.h" |
| 33 | #include "arm_compute/core/Utils.h" |
| 34 | #include "arm_compute/core/Validate.h" |
| 35 | #include "arm_compute/core/Window.h" |
Georgios Pinitas | 041f36d | 2018-09-18 18:38:37 +0100 | [diff] [blame] | 36 | #include "arm_compute/core/utils/misc/ShapeCalculator.h" |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 37 | |
| 38 | #include <arm_neon.h> |
| 39 | #include <cstddef> |
| 40 | #include <cstdint> |
| 41 | |
| 42 | using namespace arm_compute; |
| 43 | |
| 44 | namespace |
| 45 | { |
Georgios Pinitas | bb081ca | 2018-11-08 10:22:01 +0000 | [diff] [blame] | 46 | Status validate_arguments(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, int min, int max) |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 47 | { |
| 48 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::S32); |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 49 | ARM_COMPUTE_RETURN_ERROR_ON(max > 255); |
| 50 | ARM_COMPUTE_RETURN_ERROR_ON(min < 0 || min > max); |
| 51 | |
| 52 | // Check biases if exist |
| 53 | if(bias != nullptr) |
| 54 | { |
| 55 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, bias); |
| 56 | ARM_COMPUTE_RETURN_ERROR_ON(bias->num_dimensions() > 1); |
| 57 | ARM_COMPUTE_RETURN_ERROR_ON(input->dimension(0) != bias->dimension(0)); |
| 58 | } |
Chunosov | 5124be5 | 2017-11-22 20:42:13 +0700 | [diff] [blame] | 59 | |
| 60 | if(output->total_size() != 0) |
| 61 | { |
| 62 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(output, 1, DataType::QASYMM8); |
Georgios Pinitas | bb081ca | 2018-11-08 10:22:01 +0000 | [diff] [blame] | 63 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(output, input); |
Chunosov | 5124be5 | 2017-11-22 20:42:13 +0700 | [diff] [blame] | 64 | } |
| 65 | |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 66 | return Status{}; |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 67 | } |
| 68 | |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 69 | std::pair<Status, Window> validate_and_configure_window(ITensorInfo *input, ITensorInfo *bias, ITensorInfo *output) |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 70 | { |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 71 | // Note: This kernel performs 16 elements per iteration. |
| 72 | // However, since we use a left-over for loop, we cannot have any read or write out of memory |
| 73 | // For this reason num_elems_processed_per_iteration is set to 1 |
| 74 | constexpr unsigned int num_elems_processed_per_iteration = 1; |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 75 | |
Georgios Pinitas | bb081ca | 2018-11-08 10:22:01 +0000 | [diff] [blame] | 76 | // Output auto inizialitation if not yet initialized |
| 77 | auto_init_if_empty(*output, input->clone()->set_data_type(DataType::QASYMM8)); |
| 78 | |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 79 | // Configure kernel window |
Georgios Pinitas | 041f36d | 2018-09-18 18:38:37 +0100 | [diff] [blame] | 80 | Window win = calculate_max_window(*input, Steps(num_elems_processed_per_iteration)); |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 81 | |
| 82 | AccessWindowHorizontal input_access(input, 0, num_elems_processed_per_iteration); |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 83 | |
| 84 | bool window_changed = update_window_and_padding(win, |
Chunosov | 5124be5 | 2017-11-22 20:42:13 +0700 | [diff] [blame] | 85 | input_access); |
| 86 | |
| 87 | if(output->total_size() != 0) |
| 88 | { |
Georgios Pinitas | 041f36d | 2018-09-18 18:38:37 +0100 | [diff] [blame] | 89 | output->set_valid_region(ValidRegion(Coordinates(), output->tensor_shape())); |
Chunosov | 5124be5 | 2017-11-22 20:42:13 +0700 | [diff] [blame] | 90 | } |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 91 | |
| 92 | if(bias != nullptr) |
| 93 | { |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 94 | AccessWindowStatic bias_access(bias, 0, 0, bias->dimension(0), bias->dimension(1)); |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 95 | window_changed = window_changed || update_window_and_padding(win, bias_access); |
| 96 | } |
| 97 | |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 98 | Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{}; |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 99 | return std::make_pair(err, win); |
| 100 | } |
Georgios Pinitas | f72f936 | 2018-01-12 16:29:45 +0000 | [diff] [blame] | 101 | } // namespace |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 102 | |
Georgios Pinitas | f72f936 | 2018-01-12 16:29:45 +0000 | [diff] [blame] | 103 | namespace arm_compute |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 104 | { |
Georgios Pinitas | f72f936 | 2018-01-12 16:29:45 +0000 | [diff] [blame] | 105 | class Coordinates; |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 106 | |
| 107 | /* Function used by the left-over for loop to perform the quantization */ |
| 108 | template <bool is_bounded_relu> |
| 109 | inline uint8_t finalize_quantization(int32x4_t in_s32, int result_fixedpoint_multiplier, int32_t result_shift, int32x4_t result_offset_after_shift_s32, uint8_t min_u8, uint8_t max_u8) |
| 110 | { |
| 111 | const static int32x4_t zero_s32 = vdupq_n_s32(0); |
| 112 | const static int32x4_t sat_value_s32 = vdupq_n_s32(255); |
| 113 | |
| 114 | // Fixed point multiplication with vector saturating rounding doubling multiply high with scalar |
| 115 | in_s32 = vqrdmulhq_n_s32(in_s32, result_fixedpoint_multiplier); |
| 116 | |
| 117 | // Round to the nearest division by a power-of-two using result_shift_s32 |
| 118 | in_s32 = rounding_divide_by_pow2(in_s32, result_shift); |
| 119 | |
| 120 | // Add the offset terms |
| 121 | in_s32 = vaddq_s32(in_s32, result_offset_after_shift_s32); |
| 122 | |
| 123 | // Saturate negative values |
| 124 | in_s32 = vmaxq_s32(in_s32, zero_s32); |
| 125 | in_s32 = vminq_s32(in_s32, sat_value_s32); |
| 126 | |
| 127 | auto out_u8 = static_cast<uint8_t>(vgetq_lane_s32(in_s32, 0)); |
| 128 | |
| 129 | if(is_bounded_relu) |
| 130 | { |
| 131 | out_u8 = std::max(out_u8, min_u8); |
| 132 | out_u8 = std::min(out_u8, max_u8); |
| 133 | } |
| 134 | |
| 135 | return out_u8; |
| 136 | } |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 137 | } // namespace arm_compute |
| 138 | |
| 139 | template <bool is_bounded_relu> |
| 140 | void NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel::run(const Window &window) |
| 141 | { |
| 142 | const int32x4_t result_offset_after_shift_s32 = vdupq_n_s32(_result_offset_after_shift); |
| 143 | const uint8x16_t min_u8 = vdupq_n_u8(static_cast<uint8_t>(_min)); |
| 144 | const uint8x16_t max_u8 = vdupq_n_u8(static_cast<uint8_t>(_max)); |
| 145 | |
| 146 | ARM_COMPUTE_UNUSED(min_u8); |
| 147 | ARM_COMPUTE_UNUSED(max_u8); |
| 148 | |
Georgios Pinitas | bb081ca | 2018-11-08 10:22:01 +0000 | [diff] [blame] | 149 | const int window_step_x = 16; |
| 150 | const auto window_start_x = static_cast<int>(window.x().start()); |
| 151 | const auto window_end_x = static_cast<int>(window.x().end()); |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 152 | |
Georgios Pinitas | 041f36d | 2018-09-18 18:38:37 +0100 | [diff] [blame] | 153 | Window win_collapsed = window.collapse_if_possible(window, Window::DimZ); |
| 154 | win_collapsed.set(Window::DimX, Window::Dimension(0, 1, 1)); |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 155 | |
Georgios Pinitas | 041f36d | 2018-09-18 18:38:37 +0100 | [diff] [blame] | 156 | Iterator in(_input, win_collapsed); |
Georgios Pinitas | bb081ca | 2018-11-08 10:22:01 +0000 | [diff] [blame] | 157 | Iterator out(_output, win_collapsed); |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 158 | if(_bias != nullptr) |
| 159 | { |
| 160 | Window win_biases; |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 161 | win_biases.set(Window::DimX, Window::Dimension(0, 1, 1)); |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 162 | win_biases.set(Window::DimY, Window::Dimension(0, 1, 1)); |
| 163 | |
| 164 | Iterator bias(_bias, win_biases); |
Georgios Pinitas | 041f36d | 2018-09-18 18:38:37 +0100 | [diff] [blame] | 165 | execute_window_loop(win_collapsed, [&](const Coordinates & id) |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 166 | { |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 167 | // Compute 16 elements per iteration |
| 168 | int x = window_start_x; |
| 169 | for(; x <= (window_end_x - window_step_x); x += window_step_x) |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 170 | { |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 171 | int32x4x4_t in_s32 = |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 172 | { |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 173 | { |
| 174 | vld1q_s32(reinterpret_cast<const int32_t *>(in.ptr()) + x + 0), |
| 175 | vld1q_s32(reinterpret_cast<const int32_t *>(in.ptr()) + x + 4), |
| 176 | vld1q_s32(reinterpret_cast<const int32_t *>(in.ptr()) + x + 8), |
| 177 | vld1q_s32(reinterpret_cast<const int32_t *>(in.ptr()) + x + 12) |
| 178 | } |
| 179 | }; |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 180 | |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 181 | const int32x4x4_t bias_s32 = |
| 182 | { |
| 183 | { |
| 184 | vld1q_s32(reinterpret_cast<const int32_t *>(bias.ptr()) + x + 0), |
| 185 | vld1q_s32(reinterpret_cast<const int32_t *>(bias.ptr()) + x + 4), |
| 186 | vld1q_s32(reinterpret_cast<const int32_t *>(bias.ptr()) + x + 8), |
| 187 | vld1q_s32(reinterpret_cast<const int32_t *>(bias.ptr()) + x + 12) |
| 188 | } |
| 189 | }; |
| 190 | |
| 191 | // Add the bias to GEMM's result |
| 192 | in_s32.val[0] = vaddq_s32(in_s32.val[0], bias_s32.val[0]); |
| 193 | in_s32.val[1] = vaddq_s32(in_s32.val[1], bias_s32.val[1]); |
| 194 | in_s32.val[2] = vaddq_s32(in_s32.val[2], bias_s32.val[2]); |
| 195 | in_s32.val[3] = vaddq_s32(in_s32.val[3], bias_s32.val[3]); |
| 196 | |
Georgios Pinitas | bb081ca | 2018-11-08 10:22:01 +0000 | [diff] [blame] | 197 | vst1q_u8(out.ptr() + x, finalize_quantization<is_bounded_relu>(in_s32, _result_fixedpoint_multiplier, _result_shift, result_offset_after_shift_s32, min_u8, max_u8)); |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | // Compute left-over elements |
| 201 | for(; x < window_end_x; ++x) |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 202 | { |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 203 | const int32_t bias_value = *(reinterpret_cast<const int32_t *>(bias.ptr()) + x); |
| 204 | int32_t in_value = *(reinterpret_cast<const int32_t *>(in.ptr()) + x); |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 205 | |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 206 | // Add bias |
| 207 | in_value += bias_value; |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 208 | |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 209 | // Finalize and store the result |
Georgios Pinitas | bb081ca | 2018-11-08 10:22:01 +0000 | [diff] [blame] | 210 | *(out.ptr() + x) = finalize_quantization<is_bounded_relu>(vdupq_n_s32(in_value), _result_fixedpoint_multiplier, _result_shift, result_offset_after_shift_s32, static_cast<uint8_t>(_min), |
| 211 | static_cast<uint8_t>(_max)); |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 212 | } |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 213 | }, |
Georgios Pinitas | bb081ca | 2018-11-08 10:22:01 +0000 | [diff] [blame] | 214 | in, out, bias); |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 215 | } |
| 216 | else |
| 217 | { |
Georgios Pinitas | 041f36d | 2018-09-18 18:38:37 +0100 | [diff] [blame] | 218 | execute_window_loop(win_collapsed, [&](const Coordinates & id) |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 219 | { |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 220 | // Compute 16 elements per iteration |
| 221 | int x = window_start_x; |
| 222 | for(; x <= (window_end_x - window_step_x); x += window_step_x) |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 223 | { |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 224 | int32x4x4_t in_s32 = |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 225 | { |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 226 | { |
| 227 | vld1q_s32(reinterpret_cast<const int32_t *>(in.ptr()) + x + 0), |
| 228 | vld1q_s32(reinterpret_cast<const int32_t *>(in.ptr()) + x + 4), |
| 229 | vld1q_s32(reinterpret_cast<const int32_t *>(in.ptr()) + x + 8), |
| 230 | vld1q_s32(reinterpret_cast<const int32_t *>(in.ptr()) + x + 12) |
| 231 | } |
| 232 | }; |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 233 | |
Georgios Pinitas | bb081ca | 2018-11-08 10:22:01 +0000 | [diff] [blame] | 234 | vst1q_u8(out.ptr() + x, finalize_quantization<is_bounded_relu>(in_s32, _result_fixedpoint_multiplier, _result_shift, result_offset_after_shift_s32, min_u8, max_u8)); |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | // Compute left-over elements |
| 238 | for(; x < window_end_x; ++x) |
| 239 | { |
| 240 | const int32x4_t in_s32 = vld1q_dup_s32(reinterpret_cast<const int32_t *>(in.ptr()) + x); |
| 241 | |
| 242 | // Finalize and store the result |
Georgios Pinitas | bb081ca | 2018-11-08 10:22:01 +0000 | [diff] [blame] | 243 | *(out.ptr() + x) = finalize_quantization<is_bounded_relu>(in_s32, _result_fixedpoint_multiplier, _result_shift, result_offset_after_shift_s32, static_cast<uint8_t>(_min), static_cast<uint8_t>(_max)); |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 244 | } |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 245 | }, |
Georgios Pinitas | bb081ca | 2018-11-08 10:22:01 +0000 | [diff] [blame] | 246 | in, out); |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 247 | } |
| 248 | } |
| 249 | |
| 250 | NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel::NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel() |
Georgios Pinitas | bb081ca | 2018-11-08 10:22:01 +0000 | [diff] [blame] | 251 | : _func(nullptr), _input(nullptr), _bias(nullptr), _output(nullptr), _result_fixedpoint_multiplier(0), _result_shift(0), _result_offset_after_shift(0), _min(0), _max(0) |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 252 | { |
| 253 | } |
| 254 | |
| 255 | void NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel::configure(const ITensor *input, const ITensor *bias, ITensor *output, int result_fixedpoint_multiplier, int result_shift, |
Georgios Pinitas | bb081ca | 2018-11-08 10:22:01 +0000 | [diff] [blame] | 256 | int result_offset_after_shift, int min, int max) |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 257 | { |
| 258 | // Perform validate step |
| 259 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, output); |
Georgios Pinitas | bb081ca | 2018-11-08 10:22:01 +0000 | [diff] [blame] | 260 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), (bias != nullptr) ? bias->info() : nullptr, output->info(), min, max)); |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 261 | |
| 262 | _input = input; |
| 263 | _bias = bias; |
| 264 | _output = output; |
| 265 | _result_fixedpoint_multiplier = result_fixedpoint_multiplier; |
| 266 | _result_shift = result_shift; |
| 267 | _result_offset_after_shift = result_offset_after_shift; |
| 268 | _min = min; |
| 269 | _max = max; |
| 270 | |
| 271 | // Configure kernel window |
| 272 | auto win_config = validate_and_configure_window(input->info(), (bias != nullptr) ? bias->info() : nullptr, output->info()); |
| 273 | ARM_COMPUTE_ERROR_THROW_ON(win_config.first); |
| 274 | INEKernel::configure(win_config.second); |
| 275 | |
| 276 | // Check if we need to clamp the result using min and max |
| 277 | const bool is_bounded_relu = ((min != max) && !(min == 0 && max == 255)); |
| 278 | _func = is_bounded_relu ? &NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel::run<true> : &NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel::run<false>; |
| 279 | } |
| 280 | |
Georgios Pinitas | bb081ca | 2018-11-08 10:22:01 +0000 | [diff] [blame] | 281 | Status NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel::validate(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, int min, int max) |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 282 | { |
Chunosov | 5124be5 | 2017-11-22 20:42:13 +0700 | [diff] [blame] | 283 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, output); |
Georgios Pinitas | bb081ca | 2018-11-08 10:22:01 +0000 | [diff] [blame] | 284 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, bias, output, min, max)); |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 285 | ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), |
| 286 | (bias != nullptr) ? bias->clone().get() : nullptr, |
| 287 | output->clone().get()) |
| 288 | .first); |
| 289 | |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 290 | return Status{}; |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | void NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel::run(const Window &window, const ThreadInfo &info) |
| 294 | { |
| 295 | ARM_COMPUTE_UNUSED(info); |
| 296 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 297 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window); |
| 298 | |
| 299 | (this->*_func)(window); |
| 300 | } |