blob: 15ff0b9aaf65098856c3dccf3566ac89833b6a5b [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);
76
77 // Inherited methods overridden:
78 MemoryRequirements workspace() const override;
79};
80} // namespace experimental
81
82/** Basic function to run @ref NEStridedSliceKernel */
83class NEStridedSlice : public IFunction
84{
85public:
86 /** Default Constructor */
87 NEStridedSlice();
88 /** Default Destructor */
89 ~NEStridedSlice();
90 /** Prevent instances of this class from being copied (As this class contains pointers) */
91 NEStridedSlice(const NEStridedSlice &) = delete;
92 /** Default move constructor */
93 NEStridedSlice(NEStridedSlice &&);
94 /** Prevent instances of this class from being copied (As this class contains pointers) */
95 NEStridedSlice &operator=(const NEStridedSlice &) = delete;
96 /** Default move assignment operator */
97 NEStridedSlice &operator=(NEStridedSlice &&);
98
99 /** Configure kernel
100 *
101 * @note Supported tensor rank: up to 4
102 *
Georgios Pinitas33843562019-12-10 13:33:18 +0000103 * @param[in] input Source tensor. Data type supported: All
Georgios Pinitas6d9d6f42018-12-24 16:10:47 +0000104 * @param[out] output Destination tensor. Data type supported: Same as @p input
105 * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input).
106 * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input).
107 * @param[in] strides The strides of the dimensions of the input tensor to be sliced. The length must be of rank(input).
108 * @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.
109 * @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.
110 * @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.
111 * A slice of size 1 starting from starts[i] in the dimension must be preserved.
112 */
113 void configure(const ITensor *input, ITensor *output,
114 const Coordinates &starts, const Coordinates &ends, const BiStrides &strides,
115 int32_t begin_mask = 0, int32_t end_mask = 0, int32_t shrink_axis_mask = 0);
116
117 /** Static function to check if given info will lead to a valid configuration of @ref NEStridedSlice
118 *
119 * @note Supported tensor rank: up to 4
120 *
Georgios Pinitas33843562019-12-10 13:33:18 +0000121 * @param[in] input Source tensor info. Data type supported: All
Georgios Pinitas6d9d6f42018-12-24 16:10:47 +0000122 * @param[in] output Destination tensor info. Data type supported: Same as @p input
123 * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input).
124 * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input).
125 * @param[in] strides The strides of the dimensions of the input tensor to be sliced. The length must be of rank(input).
126 * @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.
127 * @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.
128 * @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.
129 * A slice of size 1 starting from starts[i] in the dimension must be preserved.
130 */
131 static Status validate(const ITensorInfo *input, const ITensorInfo *output,
132 const Coordinates &starts, const Coordinates &ends, const BiStrides &strides,
133 int32_t begin_mask = 0, int32_t end_mask = 0, int32_t shrink_axis_mask = 0);
Michalis Spyrou1732da82020-06-19 12:40:46 +0100134
135 // Inherited methods overridden:
136 void run() override;
137
138private:
139 struct Impl;
140 std::unique_ptr<Impl> _impl;
Georgios Pinitas6d9d6f42018-12-24 16:10:47 +0000141};
142} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000143#endif /* ARM_COMPUTE_NE_STRIDED_SLICE_H */