blob: 83f5afce72a2dda892ae9e0a58e9717a3cb5f1ef [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +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 Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_NEMINMAXLOCATIONKERNEL_H
25#define ARM_COMPUTE_NEMINMAXLOCATIONKERNEL_H
Anthony Barbier6ff3b192017-09-04 18:44:23 +010026
27#include "arm_compute/core/IArray.h"
28#include "arm_compute/core/NEON/INEKernel.h"
Michalis Spyrou07781ac2017-08-31 15:11:41 +010029#include "support/Mutex.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010030
31#include <cstdint>
Anthony Barbier6ff3b192017-09-04 18:44:23 +010032
33namespace arm_compute
34{
35class ITensor;
36using IImage = ITensor;
37
38/** Interface for the kernel to perform min max search on an image. */
39class NEMinMaxKernel : public INEKernel
40{
41public:
Anthony Barbiere8a49832018-01-18 10:04:05 +000042 const char *name() const override
43 {
44 return "NEMinMaxKernel";
45 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +010046 /** Default constructor */
47 NEMinMaxKernel();
48 /** Prevent instances of this class from being copied (As this class contains pointers) */
49 NEMinMaxKernel(const NEMinMaxKernel &) = delete;
50 /** Prevent instances of this class from being copied (As this class contains pointers) */
51 NEMinMaxKernel &operator=(const NEMinMaxKernel &) = delete;
Georgios Pinitasca4111d2020-02-21 13:21:37 +000052 /** Prevent instances of this class from being moved (As this class contains non movable objects) */
53 NEMinMaxKernel(NEMinMaxKernel &&) = delete;
54 /** Prevent instances of this class from being moved (As this class contains non movable objects) */
55 NEMinMaxKernel &operator=(NEMinMaxKernel &&) = delete;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010056 /** Default destructor */
57 ~NEMinMaxKernel() = default;
58
59 /** Initialise the kernel's input and outputs.
60 *
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +010061 * @param[in] input Input Image. Data types supported: U8/S16/F32.
62 * @param[out] min Minimum value of image. Data types supported: S32 if input type is U8/S16, F32 if input type is F32.
63 * @param[out] max Maximum value of image. Data types supported: S32 if input type is U8/S16, F32 if input type is F32.
Anthony Barbier6ff3b192017-09-04 18:44:23 +010064 */
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +010065 void configure(const IImage *input, void *min, void *max);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010066 /** Resets global minimum and maximum. */
67 void reset();
68
69 // Inherited methods overridden:
Moritz Pflanzerc186b572017-09-07 09:48:04 +010070 void run(const Window &window, const ThreadInfo &info) override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010071
72private:
73 /** Performs the min/max algorithm on U8 images on a given window.
74 *
75 * @param win The window to run the algorithm on.
76 */
steniu014c2938e2017-06-19 15:44:45 +010077 void minmax_U8(Window win);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010078 /** Performs the min/max algorithm on S16 images on a given window.
79 *
80 * @param win The window to run the algorithm on.
81 */
steniu014c2938e2017-06-19 15:44:45 +010082 void minmax_S16(Window win);
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +010083 /** Performs the min/max algorithm on F32 images on a given window.
84 *
85 * @param win The window to run the algorithm on.
86 */
87 void minmax_F32(Window win);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010088 /** Common signature for all the specialised MinMax functions
89 *
90 * @param[in] window Region on which to execute the kernel.
91 */
steniu014c2938e2017-06-19 15:44:45 +010092 using MinMaxFunction = void (NEMinMaxKernel::*)(Window window);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010093 /** MinMax function to use for the particular image types passed to configure() */
94 MinMaxFunction _func;
95 /** Helper to update min/max values **/
96 template <typename T>
97 void update_min_max(T min, T max);
98
Michalis Spyrou07781ac2017-08-31 15:11:41 +010099 const IImage *_input; /**< Input image. */
100 void *_min; /**< Minimum value. */
101 void *_max; /**< Maximum value. */
102 arm_compute::Mutex _mtx; /**< Mutex used for result reduction. */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100103};
104
105/** Interface for the kernel to find min max locations of an image. */
106class NEMinMaxLocationKernel : public INEKernel
107{
108public:
Anthony Barbiere8a49832018-01-18 10:04:05 +0000109 const char *name() const override
110 {
111 return "NEMinMaxLocationKernel";
112 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100113 /** Default constructor */
114 NEMinMaxLocationKernel();
115 /** Prevent instances of this class from being copied (As this class contains pointers) */
116 NEMinMaxLocationKernel(const NEMinMaxLocationKernel &) = delete;
117 /** Prevent instances of this class from being copied (As this class contains pointers) */
118 NEMinMaxLocationKernel &operator=(const NEMinMaxLocationKernel &) = delete;
119 /** Allow instances of this class to be moved */
120 NEMinMaxLocationKernel(NEMinMaxLocationKernel &&) = default;
121 /** Allow instances of this class to be moved */
122 NEMinMaxLocationKernel &operator=(NEMinMaxLocationKernel &&) = default;
123 /** Default destructor */
124 ~NEMinMaxLocationKernel() = default;
125
126 /** Initialise the kernel's input and outputs.
127 *
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +0100128 * @param[in] input Input Image. Data types supported: U8/S16/F32.
129 * @param[out] min Minimum value of image. Data types supported: S32 if input type is U8/S16, F32 if input type is F32.
130 * @param[out] max Maximum value of image. Data types supported: S32 if input type is U8/S16, F32 if input type is F32.
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100131 * @param[out] min_loc Array of minimum value locations.
132 * @param[out] max_loc Array of maximum value locations.
133 * @param[out] min_count Number of minimum value encounters.
134 * @param[out] max_count Number of maximum value encounters.
135 */
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +0100136 void configure(const IImage *input, void *min, void *max,
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100137 ICoordinates2DArray *min_loc = nullptr, ICoordinates2DArray *max_loc = nullptr,
138 uint32_t *min_count = nullptr, uint32_t *max_count = nullptr);
139
140 // Inherited methods overridden:
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100141 void run(const Window &window, const ThreadInfo &info) override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100142 bool is_parallelisable() const override;
143
144private:
145 /** Performs the min/max location algorithm on T type images on a given window.
146 *
147 * @param win The window to run the algorithm on.
148 */
149 template <class T, bool count_min, bool count_max, bool loc_min, bool loc_max>
150 void minmax_loc(const Window &win);
151 /** Common signature for all the specialised MinMaxLoc functions
152 *
153 * @param[in] window Region on which to execute the kernel.
154 */
155 using MinMaxLocFunction = void (NEMinMaxLocationKernel::*)(const Window &window);
156 /** MinMaxLoc function to use for the particular image types passed to configure() */
157 MinMaxLocFunction _func;
158 /** Helper to create a function pointer table for the parameterized MinMaxLocation functions. */
159 template <class T, typename>
160 struct create_func_table;
161
steniu014c2938e2017-06-19 15:44:45 +0100162 const IImage *_input; /**< Input image. */
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +0100163 void *_min; /**< Minimum value. */
164 void *_max; /**< Maximum value. */
steniu014c2938e2017-06-19 15:44:45 +0100165 uint32_t *_min_count; /**< Count of minimum value encounters. */
166 uint32_t *_max_count; /**< Count of maximum value encounters. */
167 ICoordinates2DArray *_min_loc; /**< Locations of minimum values. */
168 ICoordinates2DArray *_max_loc; /**< Locations of maximum values. */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100169};
Gian Marco Iodice356f6432017-09-22 11:32:21 +0100170} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000171#endif /*ARM_COMPUTE_NEMINMAXLOCATIONKERNEL_H */