blob: 2196abe033744760d31c5b6c413c13b411bf6f34 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2017-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_CLMINMAXLOCATIONKERNEL_H
25#define ARM_COMPUTE_CLMINMAXLOCATIONKERNEL_H
Anthony Barbier6ff3b192017-09-04 18:44:23 +010026
27#include "arm_compute/core/CL/ICLArray.h"
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +010028#include "src/core/CL/ICLKernel.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010029
30#include <array>
31
32namespace arm_compute
33{
34class ICLTensor;
35using ICLImage = ICLTensor;
36
37/** Interface for the kernel to perform min max search on an image.
38 */
39class CLMinMaxKernel : public ICLKernel
40{
41public:
42 /** Default constructor */
43 CLMinMaxKernel();
44 /** Prevent instances of this class from being copied (As this class contains pointers) */
45 CLMinMaxKernel(const CLMinMaxKernel &) = delete;
46 /** Prevent instances of this class from being copied (As this class contains pointers) */
47 CLMinMaxKernel &operator=(const CLMinMaxKernel &) = delete;
48 /** Allow instances of this class to be moved */
49 CLMinMaxKernel(CLMinMaxKernel &&) = default;
50 /** Allow instances of this class to be moved */
51 CLMinMaxKernel &operator=(CLMinMaxKernel &&) = default;
52 /** Initialise the kernel's input and output.
53 *
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +010054 * @param[in] input Input Image. Data types supported: U8/S16/F32.
55 * @param[out] min_max Buffer of 2 elements to store the min value at position 0 and the max value at position 1. Data type supported: S32 if input type is U8/S16, F32 if input type is F32.
Anthony Barbier6ff3b192017-09-04 18:44:23 +010056 */
57 void configure(const ICLImage *input, cl::Buffer *min_max);
Manuel Bottini4c6bd512020-04-08 10:15:51 +010058 /** Initialise the kernel's input and output.
59 *
60 * @param[in] compile_context The compile context to be used.
61 * @param[in] input Input Image. Data types supported: U8/S16/F32.
62 * @param[out] min_max Buffer of 2 elements to store the min value at position 0 and the max value at position 1. Data type supported: S32 if input type is U8/S16, F32 if input type is F32.
63 */
Manuel Bottini679fc962020-04-21 16:08:53 +010064 void configure(const CLCompileContext &compile_context, const ICLImage *input, cl::Buffer *min_max);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010065
66 // Inherited methods overridden:
67 void run(const Window &window, cl::CommandQueue &queue) override;
68
69private:
70 const ICLTensor *_input; /**< Input image. */
71 cl::Buffer *_min_max; /**< Minimum/maximum value. */
72 std::array<int, 2> _data_type_max_min; /**< Maximum and minimum data type value respectively. */
73};
74
75/** Interface for the kernel to find min max locations of an image.
76 */
77class CLMinMaxLocationKernel : public ICLKernel
78{
79public:
80 /** Constructor */
81 CLMinMaxLocationKernel();
82 /** Prevent instances of this class from being copied (As this class contains pointers) */
83 CLMinMaxLocationKernel(const CLMinMaxLocationKernel &) = delete;
84 /** Prevent instances of this class from being copied (As this class contains pointers) */
85 CLMinMaxLocationKernel &operator=(const CLMinMaxLocationKernel &) = delete;
86 /** Allow instances of this class to be moved */
87 CLMinMaxLocationKernel(CLMinMaxLocationKernel &&) = default;
88 /** Allow instances of this class to be moved */
89 CLMinMaxLocationKernel &operator=(CLMinMaxLocationKernel &&) = default;
90 /** Initialise the kernel's input and outputs.
91 *
92 * @note When locations of min and max occurrences are requested, the reported number of locations is limited to the given array size.
93 *
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +010094 * @param[in] input Input image. Data types supported: U8/S16/F32.
95 * @param[out] min_max Buffer of 2 elements to store the min value at position 0 and the max value at position 1. Data type supported: S32 if input type is U8/S16, F32 if input type is F32.
Anthony Barbier6ff3b192017-09-04 18:44:23 +010096 * @param[out] min_max_count Buffer of 2 elements to store the min value occurrences at position 0 and the max value occurrences at position 1. Data type supported: S32
97 * @param[out] min_loc (Optional) Array of Coordinates2D used to store minimum value locations.
98 * @param[out] max_loc (Optional) Array of Coordinates2D used to store maximum value locations.
99 */
100 void configure(const ICLImage *input, cl::Buffer *min_max, cl::Buffer *min_max_count,
101 ICLCoordinates2DArray *min_loc = nullptr, ICLCoordinates2DArray *max_loc = nullptr);
Manuel Bottini4c6bd512020-04-08 10:15:51 +0100102 /** Initialise the kernel's input and outputs.
103 *
104 * @note When locations of min and max occurrences are requested, the reported number of locations is limited to the given array size.
105 *
106 * @param[in] compile_context The compile context to be used.
107 * @param[in] input Input image. Data types supported: U8/S16/F32.
108 * @param[out] min_max Buffer of 2 elements to store the min value at position 0 and the max value at position 1. Data type supported: S32 if input type is U8/S16, F32 if input type is F32.
109 * @param[out] min_max_count Buffer of 2 elements to store the min value occurrences at position 0 and the max value occurrences at position 1. Data type supported: S32
110 * @param[out] min_loc (Optional) Array of Coordinates2D used to store minimum value locations.
111 * @param[out] max_loc (Optional) Array of Coordinates2D used to store maximum value locations.
112 */
Manuel Bottini679fc962020-04-21 16:08:53 +0100113 void configure(const CLCompileContext &compile_context, const ICLImage *input, cl::Buffer *min_max, cl::Buffer *min_max_count,
Manuel Bottini4c6bd512020-04-08 10:15:51 +0100114 ICLCoordinates2DArray *min_loc = nullptr, ICLCoordinates2DArray *max_loc = nullptr);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100115
116 // Inherited methods overridden:
117 void run(const Window &window, cl::CommandQueue &queue) override;
118
119private:
120 const ICLImage *_input; /**< Input image. */
121 cl::Buffer *_min_max_count; /**< Minimum/maximum value occurrences. */
122};
Gian Marco Iodicef670a0a2017-09-18 12:20:45 +0100123} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000124#endif /*ARM_COMPUTE_CLMINMAXLOCATIONKERNEL_H */