blob: 6fab0c01866b22bea491dd3a5464486180e039e0 [file] [log] [blame]
Georgios Pinitas77589b52018-08-21 14:41:35 +01001/*
Sheri Zhanga47dcc22021-04-22 14:41:12 +01002 * Copyright (c) 2018-2021 Arm Limited.
Georgios Pinitas77589b52018-08-21 14:41:35 +01003 *
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_CL_STRIDED_SLICE_H
25#define ARM_COMPUTE_CL_STRIDED_SLICE_H
Georgios Pinitas77589b52018-08-21 14:41:35 +010026
Michalis Spyrouf20d6d62020-07-16 17:46:51 +010027#include "arm_compute/runtime/CL/CLRuntimeContext.h"
28#include "arm_compute/runtime/CL/ICLOperator.h"
29#include "arm_compute/runtime/IFunction.h"
Georgios Pinitas77589b52018-08-21 14:41:35 +010030
31namespace arm_compute
32{
33// Forward Declarations
34class ICLTensor;
35
36/** Basic function to run @ref CLStridedSliceKernel */
Michalis Spyrouf20d6d62020-07-16 17:46:51 +010037class CLStridedSlice : public IFunction
Georgios Pinitas77589b52018-08-21 14:41:35 +010038{
39public:
Michalis Spyrouf20d6d62020-07-16 17:46:51 +010040 /** Constructor
41 *
42 * @param[in] ctx Runtime context to be used by the function
43 */
44 CLStridedSlice(CLRuntimeContext *ctx = nullptr);
45 /** Destructor */
46 ~CLStridedSlice();
47 /** Prevent instances of this class from being copied (As this class contains pointers) */
48 CLStridedSlice(const CLStridedSlice &) = delete;
49 /** Default move constructor */
50 CLStridedSlice(CLStridedSlice &&);
51 /** Prevent instances of this class from being copied (As this class contains pointers) */
52 CLStridedSlice &operator=(const CLStridedSlice &) = delete;
53 /** Default move assignment operator */
54 CLStridedSlice &operator=(CLStridedSlice &&);
Georgios Pinitas77589b52018-08-21 14:41:35 +010055 /** Configure kernel
56 *
Sheri Zhanga47dcc22021-04-22 14:41:12 +010057 * Valid data layouts:
58 * - All
59 *
60 * Valid data type configurations:
61 * |src |dst |
62 * |:--------------|:--------------|
63 * |All |All |
64 *
Georgios Pinitas77589b52018-08-21 14:41:35 +010065 * @note Supported tensor rank: up to 4
66 *
Manuel Bottini8481d832019-12-10 15:28:40 +000067 * @param[in] input Source tensor. Data type supported: All.
Georgios Pinitas77589b52018-08-21 14:41:35 +010068 * @param[out] output Destination tensor. Data type supported: Same as @p input
69 * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input).
70 * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input).
71 * @param[in] strides The strides of the dimensions of the input tensor to be sliced. The length must be of rank(input).
72 * @param[in] begin_mask (Optional) If the ith bit of begin_mask is set, starts[i] is ignored and the fullest possible range in that dimension is used instead.
73 * @param[in] end_mask (Optional) If the ith bit of end_mask is set, ends[i] is ignored and the fullest possible range in that dimension is used instead.
74 * @param[in] shrink_axis_mask (Optional) If the ith bit of shrink_axis_mask is set, it implies that the ith specification shrinks the dimensionality by 1.
75 * A slice of size 1 starting from starts[i] in the dimension must be preserved.
76 */
77 void configure(const ICLTensor *input, ICLTensor *output,
78 const Coordinates &starts, const Coordinates &ends, const BiStrides &strides,
79 int32_t begin_mask = 0, int32_t end_mask = 0, int32_t shrink_axis_mask = 0);
Manuel Bottini2b84be52020-04-08 10:15:51 +010080 /** Configure kernel
81 *
82 * @note Supported tensor rank: up to 4
83 *
84 * @param[in] compile_context The compile context to be used.
85 * @param[in] input Source tensor. Data type supported: All.
86 * @param[out] output Destination tensor. Data type supported: Same as @p input
87 * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input).
88 * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input).
89 * @param[in] strides The strides of the dimensions of the input tensor to be sliced. The length must be of rank(input).
90 * @param[in] begin_mask (Optional) If the ith bit of begin_mask is set, starts[i] is ignored and the fullest possible range in that dimension is used instead.
91 * @param[in] end_mask (Optional) If the ith bit of end_mask is set, ends[i] is ignored and the fullest possible range in that dimension is used instead.
92 * @param[in] shrink_axis_mask (Optional) If the ith bit of shrink_axis_mask is set, it implies that the ith specification shrinks the dimensionality by 1.
93 * A slice of size 1 starting from starts[i] in the dimension must be preserved.
94 */
95 void configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output,
96 const Coordinates &starts, const Coordinates &ends, const BiStrides &strides,
97 int32_t begin_mask = 0, int32_t end_mask = 0, int32_t shrink_axis_mask = 0);
Georgios Pinitas77589b52018-08-21 14:41:35 +010098
99 /** Static function to check if given info will lead to a valid configuration of @ref CLStridedSlice
100 *
101 * @note Supported tensor rank: up to 4
102 *
Manuel Bottini8481d832019-12-10 15:28:40 +0000103 * @param[in] input Source tensor. Data type supported: All.
Georgios Pinitas77589b52018-08-21 14:41:35 +0100104 * @param[in] output Destination tensor. Data type supported: Same as @p input
105 * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input).
106 * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input).
107 * @param[in] strides The strides of the dimensions of the input tensor to be sliced. The length must be of rank(input).
108 * @param[in] begin_mask (Optional) If the ith bit of begin_mask is set, starts[i] is ignored and the fullest possible range in that dimension is used instead.
109 * @param[in] end_mask (Optional) If the ith bit of end_mask is set, ends[i] is ignored and the fullest possible range in that dimension is used instead.
110 * @param[in] shrink_axis_mask (Optional) If the ith bit of shrink_axis_mask is set, it implies that the ith specification shrinks the dimensionality by 1.
111 * A slice of size 1 starting from starts[i] in the dimension must be preserved.
112 */
113 static Status validate(const ITensorInfo *input, const ITensorInfo *output,
114 const Coordinates &starts, const Coordinates &ends, const BiStrides &strides,
115 int32_t begin_mask = 0, int32_t end_mask = 0, int32_t shrink_axis_mask = 0);
Michalis Spyrouf20d6d62020-07-16 17:46:51 +0100116
117 // Inherited methods overridden:
118 void run() override;
119
120private:
121 struct Impl;
122 std::unique_ptr<Impl> _impl;
Georgios Pinitas77589b52018-08-21 14:41:35 +0100123};
Michalis Spyrouf20d6d62020-07-16 17:46:51 +0100124
125namespace experimental
126{
127/** Basic function to run @ref CLStridedSliceKernel */
128class CLStridedSlice : public ICLOperator
129{
130public:
131 /** Configure kernel
132 *
133 * @note Supported tensor rank: up to 4
134 *
135 * @param[in] compile_context The compile context to be used.
136 * @param[in] input Source tensor info. Data type supported: All.
137 * @param[out] output Destination tensor info. Data type supported: Same as @p input
138 * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input).
139 * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input).
140 * @param[in] strides The strides of the dimensions of the input tensor to be sliced. The length must be of rank(input).
141 * @param[in] begin_mask (Optional) If the ith bit of begin_mask is set, starts[i] is ignored and the fullest possible range in that dimension is used instead.
142 * @param[in] end_mask (Optional) If the ith bit of end_mask is set, ends[i] is ignored and the fullest possible range in that dimension is used instead.
143 * @param[in] shrink_axis_mask (Optional) If the ith bit of shrink_axis_mask is set, it implies that the ith specification shrinks the dimensionality by 1.
144 * A slice of size 1 starting from starts[i] in the dimension must be preserved.
145 */
146 void configure(const CLCompileContext &compile_context, const ITensorInfo *input, ITensorInfo *output,
147 const Coordinates &starts, const Coordinates &ends, const BiStrides &strides,
148 int32_t begin_mask = 0, int32_t end_mask = 0, int32_t shrink_axis_mask = 0);
149
150 /** Static function to check if given info will lead to a valid configuration of @ref CLStridedSlice
151 *
152 * @note Supported tensor rank: up to 4
153 *
154 * @param[in] input Source tensor info. Data type supported: All.
155 * @param[in] output Destination tensor info. Data type supported: Same as @p input
156 * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input).
157 * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input).
158 * @param[in] strides The strides of the dimensions of the input tensor to be sliced. The length must be of rank(input).
159 * @param[in] begin_mask (Optional) If the ith bit of begin_mask is set, starts[i] is ignored and the fullest possible range in that dimension is used instead.
160 * @param[in] end_mask (Optional) If the ith bit of end_mask is set, ends[i] is ignored and the fullest possible range in that dimension is used instead.
161 * @param[in] shrink_axis_mask (Optional) If the ith bit of shrink_axis_mask is set, it implies that the ith specification shrinks the dimensionality by 1.
162 * A slice of size 1 starting from starts[i] in the dimension must be preserved.
163 */
164 static Status validate(const ITensorInfo *input, const ITensorInfo *output,
165 const Coordinates &starts, const Coordinates &ends, const BiStrides &strides,
166 int32_t begin_mask = 0, int32_t end_mask = 0, int32_t shrink_axis_mask = 0);
Michalis Spyrouf20d6d62020-07-16 17:46:51 +0100167};
168} // namespace experimental
Georgios Pinitas77589b52018-08-21 14:41:35 +0100169} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000170#endif /* ARM_COMPUTE_CL_STRIDED_SLICE_H */