• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2017-2020 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_CLMINMAXLOCATIONKERNEL_H
25 #define ARM_COMPUTE_CLMINMAXLOCATIONKERNEL_H
26 
27 #include "arm_compute/core/CL/ICLArray.h"
28 #include "src/core/CL/ICLKernel.h"
29 
30 #include <array>
31 
32 namespace arm_compute
33 {
34 class ICLTensor;
35 using ICLImage = ICLTensor;
36 
37 /** Interface for the kernel to perform min max search on an image.
38  */
39 class CLMinMaxKernel : public ICLKernel
40 {
41 public:
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      *
54      * @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.
56      */
57     void configure(const ICLImage *input, cl::Buffer *min_max);
58     /** 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      */
64     void configure(const CLCompileContext &compile_context, const ICLImage *input, cl::Buffer *min_max);
65 
66     // Inherited methods overridden:
67     void run(const Window &window, cl::CommandQueue &queue) override;
68 
69 private:
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  */
77 class CLMinMaxLocationKernel : public ICLKernel
78 {
79 public:
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      *
94      * @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.
96      * @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);
102     /** 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      */
113     void configure(const CLCompileContext &compile_context, const ICLImage *input, cl::Buffer *min_max, cl::Buffer *min_max_count,
114                    ICLCoordinates2DArray *min_loc = nullptr, ICLCoordinates2DArray *max_loc = nullptr);
115 
116     // Inherited methods overridden:
117     void run(const Window &window, cl::CommandQueue &queue) override;
118 
119 private:
120     const ICLImage *_input;         /**< Input image. */
121     cl::Buffer     *_min_max_count; /**< Minimum/maximum value occurrences. */
122 };
123 } // namespace arm_compute
124 #endif /*ARM_COMPUTE_CLMINMAXLOCATIONKERNEL_H */
125