Debian Codegraph @

arm_compute/runtime/NEON/functions/NEStridedSlice.h

raw
1 /*
2 * Copyright (c) 2018-2021, 2024 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 ACL_ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NESTRIDEDSLICE_H
25 #define ACL_ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NESTRIDEDSLICE_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 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,
75 ITensor *output,
76 const Coordinates &starts,
77 const Coordinates &ends,
78 const BiStrides &strides,
79 int32_t begin_mask = 0,
80 int32_t end_mask = 0,
81 int32_t shrink_axis_mask = 0);
82
83 /** Static function to check if given info will lead to a valid configuration of @ref NEStridedSlice
84 *
85 * @note Supported tensor rank: up to 4
86 *
87 * @param[in] input Source tensor info. Data type supported: All
88 * @param[in] output Destination tensor info. Data type supported: Same as @p input
89 * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input).
90 * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input).
91 * @param[in] strides The strides of the dimensions of the input tensor to be sliced. The length must be of rank(input).
92 * @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.
93 * @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.
94 * @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.
95 * A slice of size 1 starting from starts[i] in the dimension must be preserved.
96 */
97 static Status validate(const ITensorInfo *input,
98 const ITensorInfo *output,
99 const Coordinates &starts,
100 const Coordinates &ends,
101 const BiStrides &strides,
102 int32_t begin_mask = 0,
103 int32_t end_mask = 0,
104 int32_t shrink_axis_mask = 0);
105
106 // Inherited methods overridden:
107 void run() override;
108
109 private:
110 struct Impl;
111 std::unique_ptr<Impl> _impl;
112 };
113
114 namespace experimental
115 {
116 /** Basic function to run NEStridedSliceKernel */
117 class NEStridedSlice : public INEOperator
118 {
119 public:
120 /** Configure kernel
121 *
122 * @note Supported tensor rank: up to 4
123 *
124 * @param[in] input Source tensor info. Data type supported: All
125 * @param[out] output Destination tensor info. Data type supported: Same as @p input
126 * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input).
127 * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input).
128 * @param[in] strides The strides of the dimensions of the input tensor to be sliced. The length must be of rank(input).
129 * @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.
130 * @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.
131 * @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.
132 * A slice of size 1 starting from starts[i] in the dimension must be preserved.
133 */
134 void configure(const ITensorInfo *input,
135 ITensorInfo *output,
136 const Coordinates &starts,
137 const Coordinates &ends,
138 const BiStrides &strides,
139 int32_t begin_mask = 0,
140 int32_t end_mask = 0,
141 int32_t shrink_axis_mask = 0);
142
143 /** Static function to check if given info will lead to a valid configuration of @ref NEStridedSlice
144 *
145 * @note Supported tensor rank: up to 4
146 *
147 * @param[in] input Source tensor info. Data type supported: All
148 * @param[in] output Destination tensor info. Data type supported: Same as @p input
149 * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input).
150 * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input).
151 * @param[in] strides The strides of the dimensions of the input tensor to be sliced. The length must be of rank(input).
152 * @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.
153 * @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.
154 * @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.
155 * A slice of size 1 starting from starts[i] in the dimension must be preserved.
156 */
157 static Status validate(const ITensorInfo *input,
158 const ITensorInfo *output,
159 const Coordinates &starts,
160 const Coordinates &ends,
161 const BiStrides &strides,
162 int32_t begin_mask = 0,
163 int32_t end_mask = 0,
164 int32_t shrink_axis_mask = 0);
165 };
166 } // namespace experimental
167 } // namespace arm_compute
168 #endif // ACL_ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NESTRIDEDSLICE_H