blob: 5f0ddad812ed470a58799faa8f75d541ba17c03e [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
2 * Copyright (c) 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_CLMINMAXLOCATIONKERNEL_H__
25#define __ARM_COMPUTE_CLMINMAXLOCATIONKERNEL_H__
26
27#include "arm_compute/core/CL/ICLArray.h"
28#include "arm_compute/core/CL/ICLKernel.h"
29
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);
58
59 // Inherited methods overridden:
60 void run(const Window &window, cl::CommandQueue &queue) override;
61
62private:
63 const ICLTensor *_input; /**< Input image. */
64 cl::Buffer *_min_max; /**< Minimum/maximum value. */
65 std::array<int, 2> _data_type_max_min; /**< Maximum and minimum data type value respectively. */
66};
67
68/** Interface for the kernel to find min max locations of an image.
69 */
70class CLMinMaxLocationKernel : public ICLKernel
71{
72public:
73 /** Constructor */
74 CLMinMaxLocationKernel();
75 /** Prevent instances of this class from being copied (As this class contains pointers) */
76 CLMinMaxLocationKernel(const CLMinMaxLocationKernel &) = delete;
77 /** Prevent instances of this class from being copied (As this class contains pointers) */
78 CLMinMaxLocationKernel &operator=(const CLMinMaxLocationKernel &) = delete;
79 /** Allow instances of this class to be moved */
80 CLMinMaxLocationKernel(CLMinMaxLocationKernel &&) = default;
81 /** Allow instances of this class to be moved */
82 CLMinMaxLocationKernel &operator=(CLMinMaxLocationKernel &&) = default;
83 /** Initialise the kernel's input and outputs.
84 *
85 * @note When locations of min and max occurrences are requested, the reported number of locations is limited to the given array size.
86 *
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +010087 * @param[in] input Input image. Data types supported: U8/S16/F32.
88 * @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 +010089 * @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
90 * @param[out] min_loc (Optional) Array of Coordinates2D used to store minimum value locations.
91 * @param[out] max_loc (Optional) Array of Coordinates2D used to store maximum value locations.
92 */
93 void configure(const ICLImage *input, cl::Buffer *min_max, cl::Buffer *min_max_count,
94 ICLCoordinates2DArray *min_loc = nullptr, ICLCoordinates2DArray *max_loc = nullptr);
95
96 // Inherited methods overridden:
97 void run(const Window &window, cl::CommandQueue &queue) override;
98
99private:
100 const ICLImage *_input; /**< Input image. */
101 cl::Buffer *_min_max_count; /**< Minimum/maximum value occurrences. */
102};
Gian Marco Iodicef670a0a2017-09-18 12:20:45 +0100103} // namespace arm_compute
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100104#endif /*__ARM_COMPUTE_CLMINMAXLOCATIONKERNEL_H__ */