blob: 84ea0ca058ab21cea2e9ee56dc217b67166d7e96 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
2 * Copyright (c) 2016, 2017 ARM Limited.
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/runtime/NEON/functions/NEGaussianPyramid.h"
25
26#include "arm_compute/core/Error.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010027#include "arm_compute/core/ITensor.h"
28#include "arm_compute/core/NEON/kernels/NEGaussianPyramidKernel.h"
29#include "arm_compute/core/NEON/kernels/NEScaleKernel.h"
30#include "arm_compute/core/PixelValue.h"
31#include "arm_compute/core/TensorInfo.h"
32#include "arm_compute/core/Validate.h"
33#include "arm_compute/runtime/NEON/NEScheduler.h"
34#include "arm_compute/runtime/NEON/functions/NEGaussian5x5.h"
35#include "arm_compute/runtime/Pyramid.h"
36#include "arm_compute/runtime/Tensor.h"
37#include "arm_compute/runtime/TensorAllocator.h"
Moritz Pflanzerd0ae8b82017-06-29 14:51:57 +010038#include "support/ToolchainSupport.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010039
40#include <cstddef>
41
42using namespace arm_compute;
43
44NEGaussianPyramid::NEGaussianPyramid()
45 : _input(nullptr), _pyramid(nullptr), _tmp()
46{
47}
48
Moritz Pflanzerf4af76e2017-09-06 07:42:43 +010049NEGaussianPyramidHalf::NEGaussianPyramidHalf() // NOLINT
50 : _border_handler(),
51 _horizontal_reduction(),
52 _vertical_reduction()
Anthony Barbier6ff3b192017-09-04 18:44:23 +010053{
54}
55
56void NEGaussianPyramidHalf::configure(const ITensor *input, IPyramid *pyramid, BorderMode border_mode, uint8_t constant_border_value)
57{
58 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::U8);
59 ARM_COMPUTE_ERROR_ON(nullptr == pyramid);
60 ARM_COMPUTE_ERROR_ON(input->info()->num_dimensions() != pyramid->get_pyramid_level(0)->info()->num_dimensions());
61 ARM_COMPUTE_ERROR_ON(input->info()->dimension(0) != pyramid->info()->width());
62 ARM_COMPUTE_ERROR_ON(input->info()->dimension(1) != pyramid->info()->height());
63 ARM_COMPUTE_ERROR_ON(SCALE_PYRAMID_HALF != pyramid->info()->scale());
64
65 /* Get number of pyramid levels */
66 const size_t num_levels = pyramid->info()->num_levels();
67
68 _input = input;
69 _pyramid = pyramid;
70
71 if(num_levels > 1)
72 {
Moritz Pflanzerd0ae8b82017-06-29 14:51:57 +010073 _border_handler = arm_compute::support::cpp14::make_unique<NEFillBorderKernel[]>(num_levels - 1);
74 _horizontal_reduction = arm_compute::support::cpp14::make_unique<NEGaussianPyramidHorKernel[]>(num_levels - 1);
75 _vertical_reduction = arm_compute::support::cpp14::make_unique<NEGaussianPyramidVertKernel[]>(num_levels - 1);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010076
77 // Apply half scale to the X dimension of the tensor shape
78 TensorShape tensor_shape = pyramid->info()->tensor_shape();
79 tensor_shape.set(0, (pyramid->info()->width() + 1) * SCALE_PYRAMID_HALF);
80
81 PyramidInfo pyramid_info(num_levels - 1, SCALE_PYRAMID_HALF, tensor_shape, Format::S16);
82 _tmp.init(pyramid_info);
83
84 for(unsigned int i = 0; i < num_levels - 1; ++i)
85 {
86 /* Configure horizontal kernel */
87 _horizontal_reduction[i].configure(_pyramid->get_pyramid_level(i), _tmp.get_pyramid_level(i), border_mode == BorderMode::UNDEFINED);
88
89 /* Configure vertical kernel */
90 _vertical_reduction[i].configure(_tmp.get_pyramid_level(i), _pyramid->get_pyramid_level(i + 1), border_mode == BorderMode::UNDEFINED);
91
92 /* Configure border */
93 _border_handler[i].configure(_pyramid->get_pyramid_level(i), _horizontal_reduction[i].border_size(), border_mode, PixelValue(constant_border_value));
94 }
95
96 _tmp.allocate();
97 }
98}
99
100void NEGaussianPyramidHalf::run()
101{
102 ARM_COMPUTE_ERROR_ON_MSG(_pyramid == nullptr, "Unconfigured function");
103
104 /* Get number of pyramid levels */
105 const size_t num_levels = _pyramid->info()->num_levels();
106
107 /* The first level of the pyramid has the input image */
108 _pyramid->get_pyramid_level(0)->copy_from(*_input);
109
110 for(unsigned int i = 0; i < num_levels - 1; ++i)
111 {
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100112 NEScheduler::get().schedule(_border_handler.get() + i, Window::DimZ);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100113 NEScheduler::get().schedule(_horizontal_reduction.get() + i, Window::DimY);
114 NEScheduler::get().schedule(_vertical_reduction.get() + i, Window::DimY);
115 }
116}
117
Moritz Pflanzerf4af76e2017-09-06 07:42:43 +0100118NEGaussianPyramidOrb::NEGaussianPyramidOrb() // NOLINT
Georgios Pinitas3021edf2017-09-18 17:55:22 +0100119 : _gaus5x5(),
Moritz Pflanzerf4af76e2017-09-06 07:42:43 +0100120 _scale_nearest()
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100121{
122}
123
124void NEGaussianPyramidOrb::configure(const ITensor *input, IPyramid *pyramid, BorderMode border_mode, uint8_t constant_border_value)
125{
126 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::U8);
127 ARM_COMPUTE_ERROR_ON(nullptr == pyramid);
128 ARM_COMPUTE_ERROR_ON(input->info()->num_dimensions() != pyramid->get_pyramid_level(0)->info()->num_dimensions());
129 ARM_COMPUTE_ERROR_ON(input->info()->dimension(0) != pyramid->info()->width());
130 ARM_COMPUTE_ERROR_ON(input->info()->dimension(1) != pyramid->info()->height());
131 ARM_COMPUTE_ERROR_ON(SCALE_PYRAMID_ORB != pyramid->info()->scale());
132
133 /* Get number of pyramid levels */
134 const size_t num_levels = pyramid->info()->num_levels();
135
136 _input = input;
137 _pyramid = pyramid;
138
139 if(num_levels > 1)
140 {
Moritz Pflanzerd0ae8b82017-06-29 14:51:57 +0100141 _gaus5x5 = arm_compute::support::cpp14::make_unique<NEGaussian5x5[]>(num_levels - 1);
Georgios Pinitas3021edf2017-09-18 17:55:22 +0100142 _scale_nearest = arm_compute::support::cpp14::make_unique<NEScale[]>(num_levels - 1);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100143
144 PyramidInfo pyramid_info(num_levels - 1, SCALE_PYRAMID_ORB, pyramid->info()->tensor_shape(), Format::U8);
145 _tmp.init(pyramid_info);
146
147 for(unsigned int i = 0; i < num_levels - 1; ++i)
148 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100149 /* Configure gaussian 5x5 */
150 _gaus5x5[i].configure(_pyramid->get_pyramid_level(i), _tmp.get_pyramid_level(i), border_mode, constant_border_value);
151
Georgios Pinitas3021edf2017-09-18 17:55:22 +0100152 /* Configure scale */
153 _scale_nearest[i].configure(_tmp.get_pyramid_level(i), _pyramid->get_pyramid_level(i + 1), InterpolationPolicy::NEAREST_NEIGHBOR, BorderMode::UNDEFINED);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100154 }
155
156 _tmp.allocate();
157 }
158}
159
160void NEGaussianPyramidOrb::run()
161{
162 ARM_COMPUTE_ERROR_ON_MSG(_pyramid == nullptr, "Unconfigured function");
163
164 /* Get number of pyramid levels */
165 const size_t num_levels = _pyramid->info()->num_levels();
166
167 /* The first level of the pyramid has the input image */
168 _pyramid->get_pyramid_level(0)->copy_from(*_input);
169
170 for(unsigned int i = 0; i < num_levels - 1; ++i)
171 {
172 _gaus5x5[i].run();
Georgios Pinitas3021edf2017-09-18 17:55:22 +0100173 _scale_nearest[i].run();
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100174 }
175}