1 /* 2 * Copyright (c) 2019-2021 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_NEON_CROP_KERNEL_H 25 #define ARM_COMPUTE_NEON_CROP_KERNEL_H 26 27 #include "arm_compute/core/Types.h" 28 #include "arm_compute/core/Types.h" 29 #include "src/core/NEON/INEKernel.h" 30 31 namespace arm_compute 32 { 33 // Forward declarations 34 class ITensor; 35 36 /** Interface for the kernel to perform tensor cropping */ 37 class NECropKernel : public INEKernel 38 { 39 public: name()40 const char *name() const override 41 { 42 return "NECropKernel"; 43 } 44 /** Default constructor */ 45 NECropKernel(); 46 /** Prevent instances of this class from being copied (As this class contains pointers) */ 47 NECropKernel(const NECropKernel &) = delete; 48 /** Prevent instances of this class from being copied (As this class contains pointers) */ 49 NECropKernel &operator=(const NECropKernel &) = delete; 50 /** Allow instances of this class to be moved */ 51 NECropKernel(NECropKernel &&) = default; 52 /** Allow instances of this class to be moved */ 53 NECropKernel &operator=(NECropKernel &&) = default; 54 /** Default destructor */ 55 ~NECropKernel() = default; 56 /** Configure kernel 57 * 58 * @note Supported tensor rank: up to 4 59 * @note Padding not supported. 60 * 61 * @param[in] input Source tensor. Data type supported: U8/U16/S16/U32/S32/F16/F32. Data layouts supported: NHWC. 62 * @param[in] crop_boxes Tensor containing all possible boxes used to crop the image, each represented by 4 normalized values. 63 * Data type supported: F32 64 * @param[in] box_ind One dimensional tensor mapping the @p crop_box_ind to the index of the 3D image in @p input. 65 * Data type supported: F32 66 * @param[out] output Destination tensor. Data type supported: F32 67 * @param[in] crop_box_ind Index of the crop box to be used from @p crop_boxes. Default is 0. 68 * @param[in] extrapolation_value Value to be used for values outside of the image. Default is 0. 69 */ 70 void configure(const ITensor *input, const ITensor *crop_boxes, const ITensor *box_ind, ITensor *output, uint32_t crop_box_ind = 0, float extrapolation_value = 0); 71 72 /** Static function to check if given info will lead to a valid configuration of @ref CLStridedSliceKernel 73 * 74 * @note Supported tensor rank: up to 4 75 * @note Padding not supported. 76 * 77 * @param[in] input Source tensor info. Data type supported: U8/U16/S16/U32/S32/F16/F32. Data layouts supported: NHWC. 78 * @param[in] crop_boxes Tensor info for tensor containing all possible boxes used to crop the image. Data type supported: F32 79 * @param[in] box_ind Tensor info for the one dimensional tensor mapping the @p crop_box_ind to the index of the 3D image 80 * in @p input. Data type supported: F32 81 * @param[in] output Destination tensor. Data type supported: F32 82 * @param[in] crop_box_ind Index of the crop box to be used from @p crop_boxes. Default is 0. 83 * @param[in] extrapolation_value Value to be used for values outside of the image. Default is 0. 84 */ 85 static Status validate(const ITensorInfo *input, const ITensorInfo *crop_boxes, const ITensorInfo *box_ind, const ITensorInfo *output, uint32_t crop_box_ind = 0, float extrapolation_value = 0); 86 87 /** Configure output tensor's shape as this can only be determined at runtime. */ 88 void configure_output_shape(); 89 90 // Inherited methods overridden: 91 void run(const Window &window, const ThreadInfo &info) override; 92 93 /** Function to use for in bounds crop for the particular tensor types passed to configure() */ 94 using InBoundsCropFunction = void(const ITensor *, const ITensor *, float *, Coordinates, int32_t, int32_t, int32_t, bool, bool); 95 96 private: 97 const ITensor *_input; 98 const ITensor *_crop_boxes; 99 const ITensor *_box_ind; 100 ITensor *_output; 101 102 Coordinates _start; 103 Coordinates _end; 104 uint32_t _crop_box_ind; 105 float _extrapolation_value; 106 /** The number of rows out of bounds at the start and end of output. */ 107 std::array<uint32_t, 2> _rows_out_of_bounds; 108 /** The number of columns out of bounds at the start and end of output. */ 109 std::array<uint32_t, 2> _cols_out_of_bounds; 110 }; 111 } // namespace arm_compute 112 #endif /*ARM_COMPUTE_NEON_CROP_KERNEL_H */ 113