blob: fdbef81f7dc8e1a890df38677572175c20332a41 [file] [log] [blame]
Georgios Pinitas77589b52018-08-21 14:41:35 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2018-2020 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 *
57 * @note Supported tensor rank: up to 4
58 *
Manuel Bottini8481d832019-12-10 15:28:40 +000059 * @param[in] input Source tensor. Data type supported: All.
Georgios Pinitas77589b52018-08-21 14:41:35 +010060 * @param[out] output Destination tensor. Data type supported: Same as @p input
61 * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input).
62 * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input).
63 * @param[in] strides The strides of the dimensions of the input tensor to be sliced. The length must be of rank(input).
64 * @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.
65 * @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.
66 * @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.
67 * A slice of size 1 starting from starts[i] in the dimension must be preserved.
68 */
69 void configure(const ICLTensor *input, ICLTensor *output,
70 const Coordinates &starts, const Coordinates &ends, const BiStrides &strides,
71 int32_t begin_mask = 0, int32_t end_mask = 0, int32_t shrink_axis_mask = 0);
Manuel Bottini2b84be52020-04-08 10:15:51 +010072 /** Configure kernel
73 *
74 * @note Supported tensor rank: up to 4
75 *
76 * @param[in] compile_context The compile context to be used.
77 * @param[in] input Source tensor. Data type supported: All.
78 * @param[out] output Destination tensor. Data type supported: Same as @p input
79 * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input).
80 * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input).
81 * @param[in] strides The strides of the dimensions of the input tensor to be sliced. The length must be of rank(input).
82 * @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.
83 * @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.
84 * @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.
85 * A slice of size 1 starting from starts[i] in the dimension must be preserved.
86 */
87 void configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output,
88 const Coordinates &starts, const Coordinates &ends, const BiStrides &strides,
89 int32_t begin_mask = 0, int32_t end_mask = 0, int32_t shrink_axis_mask = 0);
Georgios Pinitas77589b52018-08-21 14:41:35 +010090
91 /** Static function to check if given info will lead to a valid configuration of @ref CLStridedSlice
92 *
93 * @note Supported tensor rank: up to 4
94 *
Manuel Bottini8481d832019-12-10 15:28:40 +000095 * @param[in] input Source tensor. Data type supported: All.
Georgios Pinitas77589b52018-08-21 14:41:35 +010096 * @param[in] output Destination tensor. Data type supported: Same as @p input
97 * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input).
98 * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input).
99 * @param[in] strides The strides of the dimensions of the input tensor to be sliced. The length must be of rank(input).
100 * @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.
101 * @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.
102 * @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.
103 * A slice of size 1 starting from starts[i] in the dimension must be preserved.
104 */
105 static Status validate(const ITensorInfo *input, const ITensorInfo *output,
106 const Coordinates &starts, const Coordinates &ends, const BiStrides &strides,
107 int32_t begin_mask = 0, int32_t end_mask = 0, int32_t shrink_axis_mask = 0);
Michalis Spyrouf20d6d62020-07-16 17:46:51 +0100108
109 // Inherited methods overridden:
110 void run() override;
111
112private:
113 struct Impl;
114 std::unique_ptr<Impl> _impl;
Georgios Pinitas77589b52018-08-21 14:41:35 +0100115};
Michalis Spyrouf20d6d62020-07-16 17:46:51 +0100116
117namespace experimental
118{
119/** Basic function to run @ref CLStridedSliceKernel */
120class CLStridedSlice : public ICLOperator
121{
122public:
123 /** Configure kernel
124 *
125 * @note Supported tensor rank: up to 4
126 *
127 * @param[in] compile_context The compile context to be used.
128 * @param[in] input Source tensor info. Data type supported: All.
129 * @param[out] output Destination tensor info. Data type supported: Same as @p input
130 * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input).
131 * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input).
132 * @param[in] strides The strides of the dimensions of the input tensor to be sliced. The length must be of rank(input).
133 * @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.
134 * @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.
135 * @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.
136 * A slice of size 1 starting from starts[i] in the dimension must be preserved.
137 */
138 void configure(const CLCompileContext &compile_context, const ITensorInfo *input, ITensorInfo *output,
139 const Coordinates &starts, const Coordinates &ends, const BiStrides &strides,
140 int32_t begin_mask = 0, int32_t end_mask = 0, int32_t shrink_axis_mask = 0);
141
142 /** Static function to check if given info will lead to a valid configuration of @ref CLStridedSlice
143 *
144 * @note Supported tensor rank: up to 4
145 *
146 * @param[in] input Source tensor info. Data type supported: All.
147 * @param[in] output Destination tensor info. Data type supported: Same as @p input
148 * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input).
149 * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input).
150 * @param[in] strides The strides of the dimensions of the input tensor to be sliced. The length must be of rank(input).
151 * @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.
152 * @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.
153 * @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.
154 * A slice of size 1 starting from starts[i] in the dimension must be preserved.
155 */
156 static Status validate(const ITensorInfo *input, const ITensorInfo *output,
157 const Coordinates &starts, const Coordinates &ends, const BiStrides &strides,
158 int32_t begin_mask = 0, int32_t end_mask = 0, int32_t shrink_axis_mask = 0);
Michalis Spyrouf20d6d62020-07-16 17:46:51 +0100159};
160} // namespace experimental
Georgios Pinitas77589b52018-08-21 14:41:35 +0100161} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000162#endif /* ARM_COMPUTE_CL_STRIDED_SLICE_H */