1 /* 2 * Copyright (c) 2016-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_CLSOBEL7X7KERNEL_H 25 #define ARM_COMPUTE_CLSOBEL7X7KERNEL_H 26 27 #include "src/core/CL/ICLKernel.h" 28 29 namespace arm_compute 30 { 31 class ICLTensor; 32 33 /** Interface for the kernel to run the horizontal pass of 7x7 Sobel filter on a tensor. */ 34 class CLSobel7x7HorKernel : public ICLKernel 35 { 36 public: 37 /** Default constructor: initialize all the pointers to nullptr and parameters to zero. */ 38 CLSobel7x7HorKernel(); 39 /** Prevent instances of this class from being copied (As this class contains pointers) */ 40 CLSobel7x7HorKernel(const CLSobel7x7HorKernel &) = delete; 41 /** Prevent instances of this class from being copied (As this class contains pointers) */ 42 CLSobel7x7HorKernel &operator=(const CLSobel7x7HorKernel &) = delete; 43 /** Allow instances of this class to be moved */ 44 CLSobel7x7HorKernel(CLSobel7x7HorKernel &&) = default; 45 /** Allow instances of this class to be moved */ 46 CLSobel7x7HorKernel &operator=(CLSobel7x7HorKernel &&) = default; 47 /** Default destructor */ 48 ~CLSobel7x7HorKernel() = default; 49 50 /** Initialise the kernel's source, destination and border. 51 * 52 * @note At least one of output_x or output_y must be set. 53 * 54 * @param[in] input Source tensor. Data types supported: U8. 55 * @param[out] output_x (Optional) Destination tensor for the X gradient, Data types supported: S32. 56 * @param[out] output_y (Optional) Destination tensor for the Y gradient, Data types supported: S32. 57 * @param[in] border_undefined True if the border mode is undefined. False if it's replicate or constant. 58 */ 59 void configure(const ICLTensor *input, ICLTensor *output_x, ICLTensor *output_y, bool border_undefined); 60 /** Initialise the kernel's source, destination and border. 61 * 62 * @note At least one of output_x or output_y must be set. 63 * 64 * @param[in] compile_context The compile context to be used. 65 * @param[in] input Source tensor. Data types supported: U8. 66 * @param[out] output_x (Optional) Destination tensor for the X gradient, Data types supported: S32. 67 * @param[out] output_y (Optional) Destination tensor for the Y gradient, Data types supported: S32. 68 * @param[in] border_undefined True if the border mode is undefined. False if it's replicate or constant. 69 */ 70 void configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output_x, ICLTensor *output_y, bool border_undefined); 71 72 // Inherited methods overridden: 73 void run(const Window &window, cl::CommandQueue &queue) override; 74 BorderSize border_size() const override; 75 76 private: 77 const ICLTensor *_input; /**< Input tensor */ 78 ICLTensor *_output_x; /**< X output of horizontal pass */ 79 ICLTensor *_output_y; /**< Y output of horizontal pass */ 80 bool _run_sobel_x; /**< Do we need to run Sobel X ? */ 81 bool _run_sobel_y; /**< Do we need to run Sobel Y ? */ 82 BorderSize _border_size; /**< Border size */ 83 }; 84 85 /** Interface for the kernel to run the vertical pass of 7x7 Sobel filter on a tensor. */ 86 class CLSobel7x7VertKernel : public ICLKernel 87 { 88 public: 89 /** Default constructor: initialize all the pointers to nullptr and parameters to zero. */ 90 CLSobel7x7VertKernel(); 91 /** Prevent instances of this class from being copied (As this class contains pointers) */ 92 CLSobel7x7VertKernel(const CLSobel7x7VertKernel &) = delete; 93 /** Prevent instances of this class from being copied (As this class contains pointers) */ 94 CLSobel7x7VertKernel &operator=(const CLSobel7x7VertKernel &) = delete; 95 /** Allow instances of this class to be moved */ 96 CLSobel7x7VertKernel(CLSobel7x7VertKernel &&) = default; 97 /** Allow instances of this class to be moved */ 98 CLSobel7x7VertKernel &operator=(CLSobel7x7VertKernel &&) = default; 99 /** Default destructor */ 100 ~CLSobel7x7VertKernel() = default; 101 102 /** Initialise the kernel's source, destination and border. 103 * 104 * @note At least one of output_x or output_y must be set and the corresponding input. 105 * 106 * @param[in] input_x (Optional) Input for X (X output of horizontal pass). Data types supported: S32. 107 * @param[in] input_y (Optional) Input for Y (Y output of horizontal pass). Data types supported: S32. 108 * @param[out] output_x (Optional) Destination tensor for the X gradient, Data types supported: S32. 109 * @param[out] output_y (Optional) Destination tensor for the Y gradient, Data types supported: S32. 110 * @param[in] border_undefined True if the border mode is undefined. False if it's replicate or constant. 111 */ 112 void configure(const ICLTensor *input_x, const ICLTensor *input_y, ICLTensor *output_x, ICLTensor *output_y, bool border_undefined); 113 /** Initialise the kernel's source, destination and border. 114 * 115 * @note At least one of output_x or output_y must be set and the corresponding input. 116 * 117 * @param[in] compile_context The compile context to be used. 118 * @param[in] input_x (Optional) Input for X (X output of horizontal pass). Data types supported: S32. 119 * @param[in] input_y (Optional) Input for Y (Y output of horizontal pass). Data types supported: S32. 120 * @param[out] output_x (Optional) Destination tensor for the X gradient, Data types supported: S32. 121 * @param[out] output_y (Optional) Destination tensor for the Y gradient, Data types supported: S32. 122 * @param[in] border_undefined True if the border mode is undefined. False if it's replicate or constant. 123 */ 124 void configure(const CLCompileContext &compile_context, const ICLTensor *input_x, const ICLTensor *input_y, ICLTensor *output_x, ICLTensor *output_y, bool border_undefined); 125 126 // Inherited methods overridden: 127 void run(const Window &window, cl::CommandQueue &queue) override; 128 BorderSize border_size() const override; 129 130 private: 131 const ICLTensor *_input_x; /**< X input (X output of the horizontal pass) */ 132 const ICLTensor *_input_y; /**< Y input (Y output of the horizontal pass) */ 133 ICLTensor *_output_x; /**< X output of sobel */ 134 ICLTensor *_output_y; /**< Y output of sobel */ 135 bool _run_sobel_x; /**< Do we need to run sobel X? */ 136 bool _run_sobel_y; /**< Do we need to run sobel Y? */ 137 }; 138 } // namespace arm_compute 139 #endif /*ARM_COMPUTE_CLSOBEL7X7KERNEL_H */ 140