blob: 402e6f1811f2f3cf41ac332b9263c70f1253948c [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +01002 * Copyright (c) 2016-2020 Arm Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01003 *
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 Spyrouebcebf12020-10-21 00:04:14 +010024#include "src/core/NEON/kernels/NEMinMaxLocationKernel.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010025
26#include "arm_compute/core/Coordinates.h"
27#include "arm_compute/core/Error.h"
28#include "arm_compute/core/Helpers.h"
29#include "arm_compute/core/IAccessWindow.h"
30#include "arm_compute/core/ITensor.h"
31#include "arm_compute/core/TensorInfo.h"
32#include "arm_compute/core/Types.h"
33#include "arm_compute/core/Validate.h"
steniu014c2938e2017-06-19 15:44:45 +010034#include "arm_compute/core/Window.h"
Georgios Pinitasd8734b52017-12-22 15:27:52 +000035#include "arm_compute/core/utils/misc/Utility.h"
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +010036#include "src/core/helpers/AutoConfiguration.h"
37#include "src/core/helpers/WindowHelpers.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010038
steniu014c2938e2017-06-19 15:44:45 +010039#include <algorithm>
Anthony Barbier6ff3b192017-09-04 18:44:23 +010040#include <arm_neon.h>
41#include <climits>
42#include <cstddef>
43
44namespace arm_compute
45{
46NEMinMaxKernel::NEMinMaxKernel()
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +010047 : _func(), _input(nullptr), _min(), _max(), _mtx()
Anthony Barbier6ff3b192017-09-04 18:44:23 +010048{
49}
50
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +010051void NEMinMaxKernel::configure(const IImage *input, void *min, void *max)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010052{
53 ARM_COMPUTE_ERROR_ON_TENSOR_NOT_2D(input);
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +010054 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::U8, DataType::S16, DataType::F32);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010055 ARM_COMPUTE_ERROR_ON(nullptr == min);
56 ARM_COMPUTE_ERROR_ON(nullptr == max);
57
58 _input = input;
59 _min = min;
60 _max = max;
61
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +010062 switch(_input->info()->data_type())
Anthony Barbier6ff3b192017-09-04 18:44:23 +010063 {
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +010064 case DataType::U8:
65 _func = &NEMinMaxKernel::minmax_U8;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010066 break;
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +010067 case DataType::S16:
68 _func = &NEMinMaxKernel::minmax_S16;
69 break;
70 case DataType::F32:
71 _func = &NEMinMaxKernel::minmax_F32;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010072 break;
73 default:
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +010074 ARM_COMPUTE_ERROR("Unsupported data type");
Anthony Barbier6ff3b192017-09-04 18:44:23 +010075 break;
76 }
77
Anthony Barbier6ff3b192017-09-04 18:44:23 +010078 // Configure kernel window
steniu014c2938e2017-06-19 15:44:45 +010079 constexpr unsigned int num_elems_processed_per_iteration = 1;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010080
steniu014c2938e2017-06-19 15:44:45 +010081 Window win = calculate_max_window(*input->info(), Steps(num_elems_processed_per_iteration));
Anthony Barbier6ff3b192017-09-04 18:44:23 +010082
83 INEKernel::configure(win);
84}
85
Moritz Pflanzerc186b572017-09-07 09:48:04 +010086void NEMinMaxKernel::run(const Window &window, const ThreadInfo &info)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010087{
Moritz Pflanzerc186b572017-09-07 09:48:04 +010088 ARM_COMPUTE_UNUSED(info);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010089 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
90 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window);
91 ARM_COMPUTE_ERROR_ON(_func == nullptr);
92
93 (this->*_func)(window);
94}
95
96void NEMinMaxKernel::reset()
97{
98 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +010099 switch(_input->info()->data_type())
100 {
101 case DataType::U8:
102 *static_cast<int32_t *>(_min) = UCHAR_MAX;
103 *static_cast<int32_t *>(_max) = 0;
104 break;
105 case DataType::S16:
106 *static_cast<int32_t *>(_min) = SHRT_MAX;
107 *static_cast<int32_t *>(_max) = SHRT_MIN;
108 break;
109 case DataType::F32:
110 *static_cast<float *>(_min) = std::numeric_limits<float>::max();
111 *static_cast<float *>(_max) = std::numeric_limits<float>::lowest();
112 break;
113 default:
114 ARM_COMPUTE_ERROR("Unsupported data type");
115 break;
116 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100117}
118
119template <typename T>
120void NEMinMaxKernel::update_min_max(const T min, const T max)
121{
Georgios Pinitase874ef92019-09-09 17:40:33 +0100122 arm_compute::lock_guard<arm_compute::Mutex> lock(_mtx);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100123
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +0100124 using type = typename std::conditional<std::is_same<T, float>::value, float, int32_t>::type;
125
126 auto min_ptr = static_cast<type *>(_min);
127 auto max_ptr = static_cast<type *>(_max);
128
129 if(min < *min_ptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100130 {
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +0100131 *min_ptr = min;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100132 }
133
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +0100134 if(max > *max_ptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100135 {
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +0100136 *max_ptr = max;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100137 }
138}
139
steniu014c2938e2017-06-19 15:44:45 +0100140void NEMinMaxKernel::minmax_U8(Window win)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100141{
142 uint8x8_t carry_min = vdup_n_u8(UCHAR_MAX);
143 uint8x8_t carry_max = vdup_n_u8(0);
144
steniu014c2938e2017-06-19 15:44:45 +0100145 uint8_t carry_max_scalar = 0;
146 uint8_t carry_min_scalar = UCHAR_MAX;
147
148 const int x_start = win.x().start();
149 const int x_end = win.x().end();
150
151 // Handle X dimension manually to split into two loops
152 // First one will use vector operations, second one processes the left over pixels
153 win.set(Window::DimX, Window::Dimension(0, 1, 1));
154
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100155 Iterator input(_input, win);
156
Michalis Spyroua4f378d2019-04-26 14:54:54 +0100157 execute_window_loop(win, [&](const Coordinates &)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100158 {
steniu014c2938e2017-06-19 15:44:45 +0100159 int x = x_start;
160
161 // Vector loop
162 for(; x <= x_end - 16; x += 16)
163 {
164 const uint8x16_t pixels = vld1q_u8(input.ptr() + x);
165 const uint8x8_t tmp_min = vmin_u8(vget_high_u8(pixels), vget_low_u8(pixels));
166 const uint8x8_t tmp_max = vmax_u8(vget_high_u8(pixels), vget_low_u8(pixels));
167 carry_min = vmin_u8(tmp_min, carry_min);
168 carry_max = vmax_u8(tmp_max, carry_max);
169 }
170
171 // Process leftover pixels
172 for(; x < x_end; ++x)
173 {
174 const uint8_t pixel = input.ptr()[x];
175 carry_min_scalar = std::min(pixel, carry_min_scalar);
176 carry_max_scalar = std::max(pixel, carry_max_scalar);
177 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100178 },
179 input);
180
181 // Reduce result
182 carry_min = vpmin_u8(carry_min, carry_min);
183 carry_max = vpmax_u8(carry_max, carry_max);
184 carry_min = vpmin_u8(carry_min, carry_min);
185 carry_max = vpmax_u8(carry_max, carry_max);
186 carry_min = vpmin_u8(carry_min, carry_min);
187 carry_max = vpmax_u8(carry_max, carry_max);
188
189 // Extract max/min values
steniu014c2938e2017-06-19 15:44:45 +0100190 const uint8_t min_i = std::min(vget_lane_u8(carry_min, 0), carry_min_scalar);
191 const uint8_t max_i = std::max(vget_lane_u8(carry_max, 0), carry_max_scalar);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100192
193 // Perform reduction of local min/max values
194 update_min_max(min_i, max_i);
195}
196
steniu014c2938e2017-06-19 15:44:45 +0100197void NEMinMaxKernel::minmax_S16(Window win)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100198{
199 int16x4_t carry_min = vdup_n_s16(SHRT_MAX);
200 int16x4_t carry_max = vdup_n_s16(SHRT_MIN);
201
steniu014c2938e2017-06-19 15:44:45 +0100202 int16_t carry_max_scalar = SHRT_MIN;
203 int16_t carry_min_scalar = SHRT_MAX;
204
205 const int x_start = win.x().start();
206 const int x_end = win.x().end();
207
208 // Handle X dimension manually to split into two loops
209 // First one will use vector operations, second one processes the left over pixels
210 win.set(Window::DimX, Window::Dimension(0, 1, 1));
211
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100212 Iterator input(_input, win);
213
Michalis Spyroua4f378d2019-04-26 14:54:54 +0100214 execute_window_loop(win, [&](const Coordinates &)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100215 {
steniu014c2938e2017-06-19 15:44:45 +0100216 int x = x_start;
Kohei Takahashicedb78f2018-08-23 10:23:52 +0900217 const auto in_ptr = reinterpret_cast<const int16_t *>(input.ptr());
steniu014c2938e2017-06-19 15:44:45 +0100218
219 // Vector loop
220 for(; x <= x_end - 16; x += 16)
221 {
222 const int16x8x2_t pixels = vld2q_s16(in_ptr + x);
223 const int16x8_t tmp_min1 = vminq_s16(pixels.val[0], pixels.val[1]);
224 const int16x8_t tmp_max1 = vmaxq_s16(pixels.val[0], pixels.val[1]);
225 const int16x4_t tmp_min2 = vmin_s16(vget_high_s16(tmp_min1), vget_low_s16(tmp_min1));
226 const int16x4_t tmp_max2 = vmax_s16(vget_high_s16(tmp_max1), vget_low_s16(tmp_max1));
227 carry_min = vmin_s16(tmp_min2, carry_min);
228 carry_max = vmax_s16(tmp_max2, carry_max);
229 }
230
231 // Process leftover pixels
232 for(; x < x_end; ++x)
233 {
234 const int16_t pixel = in_ptr[x];
235 carry_min_scalar = std::min(pixel, carry_min_scalar);
236 carry_max_scalar = std::max(pixel, carry_max_scalar);
237 }
238
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100239 },
240 input);
241
242 // Reduce result
243 carry_min = vpmin_s16(carry_min, carry_min);
244 carry_max = vpmax_s16(carry_max, carry_max);
245 carry_min = vpmin_s16(carry_min, carry_min);
246 carry_max = vpmax_s16(carry_max, carry_max);
247
248 // Extract max/min values
steniu014c2938e2017-06-19 15:44:45 +0100249 const int16_t min_i = std::min(vget_lane_s16(carry_min, 0), carry_min_scalar);
250 const int16_t max_i = std::max(vget_lane_s16(carry_max, 0), carry_max_scalar);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100251
252 // Perform reduction of local min/max values
253 update_min_max(min_i, max_i);
254}
255
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +0100256void NEMinMaxKernel::minmax_F32(Window win)
257{
258 float32x2_t carry_min = vdup_n_f32(std::numeric_limits<float>::max());
259 float32x2_t carry_max = vdup_n_f32(std::numeric_limits<float>::lowest());
260
261 float carry_min_scalar = std::numeric_limits<float>::max();
262 float carry_max_scalar = std::numeric_limits<float>::lowest();
263
264 const int x_start = win.x().start();
265 const int x_end = win.x().end();
266
267 // Handle X dimension manually to split into two loops
268 // First one will use vector operations, second one processes the left over pixels
269 win.set(Window::DimX, Window::Dimension(0, 1, 1));
270
271 Iterator input(_input, win);
272
Michalis Spyroua4f378d2019-04-26 14:54:54 +0100273 execute_window_loop(win, [&](const Coordinates &)
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +0100274 {
275 int x = x_start;
Kohei Takahashicedb78f2018-08-23 10:23:52 +0900276 const auto in_ptr = reinterpret_cast<const float *>(input.ptr());
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +0100277
278 // Vector loop
279 for(; x <= x_end - 8; x += 8)
280 {
281 const float32x4x2_t pixels = vld2q_f32(in_ptr + x);
282 const float32x4_t tmp_min1 = vminq_f32(pixels.val[0], pixels.val[1]);
283 const float32x4_t tmp_max1 = vmaxq_f32(pixels.val[0], pixels.val[1]);
284 const float32x2_t tmp_min2 = vmin_f32(vget_high_f32(tmp_min1), vget_low_f32(tmp_min1));
285 const float32x2_t tmp_max2 = vmax_f32(vget_high_f32(tmp_max1), vget_low_f32(tmp_max1));
286 carry_min = vmin_f32(tmp_min2, carry_min);
287 carry_max = vmax_f32(tmp_max2, carry_max);
288 }
289
290 // Process leftover pixels
291 for(; x < x_end; ++x)
292 {
293 const float pixel = in_ptr[x];
294 carry_min_scalar = std::min(pixel, carry_min_scalar);
295 carry_max_scalar = std::max(pixel, carry_max_scalar);
296 }
297
298 },
299 input);
300
301 // Reduce result
302 carry_min = vpmin_f32(carry_min, carry_min);
303 carry_max = vpmax_f32(carry_max, carry_max);
304 carry_min = vpmin_f32(carry_min, carry_min);
305 carry_max = vpmax_f32(carry_max, carry_max);
306
307 // Extract max/min values
308 const float min_i = std::min(vget_lane_f32(carry_min, 0), carry_min_scalar);
309 const float max_i = std::max(vget_lane_f32(carry_max, 0), carry_max_scalar);
310
311 // Perform reduction of local min/max values
312 update_min_max(min_i, max_i);
313}
314
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100315NEMinMaxLocationKernel::NEMinMaxLocationKernel()
steniu014c2938e2017-06-19 15:44:45 +0100316 : _func(nullptr), _input(nullptr), _min(nullptr), _max(nullptr), _min_count(nullptr), _max_count(nullptr), _min_loc(nullptr), _max_loc(nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100317{
318}
319
320bool NEMinMaxLocationKernel::is_parallelisable() const
321{
322 return false;
323}
324
Georgios Pinitas8795ffb2017-12-01 16:13:40 +0000325template <class T, std::size_t... N>
326struct NEMinMaxLocationKernel::create_func_table<T, utility::index_sequence<N...>>
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100327{
Michalis Spyroua4f378d2019-04-26 14:54:54 +0100328 static const std::array<NEMinMaxLocationKernel::MinMaxLocFunction, sizeof...(N)> func_table;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100329};
330
Georgios Pinitas8795ffb2017-12-01 16:13:40 +0000331template <class T, std::size_t... N>
Michalis Spyroua4f378d2019-04-26 14:54:54 +0100332const std::array<NEMinMaxLocationKernel::MinMaxLocFunction, sizeof...(N)> NEMinMaxLocationKernel::create_func_table<T, utility::index_sequence<N...>>::func_table
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100333{
334 &NEMinMaxLocationKernel::minmax_loc<T, bool(N & 8), bool(N & 4), bool(N & 2), bool(N & 1)>...
335};
336
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +0100337void NEMinMaxLocationKernel::configure(const IImage *input, void *min, void *max,
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100338 ICoordinates2DArray *min_loc, ICoordinates2DArray *max_loc,
339 uint32_t *min_count, uint32_t *max_count)
340{
341 ARM_COMPUTE_ERROR_ON_TENSOR_NOT_2D(input);
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +0100342 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::U8, DataType::S16, DataType::F32);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100343 ARM_COMPUTE_ERROR_ON(nullptr == min);
344 ARM_COMPUTE_ERROR_ON(nullptr == max);
345
346 _input = input;
347 _min = min;
348 _max = max;
349 _min_count = min_count;
350 _max_count = max_count;
351 _min_loc = min_loc;
352 _max_loc = max_loc;
353
354 unsigned int count_min = (nullptr != min_count ? 1 : 0);
355 unsigned int count_max = (nullptr != max_count ? 1 : 0);
356 unsigned int loc_min = (nullptr != min_loc ? 1 : 0);
357 unsigned int loc_max = (nullptr != max_loc ? 1 : 0);
358
359 unsigned int table_idx = (count_min << 3) | (count_max << 2) | (loc_min << 1) | loc_max;
360
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +0100361 switch(input->info()->data_type())
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100362 {
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +0100363 case DataType::U8:
Georgios Pinitas8795ffb2017-12-01 16:13:40 +0000364 _func = create_func_table<uint8_t, utility::index_sequence_t<16>>::func_table[table_idx];
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100365 break;
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +0100366 case DataType::S16:
Georgios Pinitas8795ffb2017-12-01 16:13:40 +0000367 _func = create_func_table<int16_t, utility::index_sequence_t<16>>::func_table[table_idx];
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100368 break;
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +0100369 case DataType::F32:
Georgios Pinitas8795ffb2017-12-01 16:13:40 +0000370 _func = create_func_table<float, utility::index_sequence_t<16>>::func_table[table_idx];
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +0100371 break;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100372 default:
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +0100373 ARM_COMPUTE_ERROR("Unsupported data type");
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100374 break;
375 }
376
steniu014c2938e2017-06-19 15:44:45 +0100377 constexpr unsigned int num_elems_processed_per_iteration = 1;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100378
379 // Configure kernel window
steniu014c2938e2017-06-19 15:44:45 +0100380 Window win = calculate_max_window(*input->info(), Steps(num_elems_processed_per_iteration));
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100381
steniu014c2938e2017-06-19 15:44:45 +0100382 update_window_and_padding(win, AccessWindowHorizontal(input->info(), 0, num_elems_processed_per_iteration));
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100383
384 INEKernel::configure(win);
385}
386
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100387void NEMinMaxLocationKernel::run(const Window &window, const ThreadInfo &info)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100388{
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100389 ARM_COMPUTE_UNUSED(info);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100390 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
391 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window);
392 ARM_COMPUTE_ERROR_ON(_func == nullptr);
393
394 (this->*_func)(window);
395}
396
397template <class T, bool count_min, bool count_max, bool loc_min, bool loc_max>
398void NEMinMaxLocationKernel::minmax_loc(const Window &win)
399{
400 if(count_min || count_max || loc_min || loc_max)
401 {
402 Iterator input(_input, win);
403
steniu014c2938e2017-06-19 15:44:45 +0100404 size_t min_count = 0;
405 size_t max_count = 0;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100406
407 // Clear min location array
408 if(loc_min)
409 {
410 _min_loc->clear();
411 }
412
413 // Clear max location array
414 if(loc_max)
415 {
416 _max_loc->clear();
417 }
418
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +0100419 using type = typename std::conditional<std::is_same<T, float>::value, float, int32_t>::type;
420
421 auto min_ptr = static_cast<type *>(_min);
422 auto max_ptr = static_cast<type *>(_max);
423
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100424 execute_window_loop(win, [&](const Coordinates & id)
425 {
426 auto in_ptr = reinterpret_cast<const T *>(input.ptr());
427 int32_t idx = id.x();
428 int32_t idy = id.y();
429
steniu014c2938e2017-06-19 15:44:45 +0100430 const T pixel = *in_ptr;
431 Coordinates2D p{ idx, idy };
432
433 if(count_min || loc_min)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100434 {
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +0100435 if(*min_ptr == pixel)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100436 {
steniu014c2938e2017-06-19 15:44:45 +0100437 if(count_min)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100438 {
steniu014c2938e2017-06-19 15:44:45 +0100439 ++min_count;
440 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100441
steniu014c2938e2017-06-19 15:44:45 +0100442 if(loc_min)
443 {
444 _min_loc->push_back(p);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100445 }
446 }
steniu014c2938e2017-06-19 15:44:45 +0100447 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100448
steniu014c2938e2017-06-19 15:44:45 +0100449 if(count_max || loc_max)
450 {
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +0100451 if(*max_ptr == pixel)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100452 {
steniu014c2938e2017-06-19 15:44:45 +0100453 if(count_max)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100454 {
steniu014c2938e2017-06-19 15:44:45 +0100455 ++max_count;
456 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100457
steniu014c2938e2017-06-19 15:44:45 +0100458 if(loc_max)
459 {
460 _max_loc->push_back(p);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100461 }
462 }
463 }
464 },
465 input);
466
467 if(count_min)
468 {
469 *_min_count = min_count;
470 }
471
472 if(count_max)
473 {
474 *_max_count = max_count;
475 }
476 }
477}
478} // namespace arm_compute