blob: a475f09a172419a60424bcb4e787a1c077ab763e [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_KERNEL_H
25#define ARM_COMPUTE_NE_STRIDED_SLICE_KERNEL_H
Georgios Pinitas6d9d6f42018-12-24 16:10:47 +000026
Georgios Pinitas6d9d6f42018-12-24 16:10:47 +000027#include "arm_compute/core/Types.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010028
Michalis Spyrouebcebf12020-10-21 00:04:14 +010029#include "src/core/NEON/INEKernel.h"
Georgios Pinitas6d9d6f42018-12-24 16:10:47 +000030
31#include <cstdint>
32
33namespace arm_compute
34{
35// Forward declarations
36class ITensor;
37
38/** Interface for the kernel to perform tensor strided slicing */
39class NEStridedSliceKernel : public INEKernel
40{
41public:
42 const char *name() const override
43 {
44 return "NEStridedSliceKernel";
45 }
46 /** Default constructor */
47 NEStridedSliceKernel();
48 /** Prevent instances of this class from being copied (As this class contains pointers) */
49 NEStridedSliceKernel(const NEStridedSliceKernel &) = delete;
50 /** Prevent instances of this class from being copied (As this class contains pointers) */
51 NEStridedSliceKernel &operator=(const NEStridedSliceKernel &) = delete;
52 /** Allow instances of this class to be moved */
53 NEStridedSliceKernel(NEStridedSliceKernel &&) = default;
54 /** Allow instances of this class to be moved */
55 NEStridedSliceKernel &operator=(NEStridedSliceKernel &&) = default;
56 /** Default destructor */
57 ~NEStridedSliceKernel() = default;
58 /** Configure kernel
59 *
60 * @note Supported tensor rank: up to 4
61 *
Michalis Spyrou1732da82020-06-19 12:40:46 +010062 * @param[in] input Source tensor info. Data type supported: All
63 * @param[out] output Destination tensor info. Data type supported: Same as @p input
Georgios Pinitas6d9d6f42018-12-24 16:10:47 +000064 * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input).
65 * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input).
66 * @param[in] strides The strides of the dimensions of the input tensor to be sliced. The length must be of rank(input).
67 * @param[in] begin_mask If the ith bit of begin_mask is set, starts[i] is ignored and the fullest possible range in that dimension is used instead.
68 * @param[in] end_mask If the ith bit of end_mask is set, ends[i] is ignored and the fullest possible range in that dimension is used instead.
69 * @param[in] shrink_axis_mask If the ith bit of shrink_axis_mask is set, it implies that the ith specification shrinks the dimensionality by 1.
70 * A slice of size 1 starting from starts[i] in the dimension must be preserved.
71 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010072 void configure(const ITensorInfo *input,
73 ITensorInfo *output,
74 const Coordinates &starts,
75 const Coordinates &ends,
76 const BiStrides &strides,
77 int32_t begin_mask,
78 int32_t end_mask,
79 int32_t shrink_axis_mask);
Georgios Pinitas6d9d6f42018-12-24 16:10:47 +000080
Georgios Pinitas33843562019-12-10 13:33:18 +000081 /** Static function to check if given info will lead to a valid configuration of @ref NEStridedSliceKernel
Georgios Pinitas6d9d6f42018-12-24 16:10:47 +000082 *
83 * @note Supported tensor rank: up to 4
84 *
Georgios Pinitas33843562019-12-10 13:33:18 +000085 * @param[in] input Source tensor info. Data type supported: All
Georgios Pinitas6d9d6f42018-12-24 16:10:47 +000086 * @param[in] output Destination tensor info. Data type supported: Same as @p input
87 * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input).
88 * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input).
89 * @param[in] strides The strides of the dimensions of the input tensor to be sliced. The length must be of rank(input).
90 * @param[in] begin_mask If the ith bit of begin_mask is set, starts[i] is ignored and the fullest possible range in that dimension is used instead.
91 * @param[in] end_mask If the ith bit of end_mask is set, ends[i] is ignored and the fullest possible range in that dimension is used instead.
92 * @param[in] shrink_axis_mask If the ith bit of shrink_axis_mask is set, it implies that the ith specification shrinks the dimensionality by 1.
93 * A slice of size 1 starting from starts[i] in the dimension must be preserved.
94 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010095 static Status validate(const ITensorInfo *input,
96 const ITensorInfo *output,
97 const Coordinates &starts,
98 const Coordinates &ends,
99 const BiStrides &strides,
100 int32_t begin_mask,
101 int32_t end_mask,
102 int32_t shrink_axis_mask);
Georgios Pinitas6d9d6f42018-12-24 16:10:47 +0000103
104 // Inherited methods overridden:
Georgios Pinitas0499dff2020-07-31 22:21:38 +0100105 void run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) override;
Georgios Pinitas6d9d6f42018-12-24 16:10:47 +0000106
107private:
Michalis Spyrou1732da82020-06-19 12:40:46 +0100108 Coordinates _starts_abs; /**< Absolute start coordinates */
109 Coordinates _final_strides; /**< Final strides */
110 int32_t _shrink_mask; /**< Shrink axis mask */
Georgios Pinitas6d9d6f42018-12-24 16:10:47 +0000111};
112} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000113#endif /*ARM_COMPUTE_NE_STRIDED_SLICE_KERNEL_H */