From 37908d9e675a240f65e038796f44691c4c530229 Mon Sep 17 00:00:00 2001 From: Gian Marco Date: Tue, 7 Nov 2017 14:38:22 +0000 Subject: COMPMID-560 - Validation mismatches Gaussian Pyramid Half Scale Change-Id: If09afa444c6b3e91117d1b1a529faa0778457cd3 Reviewed-on: http://mpd-gerrit.cambridge.arm.com/96099 Tested-by: Kaizen Reviewed-by: Anthony Barbier --- src/core/NEON/kernels/NEGaussianPyramidKernel.cpp | 37 ++++++++--------------- src/runtime/NEON/functions/NEGaussianPyramid.cpp | 25 ++++++++++----- 2 files changed, 30 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/src/core/NEON/kernels/NEGaussianPyramidKernel.cpp b/src/core/NEON/kernels/NEGaussianPyramidKernel.cpp index d6cb1b6444..7a123e2f57 100644 --- a/src/core/NEON/kernels/NEGaussianPyramidKernel.cpp +++ b/src/core/NEON/kernels/NEGaussianPyramidKernel.cpp @@ -41,20 +41,19 @@ using namespace arm_compute; NEGaussianPyramidHorKernel::NEGaussianPyramidHorKernel() - : _border_size(0), _l2_load_offset(0) + : _l2_load_offset(0) { } BorderSize NEGaussianPyramidHorKernel::border_size() const { - return _border_size; + return BorderSize(0, 2); } -void NEGaussianPyramidHorKernel::configure(const ITensor *input, ITensor *output, bool border_undefined) +void NEGaussianPyramidHorKernel::configure(const ITensor *input, ITensor *output) { ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::U8); ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(output, 1, DataType::S16); - ARM_COMPUTE_ERROR_ON(input->info()->dimension(0) != 2 * output->info()->dimension(0)); ARM_COMPUTE_ERROR_ON(input->info()->dimension(1) != output->info()->dimension(1)); for(size_t i = 2; i < Coordinates::num_max_dimensions; ++i) @@ -62,17 +61,16 @@ void NEGaussianPyramidHorKernel::configure(const ITensor *input, ITensor *output ARM_COMPUTE_ERROR_ON(input->info()->dimension(i) != output->info()->dimension(i)); } - _input = input; - _output = output; - _border_size = BorderSize(border_undefined ? 0 : 2, 2); + _input = input; + _output = output; // Configure kernel window constexpr unsigned int num_elems_processed_per_iteration = 16; constexpr unsigned int num_elems_read_per_iteration = 32; constexpr unsigned int num_elems_written_per_iteration = 8; - constexpr float scale_x = 0.5f; + const float scale_x = static_cast(output->info()->dimension(0)) / input->info()->dimension(0); - Window win = calculate_max_window_horizontal(*input->info(), Steps(num_elems_processed_per_iteration), border_undefined, border_size()); + Window win = calculate_max_window_horizontal(*input->info(), Steps(num_elems_processed_per_iteration)); AccessWindowHorizontal output_access(output->info(), 0, num_elems_written_per_iteration, scale_x); // Sub sampling selects odd pixels (1, 3, 5, ...) for images with even @@ -97,15 +95,12 @@ void NEGaussianPyramidHorKernel::configure(const ITensor *input, ITensor *output _l2_load_offset += 1; } + // Replace input access with static window update_window_and_padding(win, AccessWindowHorizontal(input->info(), _l2_load_offset, num_elems_read_per_iteration), output_access); - ValidRegion valid_region = input->info()->valid_region(); - valid_region.anchor.set(0, std::ceil((valid_region.anchor[0] + (border_undefined ? border_size().left : 0)) / 2.f)); - valid_region.shape.set(0, (valid_region.shape[0] - (border_undefined ? border_size().right : 0)) / 2 - valid_region.anchor[0]); - - output_access.set_valid_region(win, valid_region); + output->info()->set_valid_region(ValidRegion(Coordinates(), output->info()->tensor_shape())); INEKernel::configure(win); } @@ -163,13 +158,11 @@ BorderSize NEGaussianPyramidVertKernel::border_size() const return BorderSize(2, 0); } -void NEGaussianPyramidVertKernel::configure(const ITensor *input, ITensor *output, bool border_undefined) +void NEGaussianPyramidVertKernel::configure(const ITensor *input, ITensor *output) { ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::S16); ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(output, 1, DataType::U8); - ARM_COMPUTE_ERROR_ON(input->info()->dimension(0) != output->info()->dimension(0)); - ARM_COMPUTE_ERROR_ON(input->info()->dimension(1) != 2 * output->info()->dimension(1)); for(size_t i = 2; i < Coordinates::num_max_dimensions; ++i) { @@ -189,9 +182,9 @@ void NEGaussianPyramidVertKernel::configure(const ITensor *input, ITensor *outpu constexpr unsigned int num_elems_read_per_iteration = 16; constexpr unsigned int num_rows_read_per_iteration = 5; - constexpr float scale_y = 0.5f; + const float scale_y = static_cast(output->info()->dimension(1)) / input->info()->dimension(1); - Window win = calculate_max_window(*input->info(), Steps(num_elems_processed_per_iteration, num_rows_processed_per_iteration), border_undefined, border_size()); + Window win = calculate_max_window(*input->info(), Steps(num_elems_processed_per_iteration, num_rows_processed_per_iteration)); AccessWindowRectangle output_access(output->info(), 0, 0, num_elems_written_per_iteration, num_rows_written_per_iteration, 1.f, scale_y); // Determine whether we need to load even or odd rows. See above for a @@ -207,11 +200,7 @@ void NEGaussianPyramidVertKernel::configure(const ITensor *input, ITensor *outpu AccessWindowRectangle(input->info(), 0, _t2_load_offset, num_elems_read_per_iteration, num_rows_read_per_iteration), output_access); - ValidRegion valid_region = input->info()->valid_region(); - valid_region.anchor.set(1, std::ceil((valid_region.anchor[1] + (border_undefined ? border_size().top : 0)) / 2.f)); - valid_region.shape.set(1, (valid_region.shape[1] - (border_undefined ? border_size().bottom : 0)) / 2 - valid_region.anchor[1]); - - output_access.set_valid_region(win, valid_region); + output->info()->set_valid_region(ValidRegion(Coordinates(), output->info()->tensor_shape())); INEKernel::configure(win); } diff --git a/src/runtime/NEON/functions/NEGaussianPyramid.cpp b/src/runtime/NEON/functions/NEGaussianPyramid.cpp index 84ea0ca058..8a85bba68b 100644 --- a/src/runtime/NEON/functions/NEGaussianPyramid.cpp +++ b/src/runtime/NEON/functions/NEGaussianPyramid.cpp @@ -47,7 +47,8 @@ NEGaussianPyramid::NEGaussianPyramid() } NEGaussianPyramidHalf::NEGaussianPyramidHalf() // NOLINT - : _border_handler(), + : _horizontal_border_handler(), + _vertical_border_handler(), _horizontal_reduction(), _vertical_reduction() { @@ -62,6 +63,9 @@ void NEGaussianPyramidHalf::configure(const ITensor *input, IPyramid *pyramid, B ARM_COMPUTE_ERROR_ON(input->info()->dimension(1) != pyramid->info()->height()); ARM_COMPUTE_ERROR_ON(SCALE_PYRAMID_HALF != pyramid->info()->scale()); + // Constant value to use for vertical fill border when the border mode is CONSTANT + const uint16_t pixel_value_u16 = static_cast(constant_border_value) * 2 + static_cast(constant_border_value) * 8 + static_cast(constant_border_value) * 6; + /* Get number of pyramid levels */ const size_t num_levels = pyramid->info()->num_levels(); @@ -70,9 +74,10 @@ void NEGaussianPyramidHalf::configure(const ITensor *input, IPyramid *pyramid, B if(num_levels > 1) { - _border_handler = arm_compute::support::cpp14::make_unique(num_levels - 1); - _horizontal_reduction = arm_compute::support::cpp14::make_unique(num_levels - 1); - _vertical_reduction = arm_compute::support::cpp14::make_unique(num_levels - 1); + _horizontal_border_handler = arm_compute::support::cpp14::make_unique(num_levels - 1); + _vertical_border_handler = arm_compute::support::cpp14::make_unique(num_levels - 1); + _horizontal_reduction = arm_compute::support::cpp14::make_unique(num_levels - 1); + _vertical_reduction = arm_compute::support::cpp14::make_unique(num_levels - 1); // Apply half scale to the X dimension of the tensor shape TensorShape tensor_shape = pyramid->info()->tensor_shape(); @@ -84,13 +89,16 @@ void NEGaussianPyramidHalf::configure(const ITensor *input, IPyramid *pyramid, B for(unsigned int i = 0; i < num_levels - 1; ++i) { /* Configure horizontal kernel */ - _horizontal_reduction[i].configure(_pyramid->get_pyramid_level(i), _tmp.get_pyramid_level(i), border_mode == BorderMode::UNDEFINED); + _horizontal_reduction[i].configure(_pyramid->get_pyramid_level(i), _tmp.get_pyramid_level(i)); /* Configure vertical kernel */ - _vertical_reduction[i].configure(_tmp.get_pyramid_level(i), _pyramid->get_pyramid_level(i + 1), border_mode == BorderMode::UNDEFINED); + _vertical_reduction[i].configure(_tmp.get_pyramid_level(i), _pyramid->get_pyramid_level(i + 1)); + + /* Configure border */ + _horizontal_border_handler[i].configure(_pyramid->get_pyramid_level(i), _horizontal_reduction[i].border_size(), border_mode, PixelValue(constant_border_value)); /* Configure border */ - _border_handler[i].configure(_pyramid->get_pyramid_level(i), _horizontal_reduction[i].border_size(), border_mode, PixelValue(constant_border_value)); + _vertical_border_handler[i].configure(_tmp.get_pyramid_level(i), _vertical_reduction[i].border_size(), border_mode, PixelValue(pixel_value_u16)); } _tmp.allocate(); @@ -109,8 +117,9 @@ void NEGaussianPyramidHalf::run() for(unsigned int i = 0; i < num_levels - 1; ++i) { - NEScheduler::get().schedule(_border_handler.get() + i, Window::DimZ); + NEScheduler::get().schedule(_horizontal_border_handler.get() + i, Window::DimZ); NEScheduler::get().schedule(_horizontal_reduction.get() + i, Window::DimY); + NEScheduler::get().schedule(_vertical_border_handler.get() + i, Window::DimZ); NEScheduler::get().schedule(_vertical_reduction.get() + i, Window::DimY); } } -- cgit v1.2.1