Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Pablo Marquez Tello | ba93371 | 2023-11-13 15:57:54 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2021, 2023 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 | */ |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 24 | #include "src/core/NEON/kernels/NENormalizationLayerKernel.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 25 | |
| 26 | #include "arm_compute/core/Error.h" |
| 27 | #include "arm_compute/core/Helpers.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 28 | #include "arm_compute/core/TensorInfo.h" |
| 29 | #include "arm_compute/core/Utils.h" |
| 30 | #include "arm_compute/core/Validate.h" |
| 31 | #include "arm_compute/core/Window.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 32 | |
Pablo Marquez Tello | ba93371 | 2023-11-13 15:57:54 +0000 | [diff] [blame] | 33 | #include "src/core/common/Registrars.h" |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame] | 34 | #include "src/core/CPP/Validate.h" |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame] | 35 | #include "src/core/helpers/AutoConfiguration.h" |
| 36 | #include "src/core/helpers/NormalizationHelpers.h" |
| 37 | #include "src/core/helpers/WindowHelpers.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 38 | #include "src/core/NEON/NEFixedPoint.h" |
| 39 | #include "src/core/NEON/NEMath.h" |
| 40 | #include "src/core/NEON/wrapper/wrapper.h" |
Pablo Marquez Tello | ba93371 | 2023-11-13 15:57:54 +0000 | [diff] [blame] | 41 | #include "src/cpu/kernels/norm_layer/generic/neon/impl.h" |
| 42 | #include "src/cpu/kernels/norm_layer/generic/neon/list.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 43 | |
Manuel Bottini | f2c714b | 2020-06-15 16:50:35 +0100 | [diff] [blame] | 44 | namespace arm_compute |
| 45 | { |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 46 | namespace |
| 47 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 48 | Status validate_arguments(const ITensorInfo *input, |
| 49 | const ITensorInfo *input_squared, |
| 50 | const ITensorInfo *output, |
| 51 | const NormalizationLayerInfo &norm_info) |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 52 | { |
| 53 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, input_squared, output); |
Anthony Barbier | eaefd00 | 2018-07-20 17:49:35 +0100 | [diff] [blame] | 54 | ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(input); |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame] | 55 | 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] | 56 | |
| 57 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, input_squared); |
| 58 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(input, input_squared); |
| 59 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(!(norm_info.norm_size() % 2), "Normalization size should be odd"); |
| 60 | |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 61 | // Checks performed when output is configured |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 62 | if (output->total_size() != 0) |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 63 | { |
| 64 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output); |
| 65 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(input, output); |
Michalis Spyrou | 0c71d0b | 2018-11-22 11:22:18 +0000 | [diff] [blame] | 66 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_LAYOUT(input, output); |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | return Status{}; |
| 70 | } |
| 71 | |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 72 | } // namespace |
| 73 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 74 | NENormalizationLayerKernel::NENormalizationLayerKernel() |
Manuel Bottini | f2c714b | 2020-06-15 16:50:35 +0100 | [diff] [blame] | 75 | : _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] | 76 | { |
| 77 | } |
| 78 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 79 | void NENormalizationLayerKernel::configure(const ITensor *input, |
| 80 | const ITensor *input_squared, |
| 81 | ITensor *output, |
| 82 | NormalizationLayerInfo norm_info) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 83 | { |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 84 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, input_squared, output); |
Georgios Pinitas | 09004ca | 2017-07-03 17:30:14 +0100 | [diff] [blame] | 85 | // Output tensor auto initialization if not yet initialized |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 86 | auto_init_if_empty(*output->info(), *input->info()); |
| 87 | |
| 88 | // Perform validation step |
| 89 | 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] | 90 | |
Manuel Bottini | f2c714b | 2020-06-15 16:50:35 +0100 | [diff] [blame] | 91 | 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] | 92 | |
| 93 | _input = input; |
| 94 | _input_squared = input_squared; |
| 95 | _output = output; |
| 96 | _norm_info = norm_info; |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 97 | switch (_input->info()->data_type()) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 98 | { |
Pablo Tello | df24618 | 2017-07-03 16:25:09 +0100 | [diff] [blame] | 99 | case DataType::F32: |
| 100 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 101 | switch (norm_idx) |
Pablo Tello | df24618 | 2017-07-03 16:25:09 +0100 | [diff] [blame] | 102 | { |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 103 | case 0: |
| 104 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 105 | if (norm_info.type() == NormType::IN_MAP_2D) |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 106 | { |
Pablo Marquez Tello | ba93371 | 2023-11-13 15:57:54 +0000 | [diff] [blame] | 107 | _func = REGISTER_FP32_NEON(cpu::neon_normalize_float32_4_0_2D); |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 108 | } |
| 109 | else |
| 110 | { |
Pablo Marquez Tello | ba93371 | 2023-11-13 15:57:54 +0000 | [diff] [blame] | 111 | _func = REGISTER_FP32_NEON(cpu::neon_normalize_float32_4_0); |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 112 | } |
Pablo Tello | df24618 | 2017-07-03 16:25:09 +0100 | [diff] [blame] | 113 | break; |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 114 | } |
Michalis Spyrou | 0c71d0b | 2018-11-22 11:22:18 +0000 | [diff] [blame] | 115 | case 1: |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 116 | if (norm_info.type() == NormType::IN_MAP_2D) |
Michalis Spyrou | 0c71d0b | 2018-11-22 11:22:18 +0000 | [diff] [blame] | 117 | { |
Pablo Marquez Tello | ba93371 | 2023-11-13 15:57:54 +0000 | [diff] [blame] | 118 | _func = REGISTER_FP32_NEON(cpu::neon_normalize_float32_4_1_2D); |
Michalis Spyrou | 0c71d0b | 2018-11-22 11:22:18 +0000 | [diff] [blame] | 119 | } |
| 120 | else |
| 121 | { |
Pablo Marquez Tello | ba93371 | 2023-11-13 15:57:54 +0000 | [diff] [blame] | 122 | _func = REGISTER_FP32_NEON(cpu::neon_normalize_float32_4_1); |
Michalis Spyrou | 0c71d0b | 2018-11-22 11:22:18 +0000 | [diff] [blame] | 123 | } |
| 124 | break; |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 125 | case 2: |
Pablo Marquez Tello | ba93371 | 2023-11-13 15:57:54 +0000 | [diff] [blame] | 126 | _func = REGISTER_FP32_NEON(cpu::neon_normalize_float32_4_2); |
Pablo Tello | df24618 | 2017-07-03 16:25:09 +0100 | [diff] [blame] | 127 | break; |
| 128 | default: |
Pablo Tello | df24618 | 2017-07-03 16:25:09 +0100 | [diff] [blame] | 129 | break; |
| 130 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 131 | break; |
Pablo Tello | df24618 | 2017-07-03 16:25:09 +0100 | [diff] [blame] | 132 | } |
Pablo Marquez Tello | ba93371 | 2023-11-13 15:57:54 +0000 | [diff] [blame] | 133 | #ifdef ARM_COMPUTE_ENABLE_FP16 |
Pablo Tello | df24618 | 2017-07-03 16:25:09 +0100 | [diff] [blame] | 134 | case DataType::F16: |
| 135 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 136 | switch (norm_idx) |
Pablo Tello | df24618 | 2017-07-03 16:25:09 +0100 | [diff] [blame] | 137 | { |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 138 | case 0: |
| 139 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 140 | if (norm_info.type() == NormType::IN_MAP_2D) |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 141 | { |
Pablo Marquez Tello | ba93371 | 2023-11-13 15:57:54 +0000 | [diff] [blame] | 142 | _func = REGISTER_FP16_NEON(cpu::neon_normalize_float16_8_0_2D); |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 143 | } |
| 144 | else |
| 145 | { |
Pablo Marquez Tello | ba93371 | 2023-11-13 15:57:54 +0000 | [diff] [blame] | 146 | _func = REGISTER_FP16_NEON(cpu::neon_normalize_float16_8_0); |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 147 | } |
Pablo Tello | df24618 | 2017-07-03 16:25:09 +0100 | [diff] [blame] | 148 | break; |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 149 | } |
Michalis Spyrou | 0c71d0b | 2018-11-22 11:22:18 +0000 | [diff] [blame] | 150 | case 1: |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 151 | if (norm_info.type() == NormType::IN_MAP_2D) |
Michalis Spyrou | 0c71d0b | 2018-11-22 11:22:18 +0000 | [diff] [blame] | 152 | { |
Pablo Marquez Tello | ba93371 | 2023-11-13 15:57:54 +0000 | [diff] [blame] | 153 | _func = REGISTER_FP16_NEON(cpu::neon_normalize_float16_8_1_2D); |
Michalis Spyrou | 0c71d0b | 2018-11-22 11:22:18 +0000 | [diff] [blame] | 154 | } |
| 155 | else |
| 156 | { |
Pablo Marquez Tello | ba93371 | 2023-11-13 15:57:54 +0000 | [diff] [blame] | 157 | _func = REGISTER_FP16_NEON(cpu::neon_normalize_float16_8_1); |
Michalis Spyrou | 0c71d0b | 2018-11-22 11:22:18 +0000 | [diff] [blame] | 158 | } |
| 159 | break; |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 160 | case 2: |
Pablo Marquez Tello | ba93371 | 2023-11-13 15:57:54 +0000 | [diff] [blame] | 161 | _func = REGISTER_FP16_NEON(cpu::neon_normalize_float16_8_2); |
Pablo Tello | df24618 | 2017-07-03 16:25:09 +0100 | [diff] [blame] | 162 | break; |
| 163 | default: |
Pablo Tello | df24618 | 2017-07-03 16:25:09 +0100 | [diff] [blame] | 164 | break; |
| 165 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 166 | break; |
Pablo Tello | df24618 | 2017-07-03 16:25:09 +0100 | [diff] [blame] | 167 | } |
Pablo Marquez Tello | ba93371 | 2023-11-13 15:57:54 +0000 | [diff] [blame] | 168 | #endif /* ARM_COMPUTE_ENABLE_FP16 */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 169 | default: |
| 170 | ARM_COMPUTE_ERROR("NOT SUPPORTED!"); |
| 171 | } |
| 172 | |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 173 | // Configure kernel window |
SiCongLi | b88272e | 2021-02-24 15:40:57 +0000 | [diff] [blame] | 174 | Window win = calculate_max_window(*input->info(), Steps()); |
Manuel Bottini | f2c714b | 2020-06-15 16:50:35 +0100 | [diff] [blame] | 175 | INEKernel::configure(win); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 176 | } |
| 177 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 178 | Status NENormalizationLayerKernel::validate(const ITensorInfo *input, |
| 179 | const ITensorInfo *input_squared, |
| 180 | const ITensorInfo *output, |
| 181 | const NormalizationLayerInfo norm_info) |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 182 | { |
| 183 | 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] | 184 | |
| 185 | return Status{}; |
| 186 | } |
| 187 | |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 188 | void NENormalizationLayerKernel::run(const Window &window, const ThreadInfo &info) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 189 | { |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 190 | ARM_COMPUTE_UNUSED(info); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 191 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 192 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window); |
| 193 | ARM_COMPUTE_ERROR_ON(_func == nullptr); |
| 194 | |
| 195 | // Run function |
Pablo Marquez Tello | ba93371 | 2023-11-13 15:57:54 +0000 | [diff] [blame] | 196 | (*_func)(window, _input, _input_squared, _output, _norm_info); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 197 | } |
Sheri Zhang | ac6499a | 2021-02-10 15:32:38 +0000 | [diff] [blame] | 198 | } // namespace arm_compute |