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_CLHOGDESCRIPTORKERNEL_H 25 #define ARM_COMPUTE_CLHOGDESCRIPTORKERNEL_H 26 27 #include "arm_compute/core/IHOG.h" 28 #include "arm_compute/core/Size2D.h" 29 #include "src/core/CL/ICLKernel.h" 30 31 namespace arm_compute 32 { 33 class ITensor; 34 35 /** OpenCL kernel to perform HOG Orientation Binning */ 36 class CLHOGOrientationBinningKernel : public ICLKernel 37 { 38 public: 39 /** Default constructor */ 40 CLHOGOrientationBinningKernel(); 41 /** Prevent instances of this class from being copied (As this class contains pointers) */ 42 CLHOGOrientationBinningKernel(const CLHOGOrientationBinningKernel &) = delete; 43 /** Prevent instances of this class from being copied (As this class contains pointers) */ 44 CLHOGOrientationBinningKernel &operator=(const CLHOGOrientationBinningKernel &) = delete; 45 /** Allow instances of this class to be moved */ 46 CLHOGOrientationBinningKernel(CLHOGOrientationBinningKernel &&) = default; 47 /** Allow instances of this class to be moved */ 48 CLHOGOrientationBinningKernel &operator=(CLHOGOrientationBinningKernel &&) = default; 49 /** Default destructor */ 50 ~CLHOGOrientationBinningKernel() = default; 51 52 /** Initialise the kernel's inputs, output and HOG's metadata 53 * 54 * @param[in] input_magnitude Input tensor which stores the magnitude of the gradient for each pixel. Data type supported: S16. 55 * @param[in] input_phase Input tensor which stores the phase of the gradient for each pixel. Data type supported: U8 56 * @param[out] output Output tensor which stores the local HOG for each cell. DataType supported: F32. Number of channels supported: equal to the number of histogram bins per cell 57 * @param[in] hog_info HOG's metadata 58 */ 59 void configure(const ICLTensor *input_magnitude, const ICLTensor *input_phase, ICLTensor *output, const HOGInfo *hog_info); 60 /** Initialise the kernel's inputs, output and HOG's metadata 61 * 62 * @param[in] compile_context The compile context to be used. 63 * @param[in] input_magnitude Input tensor which stores the magnitude of the gradient for each pixel. Data type supported: S16. 64 * @param[in] input_phase Input tensor which stores the phase of the gradient for each pixel. Data type supported: U8 65 * @param[out] output Output tensor which stores the local HOG for each cell. DataType supported: F32. Number of channels supported: equal to the number of histogram bins per cell 66 * @param[in] hog_info HOG's metadata 67 */ 68 void configure(const CLCompileContext &compile_context, const ICLTensor *input_magnitude, const ICLTensor *input_phase, ICLTensor *output, const HOGInfo *hog_info); 69 70 // Inherited methods overridden: 71 void run(const Window &window, cl::CommandQueue &queue) override; 72 73 private: 74 const ICLTensor *_input_magnitude; 75 const ICLTensor *_input_phase; 76 ICLTensor *_output; 77 Size2D _cell_size; 78 }; 79 80 /** OpenCL kernel to perform HOG block normalization */ 81 class CLHOGBlockNormalizationKernel : public ICLKernel 82 { 83 public: 84 /** Default constructor */ 85 CLHOGBlockNormalizationKernel(); 86 /** Prevent instances of this class from being copied (As this class contains pointers) */ 87 CLHOGBlockNormalizationKernel(const CLHOGBlockNormalizationKernel &) = delete; 88 /** Prevent instances of this class from being copied (As this class contains pointers) */ 89 CLHOGBlockNormalizationKernel &operator=(const CLHOGBlockNormalizationKernel &) = delete; 90 /** Allow instances of this class to be moved */ 91 CLHOGBlockNormalizationKernel(CLHOGBlockNormalizationKernel &&) = default; 92 /** Allow instances of this class to be moved */ 93 CLHOGBlockNormalizationKernel &operator=(CLHOGBlockNormalizationKernel &&) = default; 94 /** Default destructor */ 95 ~CLHOGBlockNormalizationKernel() = default; 96 97 /** Initialise the kernel's input, output and HOG's metadata 98 * 99 * @param[in] input Input tensor which stores the local HOG for each cell. Data type supported: F32. Number of channels supported: equal to the number of histogram bins per cell 100 * @param[out] output Output tensor which stores the normalised blocks. Data type supported: F32. Number of channels supported: equal to the number of histogram bins per block 101 * @param[in] hog_info HOG's metadata 102 */ 103 void configure(const ICLTensor *input, ICLTensor *output, const HOGInfo *hog_info); 104 /** Initialise the kernel's input, output and HOG's metadata 105 * 106 * @param[in] compile_context The compile context to be used. 107 * @param[in] input Input tensor which stores the local HOG for each cell. Data type supported: F32. Number of channels supported: equal to the number of histogram bins per cell 108 * @param[out] output Output tensor which stores the normalised blocks. Data type supported: F32. Number of channels supported: equal to the number of histogram bins per block 109 * @param[in] hog_info HOG's metadata 110 */ 111 void configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output, const HOGInfo *hog_info); 112 113 // Inherited methods overridden: 114 void run(const Window &window, cl::CommandQueue &queue) override; 115 116 private: 117 const ICLTensor *_input; 118 ICLTensor *_output; 119 Size2D _num_cells_per_block_stride; 120 }; 121 } // namespace arm_compute 122 #endif /* ARM_COMPUTE_CLHOGDESCRIPTORKERNEL_H */ 123