xref: /aosp_15_r20/external/ComputeLibrary/arm_compute/runtime/CL/functions/CLCrop.h (revision c217d954acce2dbc11938adb493fc0abd69584f3)
1 /*
2  * Copyright (c) 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_CLCROP_H
25 #define ARM_COMPUTE_CLCROP_H
26 
27 #include "arm_compute/core/Types.h"
28 #include "arm_compute/core/Window.h"
29 #include "arm_compute/runtime/IFunction.h"
30 #include <memory>
31 
32 namespace arm_compute
33 {
34 class CLCompileContext;
35 class ICLTensor;
36 class ITensorInfo;
37 
38 /** Basic function to run @ref opencl::kernels::ClCropKernel */
39 class CLCrop : public IFunction
40 {
41 public:
42     /** Constructor */
43     CLCrop();
44     /** Destructor */
45     ~CLCrop();
46     /** Prevent instances of this class from being copied (As this class contains pointers) */
47     CLCrop(const CLCrop &) = delete;
48     /** Default move constructor */
49     CLCrop(CLCrop &&);
50     /** Prevent instances of this class from being copied (As this class contains pointers) */
51     CLCrop &operator=(const CLCrop &) = delete;
52     /** Default move assignment operator */
53     CLCrop &operator=(CLCrop &&);
54     /** Configure function
55      *
56      * @note Supported tensor rank: up to 4
57      *
58      * Valid data layouts:
59      * - NHWC
60      *
61      * Valid data type configurations:
62      * |src            |dst            |
63      * |:--------------|:--------------|
64      * |All            |F32            |
65      *
66      * @param[in]  input               Source tensor. Data type supported: All. Data layouts supported: NHWC.
67      * @param[out] output              Destination tensor. Data type supported: F32
68      * @param[in]  start               Coordinates of where to start cropping the image.
69      * @param[in]  end                 Coordinates of where to end cropping the image.
70      * @param[in]  batch_index         Fourth dimension index of the 3D image to crop in @p input.
71      * @param[in]  extrapolation_value Value to be used for values outside of the image. Default is 0.
72      * @param[in]  output_window       Output window to be used in case cropped image is being copied into a tensor. Default is nullptr.
73      */
74     void configure(const ICLTensor *input, ICLTensor *output, Coordinates2D start, Coordinates2D end, uint32_t batch_index, float extrapolation_value = 0, Window *output_window = nullptr);
75     /** Configure function
76      *
77      * @note Supported tensor rank: up to 4
78      *
79      * @param[in]  compile_context     The compile context to be used.
80      * @param[in]  input               Source tensor. Data type supported: All. Data layouts supported: NHWC.
81      * @param[out] output              Destination tensor. Data type supported: F32
82      * @param[in]  start               Coordinates of where to start cropping the image.
83      * @param[in]  end                 Coordinates of where to end cropping the image.
84      * @param[in]  batch_index         Fourth dimension index of the 3D image to crop in @p input.
85      * @param[in]  extrapolation_value Value to be used for values outside of the image. Default is 0.
86      * @param[in]  output_window       Output window to be used in case cropped image is being copied into a tensor. Default is nullptr.
87      */
88     void configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output, Coordinates2D start, Coordinates2D end, uint32_t batch_index, float extrapolation_value = 0,
89                    Window *output_window = nullptr);
90 
91     /** Static function to check if given info will lead to a valid configuration of @ref CLStridedSliceKernel
92      *
93      * @note Supported tensor rank: up to 4
94      *
95      * @param[in] input               Source tensor info. Data type supported: All. Data layouts supported: NHWC.
96      * @param[in] output              Destination tensor info. Data type supported: F32
97      * @param[in] start               Coordinates of where to start cropping the image.
98      * @param[in] end                 Coordinates of where to end cropping the image.
99      * @param[in] batch_index         Fourth dimension index of the 3D image to crop in @p input.
100      * @param[in] extrapolation_value Value to be used for values outside of the image. Default is 0.
101      * @param[in] output_window       Output window to be used in case cropped image is being copied into a tensor. Default is nullptr.
102      */
103     static Status validate(const ITensorInfo *input, const ITensorInfo *output, Coordinates2D start, Coordinates2D end, uint32_t batch_index, float extrapolation_value = 0,
104                            Window *output_window = nullptr);
105 
106     // Inherited methods overridden:
107     void run() override;
108 
109 private:
110     struct Impl;
111     std::unique_ptr<Impl> _impl;
112 };
113 } // namespace arm_compute
114 #endif /*ARM_COMPUTE_CLCROP_H */
115