Compute Library
 21.02
NEStridedSlice.h
Go to the documentation of this file.
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_NE_STRIDED_SLICE_H
25 #define ARM_COMPUTE_NE_STRIDED_SLICE_H
26 
29 
30 namespace arm_compute
31 {
32 // Forward Declarations
33 class ITensor;
34 
35 namespace experimental
36 {
37 /** Basic function to run @ref NEStridedSliceKernel */
39 {
40 public:
41  /** Configure kernel
42  *
43  * @note Supported tensor rank: up to 4
44  *
45  * @param[in] input Source tensor info. Data type supported: All
46  * @param[out] output Destination tensor info. Data type supported: Same as @p input
47  * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input).
48  * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input).
49  * @param[in] strides The strides of the dimensions of the input tensor to be sliced. The length must be of rank(input).
50  * @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.
51  * @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.
52  * @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.
53  * A slice of size 1 starting from starts[i] in the dimension must be preserved.
54  */
55  void configure(const ITensorInfo *input, ITensorInfo *output,
56  const Coordinates &starts, const Coordinates &ends, const BiStrides &strides,
57  int32_t begin_mask = 0, int32_t end_mask = 0, int32_t shrink_axis_mask = 0);
58 
59  /** Static function to check if given info will lead to a valid configuration of @ref NEStridedSlice
60  *
61  * @note Supported tensor rank: up to 4
62  *
63  * @param[in] input Source tensor info. Data type supported: All
64  * @param[in] output Destination tensor info. Data type supported: Same as @p input
65  * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input).
66  * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input).
67  * @param[in] strides The strides of the dimensions of the input tensor to be sliced. The length must be of rank(input).
68  * @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.
69  * @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.
70  * @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.
71  * A slice of size 1 starting from starts[i] in the dimension must be preserved.
72  */
73  static Status validate(const ITensorInfo *input, const ITensorInfo *output,
74  const Coordinates &starts, const Coordinates &ends, const BiStrides &strides,
75  int32_t begin_mask = 0, int32_t end_mask = 0, int32_t shrink_axis_mask = 0);
76 };
77 } // namespace experimental
78 
79 /** Basic function to run @ref NEStridedSliceKernel */
80 class NEStridedSlice : public IFunction
81 {
82 public:
83  /** Default Constructor */
85  /** Default Destructor */
86  ~NEStridedSlice();
87  /** Prevent instances of this class from being copied (As this class contains pointers) */
88  NEStridedSlice(const NEStridedSlice &) = delete;
89  /** Default move constructor */
91  /** Prevent instances of this class from being copied (As this class contains pointers) */
92  NEStridedSlice &operator=(const NEStridedSlice &) = delete;
93  /** Default move assignment operator */
95 
96  /** Configure kernel
97  *
98  * @note Supported tensor rank: up to 4
99  *
100  * @param[in] input Source tensor. Data type supported: All
101  * @param[out] output Destination tensor. Data type supported: Same as @p input
102  * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input).
103  * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input).
104  * @param[in] strides The strides of the dimensions of the input tensor to be sliced. The length must be of rank(input).
105  * @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.
106  * @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.
107  * @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.
108  * A slice of size 1 starting from starts[i] in the dimension must be preserved.
109  */
110  void configure(const ITensor *input, ITensor *output,
111  const Coordinates &starts, const Coordinates &ends, const BiStrides &strides,
112  int32_t begin_mask = 0, int32_t end_mask = 0, int32_t shrink_axis_mask = 0);
113 
114  /** Static function to check if given info will lead to a valid configuration of @ref NEStridedSlice
115  *
116  * @note Supported tensor rank: up to 4
117  *
118  * @param[in] input Source tensor info. Data type supported: All
119  * @param[in] output Destination tensor info. Data type supported: Same as @p input
120  * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input).
121  * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input).
122  * @param[in] strides The strides of the dimensions of the input tensor to be sliced. The length must be of rank(input).
123  * @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.
124  * @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.
125  * @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.
126  * A slice of size 1 starting from starts[i] in the dimension must be preserved.
127  */
128  static Status validate(const ITensorInfo *input, const ITensorInfo *output,
129  const Coordinates &starts, const Coordinates &ends, const BiStrides &strides,
130  int32_t begin_mask = 0, int32_t end_mask = 0, int32_t shrink_axis_mask = 0);
131 
132  // Inherited methods overridden:
133  void run() override;
134 
135 private:
136  struct Impl;
137  std::unique_ptr<Impl> _impl;
138 };
139 } // namespace arm_compute
140 #endif /* ARM_COMPUTE_NE_STRIDED_SLICE_H */
Basic function to run NEStridedSliceKernel.
Base class for all functions.
Definition: IFunction.h:30
Basic interface for functions which have a single async Neon kernel.
Definition: INEOperator.h:41
Store the tensor&#39;s metadata.
Definition: ITensorInfo.h:40
Status class.
Definition: Error.h:52
static Status validate(const ITensorInfo *input, const ITensorInfo *output, const Coordinates &starts, const Coordinates &ends, const BiStrides &strides, int32_t begin_mask=0, int32_t end_mask=0, int32_t shrink_axis_mask=0)
Static function to check if given info will lead to a valid configuration of NEStridedSlice.
Interface for Neon tensor.
Definition: ITensor.h:36
Copyright (c) 2017-2021 Arm Limited.
Basic function to run NEStridedSliceKernel.
Coordinates of an item.
Definition: Coordinates.h:37
void run(ITensorPack &tensors) override
Run the kernels contained in the function.
Definition: INEOperator.cpp:40
INEOperator & operator=(const INEOperator &)=delete
Prevent instances of this class from being copied (As this class contains pointers) ...
void configure(const ITensorInfo *input, ITensorInfo *output, const Coordinates &starts, const Coordinates &ends, const BiStrides &strides, int32_t begin_mask=0, int32_t end_mask=0, int32_t shrink_axis_mask=0)
Configure kernel.