Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2020 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 | */ |
| 24 | #include "arm_compute/core/NEON/kernels/NENormalizationLayerKernel.h" |
| 25 | |
Georgios Pinitas | 7f32d01 | 2018-10-11 18:41:19 +0100 | [diff] [blame] | 26 | #include "arm_compute/core/AccessWindowStatic.h" |
Anthony Barbier | eaefd00 | 2018-07-20 17:49:35 +0100 | [diff] [blame] | 27 | #include "arm_compute/core/CPP/Validate.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 28 | #include "arm_compute/core/Error.h" |
| 29 | #include "arm_compute/core/Helpers.h" |
| 30 | #include "arm_compute/core/NEON/NEFixedPoint.h" |
| 31 | #include "arm_compute/core/NEON/NEMath.h" |
Michalis Spyrou | 0c71d0b | 2018-11-22 11:22:18 +0000 | [diff] [blame] | 32 | #include "arm_compute/core/NEON/wrapper/wrapper.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 33 | #include "arm_compute/core/TensorInfo.h" |
| 34 | #include "arm_compute/core/Utils.h" |
| 35 | #include "arm_compute/core/Validate.h" |
| 36 | #include "arm_compute/core/Window.h" |
| 37 | |
Manuel Bottini | f2c714b | 2020-06-15 16:50:35 +0100 | [diff] [blame] | 38 | namespace arm_compute |
| 39 | { |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 40 | namespace |
| 41 | { |
| 42 | Status validate_arguments(const ITensorInfo *input, const ITensorInfo *input_squared, const ITensorInfo *output, const NormalizationLayerInfo &norm_info) |
| 43 | { |
| 44 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, input_squared, output); |
Anthony Barbier | eaefd00 | 2018-07-20 17:49:35 +0100 | [diff] [blame] | 45 | ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(input); |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame] | 46 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::F16, DataType::F32); |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 47 | |
| 48 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, input_squared); |
| 49 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(input, input_squared); |
| 50 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(!(norm_info.norm_size() % 2), "Normalization size should be odd"); |
| 51 | |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 52 | // Checks performed when output is configured |
| 53 | if(output->total_size() != 0) |
| 54 | { |
| 55 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output); |
| 56 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(input, output); |
Michalis Spyrou | 0c71d0b | 2018-11-22 11:22:18 +0000 | [diff] [blame] | 57 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_LAYOUT(input, output); |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | return Status{}; |
| 61 | } |
| 62 | |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 63 | } // namespace |
| 64 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 65 | NENormalizationLayerKernel::NENormalizationLayerKernel() |
Manuel Bottini | f2c714b | 2020-06-15 16:50:35 +0100 | [diff] [blame] | 66 | : _func(nullptr), _input(nullptr), _input_squared(nullptr), _output(nullptr), _norm_info(NormType::IN_MAP_1D) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 67 | { |
| 68 | } |
| 69 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 70 | void NENormalizationLayerKernel::configure(const ITensor *input, const ITensor *input_squared, ITensor *output, NormalizationLayerInfo norm_info) |
| 71 | { |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 72 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, input_squared, output); |
Georgios Pinitas | 09004ca | 2017-07-03 17:30:14 +0100 | [diff] [blame] | 73 | // Output tensor auto initialization if not yet initialized |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 74 | auto_init_if_empty(*output->info(), *input->info()); |
| 75 | |
| 76 | // Perform validation step |
| 77 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), input_squared->info(), output->info(), norm_info)); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 78 | |
Manuel Bottini | f2c714b | 2020-06-15 16:50:35 +0100 | [diff] [blame] | 79 | const unsigned int norm_idx = get_normalization_dimension_index(input->info()->data_layout(), norm_info); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 80 | |
| 81 | _input = input; |
| 82 | _input_squared = input_squared; |
| 83 | _output = output; |
| 84 | _norm_info = norm_info; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 85 | |
Pablo Tello | df24618 | 2017-07-03 16:25:09 +0100 | [diff] [blame] | 86 | switch(_input->info()->data_type()) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 87 | { |
Pablo Tello | df24618 | 2017-07-03 16:25:09 +0100 | [diff] [blame] | 88 | case DataType::F32: |
| 89 | { |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 90 | switch(norm_idx) |
Pablo Tello | df24618 | 2017-07-03 16:25:09 +0100 | [diff] [blame] | 91 | { |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 92 | case 0: |
| 93 | { |
| 94 | if(norm_info.type() == NormType::IN_MAP_2D) |
| 95 | { |
Michalis Spyrou | 0c71d0b | 2018-11-22 11:22:18 +0000 | [diff] [blame] | 96 | _func = &NENormalizationLayerKernel::normalize_float<float, 4, 0, true>; |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 97 | } |
| 98 | else |
| 99 | { |
Michalis Spyrou | 0c71d0b | 2018-11-22 11:22:18 +0000 | [diff] [blame] | 100 | _func = &NENormalizationLayerKernel::normalize_float<float, 4, 0, false>; |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 101 | } |
Pablo Tello | df24618 | 2017-07-03 16:25:09 +0100 | [diff] [blame] | 102 | break; |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 103 | } |
Michalis Spyrou | 0c71d0b | 2018-11-22 11:22:18 +0000 | [diff] [blame] | 104 | case 1: |
| 105 | if(norm_info.type() == NormType::IN_MAP_2D) |
| 106 | { |
| 107 | _func = &NENormalizationLayerKernel::normalize_float<float, 4, 1, true>; |
| 108 | } |
| 109 | else |
| 110 | { |
| 111 | _func = &NENormalizationLayerKernel::normalize_float<float, 4, 1, false>; |
| 112 | } |
| 113 | break; |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 114 | case 2: |
Michalis Spyrou | 0c71d0b | 2018-11-22 11:22:18 +0000 | [diff] [blame] | 115 | _func = &NENormalizationLayerKernel::normalize_float<float, 4, 2, false>; |
Pablo Tello | df24618 | 2017-07-03 16:25:09 +0100 | [diff] [blame] | 116 | break; |
| 117 | default: |
Pablo Tello | df24618 | 2017-07-03 16:25:09 +0100 | [diff] [blame] | 118 | break; |
| 119 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 120 | break; |
Pablo Tello | df24618 | 2017-07-03 16:25:09 +0100 | [diff] [blame] | 121 | } |
Gian Marco Iodice | f2cde9b | 2018-08-23 15:29:16 +0100 | [diff] [blame] | 122 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Pablo Tello | df24618 | 2017-07-03 16:25:09 +0100 | [diff] [blame] | 123 | case DataType::F16: |
| 124 | { |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 125 | switch(norm_idx) |
Pablo Tello | df24618 | 2017-07-03 16:25:09 +0100 | [diff] [blame] | 126 | { |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 127 | case 0: |
| 128 | { |
| 129 | if(norm_info.type() == NormType::IN_MAP_2D) |
| 130 | { |
Michalis Spyrou | 0c71d0b | 2018-11-22 11:22:18 +0000 | [diff] [blame] | 131 | _func = &NENormalizationLayerKernel::normalize_float<float16_t, 8, 0, true>; |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 132 | } |
| 133 | else |
| 134 | { |
Michalis Spyrou | 0c71d0b | 2018-11-22 11:22:18 +0000 | [diff] [blame] | 135 | _func = &NENormalizationLayerKernel::normalize_float<float16_t, 8, 0, false>; |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 136 | } |
Pablo Tello | df24618 | 2017-07-03 16:25:09 +0100 | [diff] [blame] | 137 | break; |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 138 | } |
Michalis Spyrou | 0c71d0b | 2018-11-22 11:22:18 +0000 | [diff] [blame] | 139 | case 1: |
| 140 | if(norm_info.type() == NormType::IN_MAP_2D) |
| 141 | { |
| 142 | _func = &NENormalizationLayerKernel::normalize_float<float16_t, 8, 1, true>; |
| 143 | } |
| 144 | else |
| 145 | { |
| 146 | _func = &NENormalizationLayerKernel::normalize_float<float16_t, 8, 1, false>; |
| 147 | } |
| 148 | break; |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 149 | case 2: |
Michalis Spyrou | 0c71d0b | 2018-11-22 11:22:18 +0000 | [diff] [blame] | 150 | _func = &NENormalizationLayerKernel::normalize_float<float16_t, 8, 2, false>; |
Pablo Tello | df24618 | 2017-07-03 16:25:09 +0100 | [diff] [blame] | 151 | break; |
| 152 | default: |
Pablo Tello | df24618 | 2017-07-03 16:25:09 +0100 | [diff] [blame] | 153 | break; |
| 154 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 155 | break; |
Pablo Tello | df24618 | 2017-07-03 16:25:09 +0100 | [diff] [blame] | 156 | } |
Gian Marco Iodice | f2cde9b | 2018-08-23 15:29:16 +0100 | [diff] [blame] | 157 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 158 | default: |
| 159 | ARM_COMPUTE_ERROR("NOT SUPPORTED!"); |
| 160 | } |
| 161 | |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 162 | // Configure kernel window |
Manuel Bottini | f2c714b | 2020-06-15 16:50:35 +0100 | [diff] [blame] | 163 | Window win = calculate_max_window(*input->info(), Steps()); |
| 164 | Coordinates coord; |
| 165 | coord.set_num_dimensions(output->info()->num_dimensions()); |
| 166 | output->info()->set_valid_region(ValidRegion(coord, output->info()->tensor_shape())); |
| 167 | INEKernel::configure(win); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 168 | } |
| 169 | |
Michalis Spyrou | 0c71d0b | 2018-11-22 11:22:18 +0000 | [diff] [blame] | 170 | template <typename T, unsigned int S, unsigned int dim, bool do_2D_norm> |
Pablo Tello | df24618 | 2017-07-03 16:25:09 +0100 | [diff] [blame] | 171 | void NENormalizationLayerKernel::normalize_float(const Window &window) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 172 | { |
Michalis Spyrou | 0c71d0b | 2018-11-22 11:22:18 +0000 | [diff] [blame] | 173 | /** NEON vector tag type. */ |
| 174 | using ExactTagType = typename wrapper::traits::neon_vector<T, S>::tag_type; |
| 175 | |
Manuel Bottini | f2c714b | 2020-06-15 16:50:35 +0100 | [diff] [blame] | 176 | Window win(window); |
| 177 | win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 178 | |
Manuel Bottini | f2c714b | 2020-06-15 16:50:35 +0100 | [diff] [blame] | 179 | const auto window_start_x = static_cast<int>(window.x().start()); |
| 180 | const auto window_end_x = static_cast<int>(window.x().end()); |
| 181 | const int window_step_x = S; |
| 182 | |
| 183 | Iterator input(_input, win); |
| 184 | Iterator input_squared(_input_squared, win); |
| 185 | Iterator output(_output, win); |
| 186 | |
| 187 | const int dim_y = _input->info()->data_layout() == DataLayout::NCHW ? 1 : 2; |
| 188 | const int radius = _norm_info.norm_size() / 2; |
| 189 | const int input_squared_stride_x = _input_squared->info()->strides_in_bytes()[0]; |
| 190 | const int input_squared_stride_slice = _input_squared->info()->strides_in_bytes()[dim]; |
| 191 | const int input_squared_stride_row = _input_squared->info()->strides_in_bytes()[dim_y]; |
| 192 | |
Georgios Pinitas | 7f32d01 | 2018-10-11 18:41:19 +0100 | [diff] [blame] | 193 | const int max_right = _input->info()->dimension(dim) - 1; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 194 | const int max_bottom = _input->info()->dimension(dim_y) - 1; |
| 195 | |
Michalis Spyrou | 0c71d0b | 2018-11-22 11:22:18 +0000 | [diff] [blame] | 196 | const auto coeff_vec = wrapper::vdup_n(static_cast<T>(_norm_info.scale_coeff()), ExactTagType{}); |
| 197 | const auto beta_vec = wrapper::vdup_n(static_cast<T>(_norm_info.beta()), ExactTagType{}); |
| 198 | const auto kappa_vec = wrapper::vdup_n(static_cast<T>(_norm_info.kappa()), ExactTagType{}); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 199 | |
Manuel Bottini | f2c714b | 2020-06-15 16:50:35 +0100 | [diff] [blame] | 200 | auto sequential_normalization = [&](const int x, const Coordinates & id, const int current_row, const int first_row, const int last_row, const T * input_ptr, const uint8_t *input_squared_start_ptr, |
| 201 | T * output_ptr) |
Michalis Spyrou | 0c71d0b | 2018-11-22 11:22:18 +0000 | [diff] [blame] | 202 | { |
Manuel Bottini | f2c714b | 2020-06-15 16:50:35 +0100 | [diff] [blame] | 203 | const int current_slice = dim == 0 ? x : id[dim]; |
| 204 | const int first_slice = std::max(current_slice - radius, 0); |
Michalis Spyrou | 0c71d0b | 2018-11-22 11:22:18 +0000 | [diff] [blame] | 205 | const int last_slice = std::min(current_slice + radius, max_right); |
| 206 | |
Manuel Bottini | f2c714b | 2020-06-15 16:50:35 +0100 | [diff] [blame] | 207 | const uint8_t *const input_squared_x_ptr = input_squared_start_ptr + x * input_squared_stride_x; |
Michalis Spyrou | 0c71d0b | 2018-11-22 11:22:18 +0000 | [diff] [blame] | 208 | // Accumulate 2D In-Map values |
Manuel Bottini | f2c714b | 2020-06-15 16:50:35 +0100 | [diff] [blame] | 209 | auto accu = static_cast<T>(0.f); |
| 210 | for(int j = first_row; j <= last_row; ++j) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 211 | { |
Michalis Spyrou | 0c71d0b | 2018-11-22 11:22:18 +0000 | [diff] [blame] | 212 | // Compute row displacement |
Manuel Bottini | f2c714b | 2020-06-15 16:50:35 +0100 | [diff] [blame] | 213 | const uint8_t *const input_squared_ptr = input_squared_x_ptr + (j - current_row) * input_squared_stride_row; |
Michalis Spyrou | 0c71d0b | 2018-11-22 11:22:18 +0000 | [diff] [blame] | 214 | for(int i = first_slice; i <= last_slice; ++i) |
Pablo Tello | df24618 | 2017-07-03 16:25:09 +0100 | [diff] [blame] | 215 | { |
Manuel Bottini | f2c714b | 2020-06-15 16:50:35 +0100 | [diff] [blame] | 216 | accu += *reinterpret_cast<const T *>(input_squared_ptr + (i - current_slice) * input_squared_stride_slice); |
Pablo Tello | df24618 | 2017-07-03 16:25:09 +0100 | [diff] [blame] | 217 | } |
Michalis Spyrou | 0c71d0b | 2018-11-22 11:22:18 +0000 | [diff] [blame] | 218 | } |
Pablo Tello | df24618 | 2017-07-03 16:25:09 +0100 | [diff] [blame] | 219 | |
Michalis Spyrou | 0c71d0b | 2018-11-22 11:22:18 +0000 | [diff] [blame] | 220 | // Normalize |
Manuel Bottini | f2c714b | 2020-06-15 16:50:35 +0100 | [diff] [blame] | 221 | const auto normalized = std::pow(accu * static_cast<T>(_norm_info.scale_coeff()) + static_cast<T>(_norm_info.kappa()), _norm_info.beta()); |
| 222 | const auto normalized_pixel = (*(input_ptr + x)) / normalized; |
| 223 | *(output_ptr + x) = normalized_pixel; |
| 224 | }; |
| 225 | |
| 226 | execute_window_loop(win, [&](const Coordinates & id) |
| 227 | { |
| 228 | const auto input_ptr = reinterpret_cast<const T *>(input.ptr()); |
| 229 | auto output_ptr = reinterpret_cast<T *>(output.ptr()); |
| 230 | |
| 231 | // Get range to normalize |
| 232 | const int current_row = do_2D_norm ? id[dim_y] : 0; |
| 233 | const int first_row = do_2D_norm ? std::max(current_row - radius, 0) : 0; |
| 234 | const int last_row = do_2D_norm ? std::min(current_row + radius, max_bottom) : 0; |
| 235 | |
| 236 | int x = window_start_x; |
| 237 | // Compute serially starting elements for the case x dimension is width |
| 238 | for(; x < radius && x < window_end_x && dim == 0; ++x) |
| 239 | { |
| 240 | sequential_normalization(x, id, current_row, first_row, last_row, input_ptr, input_squared.ptr(), output_ptr); |
| 241 | } |
| 242 | |
| 243 | // Compute vectorized |
| 244 | for(; x <= window_end_x - window_step_x - radius; x += window_step_x) |
| 245 | { |
| 246 | const int current_slice = dim == 0 ? x : id[dim]; |
| 247 | const int first_slice = std::max(current_slice - radius, 0); |
| 248 | const int last_slice = std::min(current_slice + radius, max_right); |
| 249 | |
| 250 | const uint8_t *const input_squared_x_ptr = input_squared.ptr() + x * input_squared_stride_x; |
| 251 | // Accumulate 2D In-Map values |
| 252 | auto accu = wrapper::vdup_n(static_cast<T>(0.f), ExactTagType{}); |
| 253 | for(int j = first_row; j <= last_row; ++j) |
| 254 | { |
| 255 | // Compute row displacement |
| 256 | const uint8_t *const input_squared_ptr = input_squared_x_ptr + (j - current_row) * input_squared_stride_row; |
| 257 | for(int i = first_slice; i <= last_slice; ++i) |
| 258 | { |
| 259 | accu = wrapper::vadd(accu, wrapper::vloadq(reinterpret_cast<const T *>(input_squared_ptr + (i - current_slice) * input_squared_stride_slice))); |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | // Normalize |
| 264 | const auto normalized = wrapper::vpow(wrapper::vmla(kappa_vec, coeff_vec, accu), beta_vec); |
| 265 | const auto normalized_pixel = wrapper::vmul(wrapper::vloadq(input_ptr + x), wrapper::vinv(normalized)); |
| 266 | wrapper::vstore(reinterpret_cast<T *>(output_ptr + x), normalized_pixel); |
| 267 | } |
| 268 | |
| 269 | // Compute left-over elements |
| 270 | for(; x < window_end_x; ++x) |
| 271 | { |
| 272 | sequential_normalization(x, id, current_row, first_row, last_row, input_ptr, input_squared.ptr(), output_ptr); |
| 273 | } |
Michalis Spyrou | 0c71d0b | 2018-11-22 11:22:18 +0000 | [diff] [blame] | 274 | }, |
| 275 | input, input_squared, output); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 276 | } |
| 277 | |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 278 | Status NENormalizationLayerKernel::validate(const ITensorInfo *input, const ITensorInfo *input_squared, const ITensorInfo *output, const NormalizationLayerInfo norm_info) |
| 279 | { |
| 280 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, input_squared, output, norm_info)); |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 281 | |
| 282 | return Status{}; |
| 283 | } |
| 284 | |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 285 | void NENormalizationLayerKernel::run(const Window &window, const ThreadInfo &info) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 286 | { |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 287 | ARM_COMPUTE_UNUSED(info); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 288 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 289 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window); |
| 290 | ARM_COMPUTE_ERROR_ON(_func == nullptr); |
| 291 | |
| 292 | // Run function |
| 293 | (this->*_func)(window); |
| 294 | } |
Manuel Bottini | f2c714b | 2020-06-15 16:50:35 +0100 | [diff] [blame] | 295 | } // namespace arm_compute |