• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2018-2020 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_CL_STRIDED_SLICE_H
25 #define ARM_COMPUTE_CL_STRIDED_SLICE_H
26 
27 #include "arm_compute/runtime/CL/CLRuntimeContext.h"
28 #include "arm_compute/runtime/CL/ICLOperator.h"
29 #include "arm_compute/runtime/IFunction.h"
30 
31 namespace arm_compute
32 {
33 // Forward Declarations
34 class ICLTensor;
35 
36 /** Basic function to run @ref CLStridedSliceKernel */
37 class CLStridedSlice : public IFunction
38 {
39 public:
40     /** 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 &&);
55     /** Configure kernel
56      *
57      * @note Supported tensor rank: up to 4
58      *
59      * @param[in]  input            Source tensor. Data type supported: All.
60      * @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);
72     /** 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);
90 
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      *
95      * @param[in] input            Source tensor. Data type supported: All.
96      * @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);
108 
109     // Inherited methods overridden:
110     void run() override;
111 
112 private:
113     struct Impl;
114     std::unique_ptr<Impl> _impl;
115 };
116 
117 namespace experimental
118 {
119 /** Basic function to run @ref CLStridedSliceKernel */
120 class CLStridedSlice : public ICLOperator
121 {
122 public:
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);
159 };
160 } // namespace experimental
161 } // namespace arm_compute
162 #endif /* ARM_COMPUTE_CL_STRIDED_SLICE_H */
163