1 /* 2 * Copyright (c) 2018-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_NEPRIORBOXLAYERKERNEL_H 25 #define ARM_COMPUTE_NEPRIORBOXLAYERKERNEL_H 26 27 #include "src/core/NEON/INEKernel.h" 28 29 namespace arm_compute 30 { 31 class ITensor; 32 33 /** Interface for the kernel to calculate prior boxes */ 34 class NEPriorBoxLayerKernel : public INEKernel 35 { 36 public: name()37 const char *name() const override 38 { 39 return "NEPriorBoxLayerKernel"; 40 } 41 /** Default constructor */ 42 NEPriorBoxLayerKernel(); 43 /** Prevent instances of this class from being copied (As this class contains pointers) */ 44 NEPriorBoxLayerKernel(const NEPriorBoxLayerKernel &) = delete; 45 /** Prevent instances of this class from being copied (As this class contains pointers) */ 46 NEPriorBoxLayerKernel &operator=(const NEPriorBoxLayerKernel &) = delete; 47 /** Allow instances of this class to be moved */ 48 NEPriorBoxLayerKernel(NEPriorBoxLayerKernel &&) = default; 49 /** Allow instances of this class to be moved */ 50 NEPriorBoxLayerKernel &operator=(NEPriorBoxLayerKernel &&) = default; 51 /** Default destructor */ 52 ~NEPriorBoxLayerKernel() = default; 53 /** Set the input and output tensors. 54 * 55 * @param[in] input1 First source tensor. Data types supported: F32. Data layouts supported: NCHW/NHWC. 56 * @param[in] input2 Second source tensor. Data types and layouts supported: same as @p input1 57 * @param[out] output Destination tensor. Output dimensions are [W * H * num_priors * 4, 2]. Data type supported: same as @p input 58 * @param[in] info Prior box layer info. 59 */ 60 void configure(const ITensor *input1, const ITensor *input2, ITensor *output, const PriorBoxLayerInfo &info); 61 /** Static function to check if given info will lead to a valid configuration of @ref NEPriorBoxLayerKernel 62 * 63 * @param[in] input1 First source tensor info. Data types supported: F32. Data layouts supported: NCHW/NHWC. 64 * @param[in] input2 Second source tensor info. Data types and layouts supported: same as @p input1 65 * @param[in] output Destination tensor info. Output dimensions are [W * H * num_priors * 4, 2]. Data type supported: same as @p input 66 * @param[in] info Prior box layer info. 67 * 68 * @return a status 69 */ 70 static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const PriorBoxLayerInfo &info); 71 72 // Inherited methods overridden: 73 void run(const Window &window, const ThreadInfo &info) override; 74 75 private: 76 /** Stores the coordinates of the calculated prior boxes. 77 * 78 * @param[out] out Output pointer. 79 * @param[in] offset Output offset to write to. 80 * @param[in] center_x Center pixel value on x-axis. 81 * @param[in] center_y Center pixel value on y-axis. 82 * @param[in] box_width Prior box width. 83 * @param[in] box_height Prior box height. 84 * @param[in] width Input width. 85 * @param[in] height Input height. 86 */ 87 void store_coordinates(float *out, const int offset, const float center_x, const float center_y, const float box_width, const float box_height, const int width, const int height); 88 /** Function to calculate prior boxes. 89 * 90 * @param[in] window Input region on which to execute the kernel. 91 */ 92 void calculate_prior_boxes(const Window &window); 93 94 const ITensor *_input1; 95 const ITensor *_input2; 96 ITensor *_output; 97 PriorBoxLayerInfo _info; 98 }; 99 } // namespace arm_compute 100 #endif /* ARM_COMPUTE_NEPRIORBOXLAYERKERNEL_H */ 101