• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2018-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_NE_STRIDED_SLICE_H
25 #define ARM_COMPUTE_NE_STRIDED_SLICE_H
26 
27 #include "arm_compute/runtime/IFunction.h"
28 #include "arm_compute/runtime/NEON/INEOperator.h"
29 
30 namespace arm_compute
31 {
32 // Forward Declarations
33 class ITensor;
34 
35 /** Basic function to run @ref NEStridedSliceKernel */
36 class NEStridedSlice : public IFunction
37 {
38 public:
39     /** Default Constructor */
40     NEStridedSlice();
41     /** Default Destructor */
42     ~NEStridedSlice();
43     /** Prevent instances of this class from being copied (As this class contains pointers) */
44     NEStridedSlice(const NEStridedSlice &) = delete;
45     /** Default move constructor */
46     NEStridedSlice(NEStridedSlice &&);
47     /** Prevent instances of this class from being copied (As this class contains pointers) */
48     NEStridedSlice &operator=(const NEStridedSlice &) = delete;
49     /** Default move assignment operator */
50     NEStridedSlice &operator=(NEStridedSlice &&);
51 
52     /** Configure kernel
53      *
54      * Valid data layouts:
55      * - All
56      *
57      * Valid data type configurations:
58      * |src    |dst    |
59      * |:------|:------|
60      * |All    |All    |
61      *
62      * @note Supported tensor rank: up to 4
63      *
64      * @param[in]  input            Source tensor. Data type supported: All
65      * @param[out] output           Destination tensor. Data type supported: Same as @p input
66      * @param[in]  starts           The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input).
67      * @param[in]  ends             The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input).
68      * @param[in]  strides          The strides of the dimensions of the input tensor to be sliced. The length must be of rank(input).
69      * @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.
70      * @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.
71      * @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.
72      *                              A slice of size 1 starting from starts[i] in the dimension must be preserved.
73      */
74     void configure(const ITensor *input, ITensor *output,
75                    const Coordinates &starts, const Coordinates &ends, const BiStrides &strides,
76                    int32_t begin_mask = 0, int32_t end_mask = 0, int32_t shrink_axis_mask = 0);
77 
78     /** Static function to check if given info will lead to a valid configuration of @ref NEStridedSlice
79      *
80      * @note Supported tensor rank: up to 4
81      *
82      * @param[in] input            Source tensor info. Data type supported: All
83      * @param[in] output           Destination tensor info. Data type supported: Same as @p input
84      * @param[in] starts           The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input).
85      * @param[in] ends             The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input).
86      * @param[in] strides          The strides of the dimensions of the input tensor to be sliced. The length must be of rank(input).
87      * @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.
88      * @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.
89      * @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.
90      *                             A slice of size 1 starting from starts[i] in the dimension must be preserved.
91      */
92     static Status validate(const ITensorInfo *input, const ITensorInfo *output,
93                            const Coordinates &starts, const Coordinates &ends, const BiStrides &strides,
94                            int32_t begin_mask = 0, int32_t end_mask = 0, int32_t shrink_axis_mask = 0);
95 
96     // Inherited methods overridden:
97     void run() override;
98 
99 private:
100     struct Impl;
101     std::unique_ptr<Impl> _impl;
102 };
103 
104 namespace experimental
105 {
106 /** Basic function to run @ref NEStridedSliceKernel */
107 class NEStridedSlice : public INEOperator
108 {
109 public:
110     /** Configure kernel
111      *
112      * @note Supported tensor rank: up to 4
113      *
114      * @param[in]  input            Source tensor info. Data type supported: All
115      * @param[out] output           Destination tensor info. Data type supported: Same as @p input
116      * @param[in]  starts           The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input).
117      * @param[in]  ends             The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input).
118      * @param[in]  strides          The strides of the dimensions of the input tensor to be sliced. The length must be of rank(input).
119      * @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.
120      * @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.
121      * @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.
122      *                              A slice of size 1 starting from starts[i] in the dimension must be preserved.
123      */
124     void configure(const ITensorInfo *input, ITensorInfo *output,
125                    const Coordinates &starts, const Coordinates &ends, const BiStrides &strides,
126                    int32_t begin_mask = 0, int32_t end_mask = 0, int32_t shrink_axis_mask = 0);
127 
128     /** Static function to check if given info will lead to a valid configuration of @ref NEStridedSlice
129      *
130      * @note Supported tensor rank: up to 4
131      *
132      * @param[in] input            Source tensor info. Data type supported: All
133      * @param[in] output           Destination tensor info. Data type supported: Same as @p input
134      * @param[in] starts           The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input).
135      * @param[in] ends             The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input).
136      * @param[in] strides          The strides of the dimensions of the input tensor to be sliced. The length must be of rank(input).
137      * @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.
138      * @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.
139      * @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.
140      *                             A slice of size 1 starting from starts[i] in the dimension must be preserved.
141      */
142     static Status validate(const ITensorInfo *input, const ITensorInfo *output,
143                            const Coordinates &starts, const Coordinates &ends, const BiStrides &strides,
144                            int32_t begin_mask = 0, int32_t end_mask = 0, int32_t shrink_axis_mask = 0);
145 };
146 } // namespace experimental
147 } // namespace arm_compute
148 #endif /* ARM_COMPUTE_NE_STRIDED_SLICE_H */
149