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