blob: a474215190df074547edb06cec663f3f2d1ba050 [file] [log] [blame]
George Wort894066d2019-02-15 15:12:52 +00001/*
Sheri Zhang7e20e292021-02-02 11:49:34 +00002 * Copyright (c) 2021 Arm Limited.
George Wort894066d2019-02-15 15:12:52 +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 */
Georgios Pinitas2eb5d162021-07-02 09:01:49 +010024#ifndef ARM_COMPUTE_CLCROP_H
25#define ARM_COMPUTE_CLCROP_H
George Wort894066d2019-02-15 15:12:52 +000026
George Wort894066d2019-02-15 15:12:52 +000027#include "arm_compute/core/Types.h"
Sheri Zhang7e20e292021-02-02 11:49:34 +000028#include "arm_compute/core/Window.h"
29#include "arm_compute/runtime/IFunction.h"
30#include <memory>
George Wort894066d2019-02-15 15:12:52 +000031
32namespace arm_compute
33{
Sheri Zhang7e20e292021-02-02 11:49:34 +000034class CLCompileContext;
George Wort894066d2019-02-15 15:12:52 +000035class ICLTensor;
Sheri Zhang7e20e292021-02-02 11:49:34 +000036class ITensorInfo;
George Wort894066d2019-02-15 15:12:52 +000037
Sheri Zhang7e20e292021-02-02 11:49:34 +000038/** Basic function to run @ref opencl::kernels::ClCropKernel */
39class CLCrop : public IFunction
George Wort894066d2019-02-15 15:12:52 +000040{
41public:
Sheri Zhang7e20e292021-02-02 11:49:34 +000042 /** 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
George Wort894066d2019-02-15 15:12:52 +000055 *
56 * @note Supported tensor rank: up to 4
57 *
Sheri Zhang6124ce62021-05-04 14:03:13 +010058 * Valid data layouts:
59 * - NHWC
60 *
61 * Valid data type configurations:
62 * |src |dst |
63 * |:--------------|:--------------|
64 * |All |F32 |
65 *
Michele Di Giorgio7d6b5772020-06-01 13:39:52 +010066 * @param[in] input Source tensor. Data type supported: All. Data layouts supported: NHWC.
George Wort894066d2019-02-15 15:12:52 +000067 * @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);
Sheri Zhang7e20e292021-02-02 11:49:34 +000075 /** Configure function
Manuel Bottini4c6bd512020-04-08 10:15:51 +010076 *
77 * @note Supported tensor rank: up to 4
78 *
79 * @param[in] compile_context The compile context to be used.
Michele Di Giorgio7d6b5772020-06-01 13:39:52 +010080 * @param[in] input Source tensor. Data type supported: All. Data layouts supported: NHWC.
Manuel Bottini4c6bd512020-04-08 10:15:51 +010081 * @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 */
Manuel Bottini256c0b92020-04-21 13:29:30 +010088 void configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output, Coordinates2D start, Coordinates2D end, uint32_t batch_index, float extrapolation_value = 0,
Manuel Bottini4c6bd512020-04-08 10:15:51 +010089 Window *output_window = nullptr);
George Wort894066d2019-02-15 15:12:52 +000090
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 *
Michele Di Giorgio7d6b5772020-06-01 13:39:52 +010095 * @param[in] input Source tensor info. Data type supported: All. Data layouts supported: NHWC.
George Wort894066d2019-02-15 15:12:52 +000096 * @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:
Sheri Zhang7e20e292021-02-02 11:49:34 +0000107 void run() override;
George Wort894066d2019-02-15 15:12:52 +0000108
109private:
Sheri Zhang7e20e292021-02-02 11:49:34 +0000110 struct Impl;
111 std::unique_ptr<Impl> _impl;
George Wort894066d2019-02-15 15:12:52 +0000112};
113} // namespace arm_compute
Georgios Pinitas2eb5d162021-07-02 09:01:49 +0100114#endif /*ARM_COMPUTE_CLCROP_H */