blob: c4d0297aef5c35549700803b7fb04cf934d36aa3 [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_CLCANNYEDGEKERNEL_H
25#define ARM_COMPUTE_CLCANNYEDGEKERNEL_H
Anthony Barbier6ff3b192017-09-04 18:44:23 +010026
27#include "arm_compute/core/CL/ICLKernel.h"
28
Anthony Barbier6ff3b192017-09-04 18:44:23 +010029namespace arm_compute
30{
31class ICLTensor;
32
33/** OpenCL kernel to perform Gradient computation.
34 */
35class CLGradientKernel : public ICLKernel
36{
37public:
38 /** Constructor */
39 CLGradientKernel();
Alex Gildayc357c472018-03-21 13:54:09 +000040 /** Prevent instances of this class from being copied (As this class contains pointers) */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010041 CLGradientKernel(const CLGradientKernel &) = delete;
Alex Gildayc357c472018-03-21 13:54:09 +000042 /** Prevent instances of this class from being copied (As this class contains pointers) */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010043 CLGradientKernel &operator=(const CLGradientKernel &) = delete;
44 /** Initialise the kernel's sources, destinations and border mode.
45 *
46 * @note gx, gy and mag must all be the same size (either 16 or 32).
47 *
48 * @param[in] gx Source tensor - Gx component. Data types supported: S16/S32.
49 * @param[in] gy Source tensor - Gy component. Data types supported: Same as gx.
50 * @param[out] magnitude Destination tensor - Magnitude. Data types supported: U16/U32. Must match the pixel size of gx, gy.
51 * @param[out] phase Destination tensor - Quantized phase. Data types supported: U8.
52 * @param[in] norm_type Normalization type. if 1, L1-Norm otherwise L2-Norm.
53 */
54 void configure(const ICLTensor *gx, const ICLTensor *gy, ICLTensor *magnitude, ICLTensor *phase, int32_t norm_type);
Manuel Bottini4c6bd512020-04-08 10:15:51 +010055 /** Initialise the kernel's sources, destinations and border mode.
56 *
57 * @note gx, gy and mag must all be the same size (either 16 or 32).
58 *
59 * @param[in] compile_context The compile context to be used.
60 * @param[in] gx Source tensor - Gx component. Data types supported: S16/S32.
61 * @param[in] gy Source tensor - Gy component. Data types supported: Same as gx.
62 * @param[out] magnitude Destination tensor - Magnitude. Data types supported: U16/U32. Must match the pixel size of gx, gy.
63 * @param[out] phase Destination tensor - Quantized phase. Data types supported: U8.
64 * @param[in] norm_type Normalization type. if 1, L1-Norm otherwise L2-Norm.
65 */
Manuel Bottini256c0b92020-04-21 13:29:30 +010066 void configure(const CLCompileContext &compile_context, const ICLTensor *gx, const ICLTensor *gy, ICLTensor *magnitude, ICLTensor *phase, int32_t norm_type);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010067
68 // Inherited methods overridden:
69 void run(const Window &window, cl::CommandQueue &queue) override;
70
71private:
72 const ICLTensor *_gx; /**< Source tensor - Gx component */
73 const ICLTensor *_gy; /**< Source tensor - Gy component */
74 ICLTensor *_magnitude; /**< Destination tensor - Magnitude */
75 ICLTensor *_phase; /**< Destination tensor - Quantized phase */
76};
77
78/** OpenCL kernel to perform Non-Maxima suppression for Canny Edge.
79 *
80 * @note This kernel is meant to be used alongside CannyEdge and performs a non-maxima suppression using magnitude and phase of input
81 * to characterize points as possible edges. The output buffer needs to be cleared before this kernel is executed.
82 *
83 * @note Hysteresis is computed in @ref CLEdgeTraceKernel
84 */
85class CLEdgeNonMaxSuppressionKernel : public ICLKernel
86{
87public:
88 /** Constructor */
89 CLEdgeNonMaxSuppressionKernel();
90 /** Prevent instances of this class from being copied (As this class contains pointers) */
91 CLEdgeNonMaxSuppressionKernel(const CLEdgeNonMaxSuppressionKernel &) = delete;
92 /** Prevent instances of this class from being copied (As this class contains pointers) */
93 CLEdgeNonMaxSuppressionKernel &operator=(const CLEdgeNonMaxSuppressionKernel &) = delete;
94 /** Initialise the kernel's sources, destination and border mode.
95 *
96 * @param[in] magnitude Source tensor - Magnitude. Data types supported: U16/U32.
97 * @param[in] phase Source tensor - Quantized phase. Data types supported: U8.
98 * @param[out] output Destination tensor. Data types supported: U16/U32.
99 * @param[in] lower_thr Lower threshold.
100 * @param[in] border_undefined True if the border mode is undefined. False if it's replicate or constant.
101 */
102 void configure(const ICLTensor *magnitude, const ICLTensor *phase, ICLTensor *output, int32_t lower_thr, bool border_undefined);
Manuel Bottini4c6bd512020-04-08 10:15:51 +0100103 /** Initialise the kernel's sources, destination and border mode.
104 *
105 * @param[in] compile_context The compile context to be used.
106 * @param[in] magnitude Source tensor - Magnitude. Data types supported: U16/U32.
107 * @param[in] phase Source tensor - Quantized phase. Data types supported: U8.
108 * @param[out] output Destination tensor. Data types supported: U16/U32.
109 * @param[in] lower_thr Lower threshold.
110 * @param[in] border_undefined True if the border mode is undefined. False if it's replicate or constant.
111 */
Manuel Bottini256c0b92020-04-21 13:29:30 +0100112 void configure(const CLCompileContext &compile_context, const ICLTensor *magnitude, const ICLTensor *phase, ICLTensor *output, int32_t lower_thr, bool border_undefined);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100113
114 // Inherited methods overridden:
115 void run(const Window &window, cl::CommandQueue &queue) override;
116 BorderSize border_size() const override;
117
118private:
119 const ICLTensor *_magnitude; /**< Source tensor - Magnitude. */
120 const ICLTensor *_phase; /**< Source tensor - Quantized phase. */
121 ICLTensor *_output; /**< Destination tensor. */
122};
123
124/** OpenCL kernel to perform Edge tracing.
125 */
126class CLEdgeTraceKernel : public ICLKernel
127{
128public:
129 /** Constructor */
130 CLEdgeTraceKernel();
131 /** Prevent instances of this class from being copied (As this class contains pointers) */
132 CLEdgeTraceKernel(const CLEdgeTraceKernel &) = delete;
133 /** Prevent instances of this class from being copied (As this class contains pointers) */
134 CLEdgeTraceKernel &operator=(const CLEdgeTraceKernel &) = delete;
135 /** Initialise the kernel's source, destination and border mode.
136 *
Michele Di Giorgiof6f78762020-07-06 11:27:21 +0100137 * @param[in] input Source tensor. Data types supported: U16/U32.
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100138 * @param[out] output Destination tensor. Data types supported: U8.
139 * @param[in] upper_thr Upper threshold used for the hysteresis
140 * @param[in] lower_thr Lower threshold used for the hysteresis
141 * @param[in,out] visited Tensor for keeping the visited pixels. Data types supported: U32.
142 * Expected to be initialized to 0 before each run.
143 * @param[in,out] recorded Tensor for keeping the recorded pixels. Data types supported: U32
144 * Expected to be initialized to 0 before each run.
145 * @param[in,out] l1_stack Tensor with the L1 stack for each pixel. Data types supported: S32.
146 * Expected to be initialized to 0 before each run.
147 * @param[in,out] l1_stack_counter Tensor for counting the elements in the L1 stack of each pixel. Data types supported: U8.
148 * Expected to be initialized to 0 before each run.
149 */
150 void configure(const ICLTensor *input, ICLTensor *output, int32_t upper_thr, int32_t lower_thr,
151 ICLTensor *visited, ICLTensor *recorded, ICLTensor *l1_stack, ICLTensor *l1_stack_counter);
Manuel Bottini4c6bd512020-04-08 10:15:51 +0100152 /** Initialise the kernel's source, destination and border mode.
153 *
154 * @param[in] compile_context The compile context to be used.
Michele Di Giorgiof6f78762020-07-06 11:27:21 +0100155 * @param[in] input Source tensor. Data types supported: U16/U32.
Manuel Bottini4c6bd512020-04-08 10:15:51 +0100156 * @param[out] output Destination tensor. Data types supported: U8.
157 * @param[in] upper_thr Upper threshold used for the hysteresis
158 * @param[in] lower_thr Lower threshold used for the hysteresis
159 * @param[in,out] visited Tensor for keeping the visited pixels. Data types supported: U32.
160 * Expected to be initialized to 0 before each run.
161 * @param[in,out] recorded Tensor for keeping the recorded pixels. Data types supported: U32
162 * Expected to be initialized to 0 before each run.
163 * @param[in,out] l1_stack Tensor with the L1 stack for each pixel. Data types supported: S32.
164 * Expected to be initialized to 0 before each run.
165 * @param[in,out] l1_stack_counter Tensor for counting the elements in the L1 stack of each pixel. Data types supported: U8.
166 * Expected to be initialized to 0 before each run.
167 */
Manuel Bottini256c0b92020-04-21 13:29:30 +0100168 void configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output, int32_t upper_thr, int32_t lower_thr,
Manuel Bottini4c6bd512020-04-08 10:15:51 +0100169 ICLTensor *visited, ICLTensor *recorded, ICLTensor *l1_stack, ICLTensor *l1_stack_counter);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100170
171 // Inherited methods overridden:
172 void run(const Window &window, cl::CommandQueue &queue) override;
173
174private:
175 const ICLTensor *_input; /**< Source tensor. */
176 ICLTensor *_output; /**< Destination tensor. */
177 int32_t _lower_thr; /**< Lower threshold used for the hysteresis. */
178 int32_t _upper_thr; /**< Upper threshold used for the hysteresis. */
179 ICLTensor *_visited; /**< Marks visited elements */
180 ICLTensor *_recorded; /**< Marks recorded elements */
181 ICLTensor *_l1_stack; /**< L1 hysteris stack */
182 ICLTensor *_l1_stack_counter; /**< L1 hysteris stack counter */
183};
Gian Marco Iodicef670a0a2017-09-18 12:20:45 +0100184} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000185#endif /* ARM_COMPUTE_CLCANNYEDGEKERNEL_H */