blob: da4a1b26e548721089e68fe95e1e9433082db851 [file] [log] [blame]
George Wort05398a92019-01-25 15:38:33 +00001/*
alerah0127619932021-11-24 17:21:43 +02002 * Copyright (c) 2019-2021 Arm Limited.
George Wort05398a92019-01-25 15:38:33 +00003 *
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_NEON_CROP_KERNEL_H
25#define ARM_COMPUTE_NEON_CROP_KERNEL_H
George Wort05398a92019-01-25 15:38:33 +000026
George Wort05398a92019-01-25 15:38:33 +000027#include "arm_compute/core/Types.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010028
Michalis Spyrouebcebf12020-10-21 00:04:14 +010029#include "src/core/NEON/INEKernel.h"
George Wort05398a92019-01-25 15:38:33 +000030
George Wort05398a92019-01-25 15:38:33 +000031namespace arm_compute
32{
33// Forward declarations
34class ITensor;
35
36/** Interface for the kernel to perform tensor cropping */
37class NECropKernel : public INEKernel
38{
39public:
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 *
Michele Di Giorgio17101332020-06-01 12:07:50 +010061 * @param[in] input Source tensor. Data type supported: U8/U16/S16/U32/S32/F16/F32. Data layouts supported: NHWC.
George Wort05398a92019-01-25 15:38:33 +000062 * @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 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010070 void configure(const ITensor *input,
71 const ITensor *crop_boxes,
72 const ITensor *box_ind,
73 ITensor *output,
74 uint32_t crop_box_ind = 0,
75 float extrapolation_value = 0);
George Wort05398a92019-01-25 15:38:33 +000076
77 /** Static function to check if given info will lead to a valid configuration of @ref CLStridedSliceKernel
78 *
79 * @note Supported tensor rank: up to 4
80 * @note Padding not supported.
81 *
Michele Di Giorgio17101332020-06-01 12:07:50 +010082 * @param[in] input Source tensor info. Data type supported: U8/U16/S16/U32/S32/F16/F32. Data layouts supported: NHWC.
George Wort05398a92019-01-25 15:38:33 +000083 * @param[in] crop_boxes Tensor info for tensor containing all possible boxes used to crop the image. Data type supported: F32
84 * @param[in] box_ind Tensor info for the one dimensional tensor mapping the @p crop_box_ind to the index of the 3D image
85 * in @p input. Data type supported: F32
86 * @param[in] output Destination tensor. Data type supported: F32
87 * @param[in] crop_box_ind Index of the crop box to be used from @p crop_boxes. Default is 0.
88 * @param[in] extrapolation_value Value to be used for values outside of the image. Default is 0.
89 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010090 static Status validate(const ITensorInfo *input,
91 const ITensorInfo *crop_boxes,
92 const ITensorInfo *box_ind,
93 const ITensorInfo *output,
94 uint32_t crop_box_ind = 0,
95 float extrapolation_value = 0);
George Wort05398a92019-01-25 15:38:33 +000096
97 /** Configure output tensor's shape as this can only be determined at runtime. */
98 void configure_output_shape();
99
100 // Inherited methods overridden:
101 void run(const Window &window, const ThreadInfo &info) override;
102
103 /** Function to use for in bounds crop for the particular tensor types passed to configure() */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100104 using InBoundsCropFunction =
105 void(const ITensor *, const ITensor *, float *, Coordinates, int32_t, int32_t, int32_t, bool, bool);
George Wort05398a92019-01-25 15:38:33 +0000106
107private:
108 const ITensor *_input;
109 const ITensor *_crop_boxes;
110 const ITensor *_box_ind;
111 ITensor *_output;
112
113 Coordinates _start;
114 Coordinates _end;
115 uint32_t _crop_box_ind;
116 float _extrapolation_value;
117 /** The number of rows out of bounds at the start and end of output. */
Michalis Spyroubcfd09a2019-05-01 13:03:59 +0100118 std::array<uint32_t, 2> _rows_out_of_bounds;
George Wort05398a92019-01-25 15:38:33 +0000119 /** The number of columns out of bounds at the start and end of output. */
Michalis Spyroubcfd09a2019-05-01 13:03:59 +0100120 std::array<uint32_t, 2> _cols_out_of_bounds;
George Wort05398a92019-01-25 15:38:33 +0000121};
122} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000123#endif /*ARM_COMPUTE_NEON_CROP_KERNEL_H */