Compute Library
 23.05
NEStridedSliceKernel.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_KERNEL_H
25 #define ARM_COMPUTE_NE_STRIDED_SLICE_KERNEL_H
26 
27 #include "arm_compute/core/Types.h"
29 
30 #include <cstdint>
31 
32 namespace arm_compute
33 {
34 // Forward declarations
35 class ITensor;
36 
37 /** Interface for the kernel to perform tensor strided slicing */
39 {
40 public:
41  const char *name() const override
42  {
43  return "NEStridedSliceKernel";
44  }
45  /** Default constructor */
47  /** Prevent instances of this class from being copied (As this class contains pointers) */
49  /** Prevent instances of this class from being copied (As this class contains pointers) */
51  /** Allow instances of this class to be moved */
53  /** Allow instances of this class to be moved */
55  /** Default destructor */
56  ~NEStridedSliceKernel() = default;
57  /** Configure kernel
58  *
59  * @note Supported tensor rank: up to 4
60  *
61  * @param[in] input Source tensor info. Data type supported: All
62  * @param[out] output Destination tensor info. Data type supported: Same as @p input
63  * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input).
64  * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input).
65  * @param[in] strides The strides of the dimensions of the input tensor to be sliced. The length must be of rank(input).
66  * @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.
67  * @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.
68  * @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.
69  * A slice of size 1 starting from starts[i] in the dimension must be preserved.
70  */
71  void configure(const ITensorInfo *input, ITensorInfo *output,
72  const Coordinates &starts, const Coordinates &ends, const BiStrides &strides,
73  int32_t begin_mask, int32_t end_mask, int32_t shrink_axis_mask);
74 
75  /** Static function to check if given info will lead to a valid configuration of @ref NEStridedSliceKernel
76  *
77  * @note Supported tensor rank: up to 4
78  *
79  * @param[in] input Source tensor info. Data type supported: All
80  * @param[in] output Destination tensor info. Data type supported: Same as @p input
81  * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input).
82  * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input).
83  * @param[in] strides The strides of the dimensions of the input tensor to be sliced. The length must be of rank(input).
84  * @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.
85  * @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.
86  * @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.
87  * A slice of size 1 starting from starts[i] in the dimension must be preserved.
88  */
89  static Status validate(const ITensorInfo *input, const ITensorInfo *output,
90  const Coordinates &starts, const Coordinates &ends, const BiStrides &strides,
91  int32_t begin_mask, int32_t end_mask, int32_t shrink_axis_mask);
92 
93  // Inherited methods overridden:
94  void run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) override;
95 
96 private:
97  Coordinates _starts_abs; /**< Absolute start coordinates */
98  Coordinates _final_strides; /**< Final strides */
99  int32_t _shrink_mask; /**< Shrink axis mask */
100 };
101 } // namespace arm_compute
102 #endif /*ARM_COMPUTE_NE_STRIDED_SLICE_KERNEL_H */
static Status validate(const ITensorInfo *input, const ITensorInfo *output, const Coordinates &starts, const Coordinates &ends, const BiStrides &strides, int32_t begin_mask, int32_t end_mask, int32_t shrink_axis_mask)
Static function to check if given info will lead to a valid configuration of NEStridedSliceKernel.
NEStridedSliceKernel & operator=(const NEStridedSliceKernel &)=delete
Prevent instances of this class from being copied (As this class contains pointers) ...
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
const char * name() const override
Name of the kernel.
Common interface for all kernels implemented in C++.
Definition: ICPPKernel.h:38
Store the tensor&#39;s metadata.
Definition: ITensorInfo.h:43
Status class.
Definition: Error.h:52
Copyright (c) 2017-2023 Arm Limited.
Coordinates of an item.
Definition: Coordinates.h:37
~NEStridedSliceKernel()=default
Default destructor.
Interface for the kernel to perform tensor strided slicing.
void run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) override
Execute the kernel on the passed window.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
Information about executing thread and CPU.
Definition: CPPTypes.h:180
NEStridedSliceKernel()
Default constructor.
Tensor packing service.
Definition: ITensorPack.h:39
void configure(const ITensorInfo *input, ITensorInfo *output, const Coordinates &starts, const Coordinates &ends, const BiStrides &strides, int32_t begin_mask, int32_t end_mask, int32_t shrink_axis_mask)
Configure kernel.
Describe a multidimensional execution window.
Definition: Window.h:39