blob: f9c94f530157b8fb994cd05638bb52397401f4ad [file] [log] [blame]
Georgios Pinitas6d9d6f42018-12-24 16:10:47 +00001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2018-2020 Arm Limited.
Georgios Pinitas6d9d6f42018-12-24 16:10:47 +00003 *
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_NE_STRIDED_SLICE_H
25#define ARM_COMPUTE_NE_STRIDED_SLICE_H
Georgios Pinitas6d9d6f42018-12-24 16:10:47 +000026
Michalis Spyrou1732da82020-06-19 12:40:46 +010027#include "arm_compute/runtime/IFunction.h"
28#include "arm_compute/runtime/NEON/INEOperator.h"
Georgios Pinitas6d9d6f42018-12-24 16:10:47 +000029
30namespace arm_compute
31{
32// Forward Declarations
33class ITensor;
34
Michalis Spyrou1732da82020-06-19 12:40:46 +010035namespace experimental
36{
Georgios Pinitas6d9d6f42018-12-24 16:10:47 +000037/** Basic function to run @ref NEStridedSliceKernel */
Michalis Spyrou1732da82020-06-19 12:40:46 +010038class NEStridedSlice : public INEOperator
Georgios Pinitas6d9d6f42018-12-24 16:10:47 +000039{
40public:
41 /** Configure kernel
42 *
43 * @note Supported tensor rank: up to 4
44 *
Michalis Spyrou1732da82020-06-19 12:40:46 +010045 * @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);
Michalis Spyrou1732da82020-06-19 12:40:46 +010076};
77} // namespace experimental
78
79/** Basic function to run @ref NEStridedSliceKernel */
80class NEStridedSlice : public IFunction
81{
82public:
83 /** Default Constructor */
84 NEStridedSlice();
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 */
90 NEStridedSlice(NEStridedSlice &&);
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 */
94 NEStridedSlice &operator=(NEStridedSlice &&);
95
96 /** Configure kernel
97 *
98 * @note Supported tensor rank: up to 4
99 *
Georgios Pinitas33843562019-12-10 13:33:18 +0000100 * @param[in] input Source tensor. Data type supported: All
Georgios Pinitas6d9d6f42018-12-24 16:10:47 +0000101 * @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 *
Georgios Pinitas33843562019-12-10 13:33:18 +0000118 * @param[in] input Source tensor info. Data type supported: All
Georgios Pinitas6d9d6f42018-12-24 16:10:47 +0000119 * @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);
Michalis Spyrou1732da82020-06-19 12:40:46 +0100131
132 // Inherited methods overridden:
133 void run() override;
134
135private:
136 struct Impl;
137 std::unique_ptr<Impl> _impl;
Georgios Pinitas6d9d6f42018-12-24 16:10:47 +0000138};
139} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000140#endif /* ARM_COMPUTE_NE_STRIDED_SLICE_H */