Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Matthew Bentham | 314d3e2 | 2023-06-23 10:53:52 +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 | */ |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame] | 24 | #include "src/core/CL/kernels/CLNormalizationLayerKernel.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 25 | |
| 26 | #include "arm_compute/core/CL/CLHelpers.h" |
| 27 | #include "arm_compute/core/CL/CLKernelLibrary.h" |
| 28 | #include "arm_compute/core/CL/ICLTensor.h" |
| 29 | #include "arm_compute/core/Helpers.h" |
| 30 | #include "arm_compute/core/TensorInfo.h" |
| 31 | #include "arm_compute/core/Utils.h" |
Matthew Bentham | 314d3e2 | 2023-06-23 10:53:52 +0000 | [diff] [blame] | 32 | #include "arm_compute/core/utils/helpers/AdjustVecSize.h" |
| 33 | #include "arm_compute/core/utils/StringUtils.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 34 | #include "arm_compute/core/Window.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 35 | |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame] | 36 | #include "src/core/AccessWindowStatic.h" |
| 37 | #include "src/core/CL/CLValidate.h" |
| 38 | #include "src/core/helpers/AutoConfiguration.h" |
| 39 | #include "src/core/helpers/NormalizationHelpers.h" |
| 40 | #include "src/core/helpers/WindowHelpers.h" |
Matthew Bentham | 758b5ba | 2020-03-05 23:37:48 +0000 | [diff] [blame] | 41 | #include "support/StringSupport.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 42 | |
Manuel Bottini | 21c2895 | 2021-04-08 12:50:12 +0100 | [diff] [blame] | 43 | namespace arm_compute |
| 44 | { |
Giorgio Arena | c23b633 | 2017-11-28 15:23:51 +0000 | [diff] [blame] | 45 | namespace |
| 46 | { |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 47 | Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output, NormalizationLayerInfo norm_info) |
Giorgio Arena | c23b633 | 2017-11-28 15:23:51 +0000 | [diff] [blame] | 48 | { |
Vidhya Sudhan Loganathan | f1f4906 | 2018-05-25 13:21:26 +0100 | [diff] [blame] | 49 | ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(input); |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame] | 50 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::F16, DataType::F32); |
Michele Di Giorgio | 9d3a831 | 2018-11-20 12:31:24 +0000 | [diff] [blame] | 51 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_LAYOUT_NOT_IN(input, DataLayout::NCHW, DataLayout::NHWC); |
Giorgio Arena | c23b633 | 2017-11-28 15:23:51 +0000 | [diff] [blame] | 52 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(output); |
| 53 | |
| 54 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(!(norm_info.norm_size() % 2), "Normalization size should be odd"); |
Giorgio Arena | c23b633 | 2017-11-28 15:23:51 +0000 | [diff] [blame] | 55 | |
Giorgio Arena | c23b633 | 2017-11-28 15:23:51 +0000 | [diff] [blame] | 56 | // Checks performed when output is configured |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 57 | if (output->total_size() != 0) |
Giorgio Arena | c23b633 | 2017-11-28 15:23:51 +0000 | [diff] [blame] | 58 | { |
| 59 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output); |
Michele Di Giorgio | 9d3a831 | 2018-11-20 12:31:24 +0000 | [diff] [blame] | 60 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_LAYOUT(input, output); |
Giorgio Arena | c23b633 | 2017-11-28 15:23:51 +0000 | [diff] [blame] | 61 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(input, output); |
Giorgio Arena | c23b633 | 2017-11-28 15:23:51 +0000 | [diff] [blame] | 62 | } |
| 63 | |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 64 | return Status{}; |
Giorgio Arena | c23b633 | 2017-11-28 15:23:51 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 67 | std::pair<Status, Window> |
| 68 | validate_and_configure_window(ITensorInfo *input, ITensorInfo *output, NormalizationLayerInfo norm_info) |
Giorgio Arena | c23b633 | 2017-11-28 15:23:51 +0000 | [diff] [blame] | 69 | { |
Giorgio Arena | f6a43c5 | 2017-12-01 12:16:25 +0000 | [diff] [blame] | 70 | // Output tensor auto initialization if not yet initialized |
| 71 | auto_init_if_empty(*output, *input->clone()); |
| 72 | |
Manuel Bottini | 21c2895 | 2021-04-08 12:50:12 +0100 | [diff] [blame] | 73 | bool window_changed = false; |
| 74 | Window win; |
| 75 | const DataLayout data_layout = input->data_layout(); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 76 | if (data_layout == DataLayout::NCHW) |
Georgios Pinitas | 7f32d01 | 2018-10-11 18:41:19 +0100 | [diff] [blame] | 77 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 78 | const unsigned int vec_size_x = |
| 79 | adjust_vec_size(max_cl_vector_width / input->element_size(), input->dimension(0)); |
SiCongLi | aed61f2 | 2021-08-26 17:44:08 +0100 | [diff] [blame] | 80 | const unsigned int norm_idx = get_normalization_dimension_index(input->data_layout(), norm_info); |
| 81 | const bool is_norm_across_width = norm_idx == 0; |
Manuel Bottini | 21c2895 | 2021-04-08 12:50:12 +0100 | [diff] [blame] | 82 | |
SiCongLi | aed61f2 | 2021-08-26 17:44:08 +0100 | [diff] [blame] | 83 | const unsigned int norm_radius = norm_info.norm_size() / 2; |
| 84 | // Border / padding calculation: |
| 85 | // For NCHW no border handling is impelmeneted in the kernel in the x axis. |
| 86 | // This means the x axis is fully-padded depending on vec_size_x and norm_size |
| 87 | // E.G. for input x dimension = 3, norm_size = 3 (radius = 1), vec_size_x = 2 ('#' is element 'p' is padding): |
| 88 | // In : |p|#|#|#|p|p| |
| 89 | // Out: |#|#|#|p| |
| 90 | // The output has 1 right padding because of the vec_size_x. |
| 91 | // The input has 1 left padding because radius = 1. |
| 92 | // The input has 2 right padding because of radius = 1 AND because of the extra output padding |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 93 | const unsigned int border_width_left = is_norm_across_width ? norm_radius : 0; |
| 94 | const unsigned int border_width_right = |
| 95 | is_norm_across_width ? norm_radius + (vec_size_x - input->dimension(0) % vec_size_x) : 0; |
| 96 | const BorderSize border_size = BorderSize(0, border_width_right, 0, border_width_left); |
Manuel Bottini | 21c2895 | 2021-04-08 12:50:12 +0100 | [diff] [blame] | 97 | |
| 98 | win = calculate_max_window(*input, Steps(vec_size_x)); |
| 99 | |
| 100 | // We do not use a Rectangle window for IN_MAP_2D as we clamp the top and bottom accesses inside the kernel, avoiding padding |
| 101 | // Reads can occur within the valid region of the input |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 102 | if (is_norm_across_width) |
Manuel Bottini | 21c2895 | 2021-04-08 12:50:12 +0100 | [diff] [blame] | 103 | { |
| 104 | AccessWindowStatic input_access(input, -border_size.left, 0, input->dimension(0) + border_size.right, 0); |
| 105 | window_changed = window_changed || update_window_and_padding(win, input_access); |
| 106 | } |
| 107 | else |
| 108 | { |
| 109 | AccessWindowHorizontal input_access(input, -border_size.left, vec_size_x); |
| 110 | window_changed = window_changed || update_window_and_padding(win, input_access); |
| 111 | } |
| 112 | |
| 113 | AccessWindowHorizontal output_access(output, 0, vec_size_x); |
| 114 | window_changed = window_changed || update_window_and_padding(win, output_access); |
Georgios Pinitas | 7f32d01 | 2018-10-11 18:41:19 +0100 | [diff] [blame] | 115 | } |
| 116 | else |
| 117 | { |
Manuel Bottini | 21c2895 | 2021-04-08 12:50:12 +0100 | [diff] [blame] | 118 | unsigned int vec_size_x = adjust_vec_size(max_cl_vector_width / input->element_size(), input->dimension(0)); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 119 | if (norm_info.is_cross_map()) |
Manuel Bottini | 21c2895 | 2021-04-08 12:50:12 +0100 | [diff] [blame] | 120 | { |
| 121 | vec_size_x = 1; |
| 122 | } |
| 123 | win = calculate_max_window(*input, Steps(vec_size_x)); |
Georgios Pinitas | 7f32d01 | 2018-10-11 18:41:19 +0100 | [diff] [blame] | 124 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 125 | Status err = |
| 126 | (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{}; |
Giorgio Arena | c23b633 | 2017-11-28 15:23:51 +0000 | [diff] [blame] | 127 | return std::make_pair(err, win); |
| 128 | } |
| 129 | } // namespace |
| 130 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 131 | CLNormalizationLayerKernel::CLNormalizationLayerKernel() |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 132 | : _input(nullptr), _output(nullptr), _border_size(0), _is_norm_across_width(false) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 133 | { |
Giorgio Arena | 4a95bba | 2021-06-28 11:00:27 +0100 | [diff] [blame] | 134 | _type = CLKernelType::ELEMENTWISE; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | BorderSize CLNormalizationLayerKernel::border_size() const |
| 138 | { |
| 139 | return _border_size; |
| 140 | } |
| 141 | |
Gian Marco Iodice | d60a6b9 | 2017-08-10 10:43:40 +0100 | [diff] [blame] | 142 | void CLNormalizationLayerKernel::configure(const ICLTensor *input, ICLTensor *output, NormalizationLayerInfo norm_info) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 143 | { |
Manuel Bottini | 4c6bd51 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 144 | configure(CLKernelLibrary::get().get_compile_context(), input, output, norm_info); |
| 145 | } |
| 146 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 147 | void CLNormalizationLayerKernel::configure(const CLCompileContext &compile_context, |
| 148 | const ICLTensor *input, |
| 149 | ICLTensor *output, |
| 150 | NormalizationLayerInfo norm_info) |
Manuel Bottini | 4c6bd51 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 151 | { |
Georgios Pinitas | 30902ed | 2017-11-14 15:32:57 +0000 | [diff] [blame] | 152 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, output); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 153 | auto padding_info = get_padding_info({input, output}); |
Georgios Pinitas | 09004ca | 2017-07-03 17:30:14 +0100 | [diff] [blame] | 154 | |
Georgios Pinitas | 30902ed | 2017-11-14 15:32:57 +0000 | [diff] [blame] | 155 | // Perform validation step |
Giorgio Arena | f6a43c5 | 2017-12-01 12:16:25 +0000 | [diff] [blame] | 156 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info(), norm_info)); |
Manuel Bottini | 21c2895 | 2021-04-08 12:50:12 +0100 | [diff] [blame] | 157 | auto win_config = validate_and_configure_window(input->info(), output->info(), norm_info); |
| 158 | ARM_COMPUTE_ERROR_THROW_ON(win_config.first); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 159 | |
Gian Marco Iodice | d60a6b9 | 2017-08-10 10:43:40 +0100 | [diff] [blame] | 160 | _input = input; |
| 161 | _output = output; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 162 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 163 | const DataLayout data_layout = input->info()->data_layout(); |
| 164 | unsigned int vec_size_x = |
| 165 | adjust_vec_size(max_cl_vector_width / input->info()->element_size(), input->info()->dimension(0)); |
| 166 | int vec_size_x_leftovers = input->info()->dimension(0) % vec_size_x; |
| 167 | if (norm_info.is_cross_map() && data_layout == DataLayout::NHWC) |
Manuel Bottini | 21c2895 | 2021-04-08 12:50:12 +0100 | [diff] [blame] | 168 | { |
| 169 | vec_size_x = 1; |
| 170 | vec_size_x_leftovers = 0; |
| 171 | } |
| 172 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 173 | if (data_layout == DataLayout::NCHW) |
Manuel Bottini | 21c2895 | 2021-04-08 12:50:12 +0100 | [diff] [blame] | 174 | { |
SiCongLi | aed61f2 | 2021-08-26 17:44:08 +0100 | [diff] [blame] | 175 | const unsigned int norm_idx = get_normalization_dimension_index(data_layout, norm_info); |
| 176 | _is_norm_across_width = norm_idx == 0; |
| 177 | const unsigned int norm_radius = norm_info.norm_size() / 2; |
| 178 | // Border / padding calculation: |
| 179 | // For NCHW no border handling is impelmeneted in the kernel in the x axis. |
| 180 | // This means the x axis is fully-padded depending on vec_size_x and norm_size |
| 181 | // E.G. for input x dimension = 3, norm_size = 3 (radius = 1), vec_size_x = 2 ('#' is element 'p' is padding): |
| 182 | // In : |p|#|#|#|p|p| |
| 183 | // Out: |#|#|#|p| |
| 184 | // The output has 1 right padding because of the vec_size_x. |
| 185 | // The input has 1 left padding because radius = 1. |
| 186 | // The input has 2 right padding because of radius = 1 AND the extra output padding |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 187 | const unsigned int border_width_left = _is_norm_across_width ? norm_radius : 0; |
| 188 | const unsigned int border_width_right = |
| 189 | _is_norm_across_width ? norm_radius + (vec_size_x - input->info()->dimension(0) % vec_size_x) : 0; |
| 190 | _border_size = BorderSize(0, border_width_right, 0, border_width_left); |
Manuel Bottini | 21c2895 | 2021-04-08 12:50:12 +0100 | [diff] [blame] | 191 | } |
Georgios Pinitas | 7f32d01 | 2018-10-11 18:41:19 +0100 | [diff] [blame] | 192 | |
Michele Di Giorgio | 9d3a831 | 2018-11-20 12:31:24 +0000 | [diff] [blame] | 193 | const bool is_in_map_2D = (norm_info.type() == NormType::IN_MAP_2D); |
| 194 | |
Michele Di Giorgio | 6c92834 | 2017-06-22 16:55:57 +0100 | [diff] [blame] | 195 | // Set build options |
Georgios Pinitas | 0162436 | 2017-11-30 10:53:31 +0000 | [diff] [blame] | 196 | CLBuildOptions build_opts; |
| 197 | build_opts.add_option(("-DDATA_TYPE=" + get_cl_type_from_data_type(input->info()->data_type()))); |
Georgios Pinitas | 0162436 | 2017-11-30 10:53:31 +0000 | [diff] [blame] | 198 | build_opts.add_option(("-DCOEFF=" + float_to_string_with_full_precision(norm_info.scale_coeff()))); |
| 199 | build_opts.add_option(("-DBETA=" + float_to_string_with_full_precision(norm_info.beta()))); |
| 200 | build_opts.add_option(("-DKAPPA=" + float_to_string_with_full_precision(norm_info.kappa()))); |
Manuel Bottini | 21c2895 | 2021-04-08 12:50:12 +0100 | [diff] [blame] | 201 | build_opts.add_option(("-DVEC_SIZE=" + support::cpp11::to_string(vec_size_x))); |
| 202 | build_opts.add_option(("-DVEC_SIZE_LEFTOVER=" + support::cpp11::to_string(vec_size_x_leftovers))); |
Georgios Pinitas | 0162436 | 2017-11-30 10:53:31 +0000 | [diff] [blame] | 203 | build_opts.add_option(("-DRADIUS=" + support::cpp11::to_string(norm_info.norm_size() / 2))); |
| 204 | build_opts.add_option(("-DNUM_SLICES=" + support::cpp11::to_string(input->info()->dimension(2)))); |
| 205 | build_opts.add_option_if(is_in_map_2D, "-DIN_MAP_2D"); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 206 | build_opts.add_option_if(norm_info.is_in_map() || (data_layout == DataLayout::NHWC && norm_info.is_cross_map()), |
| 207 | "-DWIDTH_SIZE=" + support::cpp11::to_string(input->info()->dimension(0))); |
| 208 | build_opts.add_option_if(norm_info.is_in_map() && data_layout == DataLayout::NHWC, |
| 209 | "-DDIM1_SIZE=" + support::cpp11::to_string(input->info()->dimension(1))); |
Michele Di Giorgio | 6c92834 | 2017-06-22 16:55:57 +0100 | [diff] [blame] | 210 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 211 | // Create kernel |
Michele Di Giorgio | 9d3a831 | 2018-11-20 12:31:24 +0000 | [diff] [blame] | 212 | std::string kernel_name; |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 213 | if (norm_info.is_in_map()) |
Michele Di Giorgio | 9d3a831 | 2018-11-20 12:31:24 +0000 | [diff] [blame] | 214 | { |
| 215 | kernel_name = "normalization_layer_in_map_" + lower_string(string_from_data_layout(data_layout)); |
| 216 | } |
| 217 | else |
| 218 | { |
Manuel Bottini | 21c2895 | 2021-04-08 12:50:12 +0100 | [diff] [blame] | 219 | kernel_name = "normalization_layer_cross_map_" + lower_string(string_from_data_layout(data_layout)); |
Michele Di Giorgio | 9d3a831 | 2018-11-20 12:31:24 +0000 | [diff] [blame] | 220 | } |
Manuel Bottini | 4c6bd51 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 221 | _kernel = create_kernel(compile_context, kernel_name, build_opts.options()); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 222 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 223 | // Configure kernel window |
Anthony Barbier | b6eb353 | 2018-08-08 13:20:04 +0100 | [diff] [blame] | 224 | ICLKernel::configure_internal(win_config.second); |
Giorgio Arena | 63485ce | 2017-11-15 16:04:20 +0000 | [diff] [blame] | 225 | |
| 226 | // Set config_id for enabling LWS tuning |
| 227 | _config_id = "normalization_layer_"; |
| 228 | _config_id += lower_string(string_from_data_type(input->info()->data_type())); |
| 229 | _config_id += "_"; |
| 230 | _config_id += support::cpp11::to_string(static_cast<std::underlying_type<NormType>::type>(norm_info.type())); |
| 231 | _config_id += "_"; |
| 232 | _config_id += support::cpp11::to_string(norm_info.norm_size()); |
| 233 | _config_id += "_"; |
| 234 | _config_id += support::cpp11::to_string(input->info()->dimension(0)); |
| 235 | _config_id += "_"; |
| 236 | _config_id += support::cpp11::to_string(input->info()->dimension(1)); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 237 | if (data_layout == DataLayout::NHWC) |
Manuel Bottini | 21c2895 | 2021-04-08 12:50:12 +0100 | [diff] [blame] | 238 | { |
| 239 | ARM_COMPUTE_ERROR_ON(has_padding_changed(padding_info)); |
| 240 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 241 | } |
| 242 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 243 | Status CLNormalizationLayerKernel::validate(const ITensorInfo *input, |
| 244 | const ITensorInfo *output, |
| 245 | NormalizationLayerInfo norm_info) |
Georgios Pinitas | 30902ed | 2017-11-14 15:32:57 +0000 | [diff] [blame] | 246 | { |
Giorgio Arena | c23b633 | 2017-11-28 15:23:51 +0000 | [diff] [blame] | 247 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output, norm_info)); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 248 | ARM_COMPUTE_RETURN_ON_ERROR( |
| 249 | validate_and_configure_window(input->clone().get(), output->clone().get(), norm_info).first); |
Georgios Pinitas | 30902ed | 2017-11-14 15:32:57 +0000 | [diff] [blame] | 250 | |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 251 | return Status{}; |
Georgios Pinitas | 30902ed | 2017-11-14 15:32:57 +0000 | [diff] [blame] | 252 | } |
| 253 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 254 | void CLNormalizationLayerKernel::run(const Window &window, cl::CommandQueue &queue) |
| 255 | { |
| 256 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 257 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(IKernel::window(), window); |
| 258 | |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 259 | const int collapsed_dimension = _is_norm_across_width ? Window::DimZ : 4; |
steniu01 | f70256b | 2017-07-13 14:03:35 +0100 | [diff] [blame] | 260 | Window window_collapsed = window.collapse_if_possible(ICLKernel::window(), collapsed_dimension); |
| 261 | Window slice = window_collapsed.first_slice_window_3D(); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 262 | |
| 263 | do |
| 264 | { |
| 265 | unsigned int idx = 0; |
| 266 | add_3D_tensor_argument(idx, _input, slice); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 267 | add_3D_tensor_argument(idx, _output, slice); |
Anthony Barbier | 5a65cfd | 2018-08-10 14:10:08 +0100 | [diff] [blame] | 268 | enqueue(queue, *this, slice, lws_hint()); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 269 | } while (window_collapsed.slide_window_slice_3D(slice)); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 270 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 271 | } // namespace arm_compute |