From 7f32d01cedfd0f2e89bea1a40e5f82ed3ad43d4e Mon Sep 17 00:00:00 2001 From: Georgios Pinitas Date: Thu, 11 Oct 2018 18:41:19 +0100 Subject: COMPMID-1451: Fix NormalizationLayer accross width normalization. NEON and CL normalization layer was generating invalida results for radius > 4. Change-Id: I15d846405e6b3492fe44920bbf8cadceb4e5258f Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/153161 Tested-by: bsgcomp Reviewed-by: Matteo Martincigh Reviewed-by: Pablo Tello --- src/core/CL/kernels/CLNormalizationLayerKernel.cpp | 43 ++++++++++++++-------- 1 file changed, 27 insertions(+), 16 deletions(-) (limited to 'src/core/CL/kernels/CLNormalizationLayerKernel.cpp') diff --git a/src/core/CL/kernels/CLNormalizationLayerKernel.cpp b/src/core/CL/kernels/CLNormalizationLayerKernel.cpp index eb1ad68cd3..67357da7d1 100644 --- a/src/core/CL/kernels/CLNormalizationLayerKernel.cpp +++ b/src/core/CL/kernels/CLNormalizationLayerKernel.cpp @@ -23,6 +23,7 @@ */ #include "arm_compute/core/CL/kernels/CLNormalizationLayerKernel.h" +#include "arm_compute/core/AccessWindowStatic.h" #include "arm_compute/core/CL/CLHelpers.h" #include "arm_compute/core/CL/CLKernelLibrary.h" #include "arm_compute/core/CL/CLValidate.h" @@ -61,24 +62,32 @@ std::pair validate_and_configure_window(ITensorInfo *input, ITen // Output tensor auto initialization if not yet initialized auto_init_if_empty(*output, *input->clone()); + const unsigned int num_elems_processed_per_iteration = 4; + const unsigned int norm_idx = get_normalization_dimension_index(input->data_layout(), norm_info); - const unsigned int norm_size = norm_info.norm_size(); - bool is_norm_accross_width = norm_idx == 0; + const bool is_norm_accross_width = norm_idx == 0; - const unsigned int border_width = is_norm_accross_width ? std::min(norm_size / 2, 3U) : 0; + const unsigned int border_width = is_norm_accross_width ? num_elems_processed_per_iteration - 1 : 0; const BorderSize border_size = BorderSize(0, border_width); - const unsigned int num_elems_processed_per_iteration = 4; - const unsigned int num_elems_read_per_iteration = is_norm_accross_width ? (num_elems_processed_per_iteration + 2 * (norm_size / 2)) : num_elems_processed_per_iteration; - - Window win = calculate_max_window(*input, Steps(num_elems_processed_per_iteration)); + Window win = calculate_max_window(*input, Steps(num_elems_processed_per_iteration)); + bool window_changed = false; // We do not use a Rectangle window for IN_MAP_2D as we clamp the top and bottom accesses inside the kernel, avoiding padding - AccessWindowHorizontal input_access(input, -border_size.left, num_elems_read_per_iteration); - AccessWindowHorizontal output_access(output, 0, num_elems_processed_per_iteration); - - bool window_changed = update_window_and_padding(win, input_access, output_access); + // Reads can occur within the valid region of the input + if(is_norm_accross_width) + { + AccessWindowStatic input_access(input, -border_size.left, 0, input->dimension(0) + border_size.right, 0); + window_changed = window_changed || update_window_and_padding(win, input_access); + } + else + { + AccessWindowHorizontal input_access(input, -border_size.left, num_elems_processed_per_iteration); + window_changed = window_changed || update_window_and_padding(win, input_access); + } + AccessWindowHorizontal output_access(output, 0, num_elems_processed_per_iteration); + window_changed = window_changed || update_window_and_padding(win, output_access); output_access.set_valid_region(win, input->valid_region()); Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{}; @@ -109,14 +118,15 @@ void CLNormalizationLayerKernel::configure(const ICLTensor *input, ICLTensor *ou _input = input; _output = output; - const unsigned int norm_idx = get_normalization_dimension_index(input->info()->data_layout(), norm_info); - _is_norm_across_width = norm_idx == 0; - const unsigned int border_width = _is_norm_across_width ? std::min(norm_info.norm_size() / 2, 3U) : 0; - _border_size = BorderSize(0, border_width); - const unsigned int num_elems_processed_per_iteration = 4; const bool is_in_map_2D = (norm_info.type() == NormType::IN_MAP_2D); + const DataLayout data_layout = input->info()->data_layout(); + const unsigned int norm_idx = get_normalization_dimension_index(data_layout, norm_info); + _is_norm_across_width = norm_idx == 0; + const unsigned int border_width = _is_norm_across_width ? num_elems_processed_per_iteration - 1 : 0; + _border_size = BorderSize(0, border_width); + // Set build options CLBuildOptions build_opts; build_opts.add_option(("-DDATA_TYPE=" + get_cl_type_from_data_type(input->info()->data_type()))); @@ -127,6 +137,7 @@ void CLNormalizationLayerKernel::configure(const ICLTensor *input, ICLTensor *ou build_opts.add_option(("-DRADIUS=" + support::cpp11::to_string(norm_info.norm_size() / 2))); build_opts.add_option(("-DNUM_SLICES=" + support::cpp11::to_string(input->info()->dimension(2)))); build_opts.add_option_if(is_in_map_2D, "-DIN_MAP_2D"); + build_opts.add_option_if(norm_info.is_in_map() || (data_layout == DataLayout::NHWC && norm_info.is_cross_map()), "-DWIDTH_SIZE=" + support::cpp11::to_string(input->info()->dimension(0))); // Create kernel std::string kernel_name = _is_norm_across_width ? "normalization_layer_in_map" : "normalization_layer_cross_map"; -- cgit v1.2.1