blob: 7b2748deeed29d45ce79f149f09407c3dc3d29bb [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#ifndef __ARM_COMPUTE_NEMINMAXLOCATIONKERNEL_H__
25#define __ARM_COMPUTE_NEMINMAXLOCATIONKERNEL_H__
26
27#include "arm_compute/core/IArray.h"
28#include "arm_compute/core/NEON/INEKernel.h"
29
30#include <cstdint>
31#include <mutex>
32
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:
42 /** Default constructor */
43 NEMinMaxKernel();
44 /** Prevent instances of this class from being copied (As this class contains pointers) */
45 NEMinMaxKernel(const NEMinMaxKernel &) = delete;
46 /** Prevent instances of this class from being copied (As this class contains pointers) */
47 NEMinMaxKernel &operator=(const NEMinMaxKernel &) = delete;
48 /** Allow instances of this class to be moved */
49 NEMinMaxKernel(NEMinMaxKernel &&) = default;
50 /** Allow instances of this class to be moved */
51 NEMinMaxKernel &operator=(NEMinMaxKernel &&) = default;
52 /** Default destructor */
53 ~NEMinMaxKernel() = default;
54
55 /** Initialise the kernel's input and outputs.
56 *
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +010057 * @param[in] input Input Image. Data types supported: U8/S16/F32.
58 * @param[out] min Minimum value of image. Data types supported: S32 if input type is U8/S16, F32 if input type is F32.
59 * @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 +010060 */
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +010061 void configure(const IImage *input, void *min, void *max);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010062 /** Resets global minimum and maximum. */
63 void reset();
64
65 // Inherited methods overridden:
66 void run(const Window &window) override;
67
68private:
69 /** Performs the min/max algorithm on U8 images on a given window.
70 *
71 * @param win The window to run the algorithm on.
72 */
steniu014c2938e2017-06-19 15:44:45 +010073 void minmax_U8(Window win);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010074 /** Performs the min/max algorithm on S16 images on a given window.
75 *
76 * @param win The window to run the algorithm on.
77 */
steniu014c2938e2017-06-19 15:44:45 +010078 void minmax_S16(Window win);
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +010079 /** Performs the min/max algorithm on F32 images on a given window.
80 *
81 * @param win The window to run the algorithm on.
82 */
83 void minmax_F32(Window win);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010084 /** Common signature for all the specialised MinMax functions
85 *
86 * @param[in] window Region on which to execute the kernel.
87 */
steniu014c2938e2017-06-19 15:44:45 +010088 using MinMaxFunction = void (NEMinMaxKernel::*)(Window window);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010089 /** MinMax function to use for the particular image types passed to configure() */
90 MinMaxFunction _func;
91 /** Helper to update min/max values **/
92 template <typename T>
93 void update_min_max(T min, T max);
94
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +010095 const IImage *_input; /**< Input image. */
96 void *_min; /**< Minimum value. */
97 void *_max; /**< Maximum value. */
98 std::mutex _mtx; /**< Mutex used for result reduction. */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010099};
100
101/** Interface for the kernel to find min max locations of an image. */
102class NEMinMaxLocationKernel : public INEKernel
103{
104public:
105 /** Default constructor */
106 NEMinMaxLocationKernel();
107 /** Prevent instances of this class from being copied (As this class contains pointers) */
108 NEMinMaxLocationKernel(const NEMinMaxLocationKernel &) = delete;
109 /** Prevent instances of this class from being copied (As this class contains pointers) */
110 NEMinMaxLocationKernel &operator=(const NEMinMaxLocationKernel &) = delete;
111 /** Allow instances of this class to be moved */
112 NEMinMaxLocationKernel(NEMinMaxLocationKernel &&) = default;
113 /** Allow instances of this class to be moved */
114 NEMinMaxLocationKernel &operator=(NEMinMaxLocationKernel &&) = default;
115 /** Default destructor */
116 ~NEMinMaxLocationKernel() = default;
117
118 /** Initialise the kernel's input and outputs.
119 *
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +0100120 * @param[in] input Input Image. Data types supported: U8/S16/F32.
121 * @param[out] min Minimum value of image. Data types supported: S32 if input type is U8/S16, F32 if input type is F32.
122 * @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 +0100123 * @param[out] min_loc Array of minimum value locations.
124 * @param[out] max_loc Array of maximum value locations.
125 * @param[out] min_count Number of minimum value encounters.
126 * @param[out] max_count Number of maximum value encounters.
127 */
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +0100128 void configure(const IImage *input, void *min, void *max,
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100129 ICoordinates2DArray *min_loc = nullptr, ICoordinates2DArray *max_loc = nullptr,
130 uint32_t *min_count = nullptr, uint32_t *max_count = nullptr);
131
132 // Inherited methods overridden:
133 void run(const Window &window) override;
134 bool is_parallelisable() const override;
135
136private:
137 /** Performs the min/max location algorithm on T type images on a given window.
138 *
139 * @param win The window to run the algorithm on.
140 */
141 template <class T, bool count_min, bool count_max, bool loc_min, bool loc_max>
142 void minmax_loc(const Window &win);
143 /** Common signature for all the specialised MinMaxLoc functions
144 *
145 * @param[in] window Region on which to execute the kernel.
146 */
147 using MinMaxLocFunction = void (NEMinMaxLocationKernel::*)(const Window &window);
148 /** MinMaxLoc function to use for the particular image types passed to configure() */
149 MinMaxLocFunction _func;
150 /** Helper to create a function pointer table for the parameterized MinMaxLocation functions. */
151 template <class T, typename>
152 struct create_func_table;
153
steniu014c2938e2017-06-19 15:44:45 +0100154 const IImage *_input; /**< Input image. */
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +0100155 void *_min; /**< Minimum value. */
156 void *_max; /**< Maximum value. */
steniu014c2938e2017-06-19 15:44:45 +0100157 uint32_t *_min_count; /**< Count of minimum value encounters. */
158 uint32_t *_max_count; /**< Count of maximum value encounters. */
159 ICoordinates2DArray *_min_loc; /**< Locations of minimum values. */
160 ICoordinates2DArray *_max_loc; /**< Locations of maximum values. */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100161};
162}
163#endif /*__ARM_COMPUTE_NEMINMAXLOCATIONKERNEL_H__ */