blob: ba58ab1e581379f274b86bb3f8e90e8fef5c7acc [file] [log] [blame]
George Wort05398a92019-01-25 15:38:33 +00001/*
Michalis Spyroua1b8bab2020-05-07 12:13:44 +01002 * Copyright (c) 2019-2020 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
27#include "arm_compute/core/NEON/INEKernel.h"
28#include "arm_compute/core/Types.h"
29#include "arm_compute/core/Types.h"
30
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 */
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 *
Michele Di Giorgio17101332020-06-01 12:07:50 +010077 * @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 +000078 * @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() */
Michalis Spyroua1b8bab2020-05-07 12:13:44 +010094 using InBoundsCropFunction = void(const ITensor *, const ITensor *, float *, Coordinates, int32_t, int32_t, int32_t, bool, bool);
George Wort05398a92019-01-25 15:38:33 +000095
96private:
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. */
Michalis Spyroubcfd09a2019-05-01 13:03:59 +0100107 std::array<uint32_t, 2> _rows_out_of_bounds;
George Wort05398a92019-01-25 15:38:33 +0000108 /** The number of columns out of bounds at the start and end of output. */
Michalis Spyroubcfd09a2019-05-01 13:03:59 +0100109 std::array<uint32_t, 2> _cols_out_of_bounds;
George Wort05398a92019-01-25 15:38:33 +0000110
George Wort05398a92019-01-25 15:38:33 +0000111 NECropKernel::InBoundsCropFunction *_in_bounds_crop_function;
George Wort05398a92019-01-25 15:38:33 +0000112};
113} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000114#endif /*ARM_COMPUTE_NEON_CROP_KERNEL_H */