Georgios Pinitas | 6d9d6f4 | 2018-12-24 16:10:47 +0000 | [diff] [blame] | 1 | /* |
Sheri Zhang | a47dcc2 | 2021-04-22 14:41:12 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2021 Arm Limited. |
Georgios Pinitas | 6d9d6f4 | 2018-12-24 16:10:47 +0000 | [diff] [blame] | 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 | */ |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_NE_STRIDED_SLICE_H |
| 25 | #define ARM_COMPUTE_NE_STRIDED_SLICE_H |
Georgios Pinitas | 6d9d6f4 | 2018-12-24 16:10:47 +0000 | [diff] [blame] | 26 | |
Michalis Spyrou | 1732da8 | 2020-06-19 12:40:46 +0100 | [diff] [blame] | 27 | #include "arm_compute/runtime/IFunction.h" |
| 28 | #include "arm_compute/runtime/NEON/INEOperator.h" |
Georgios Pinitas | 6d9d6f4 | 2018-12-24 16:10:47 +0000 | [diff] [blame] | 29 | |
| 30 | namespace arm_compute |
| 31 | { |
| 32 | // Forward Declarations |
| 33 | class ITensor; |
| 34 | |
Michalis Spyrou | 1732da8 | 2020-06-19 12:40:46 +0100 | [diff] [blame] | 35 | namespace experimental |
| 36 | { |
Georgios Pinitas | 6d9d6f4 | 2018-12-24 16:10:47 +0000 | [diff] [blame] | 37 | /** Basic function to run @ref NEStridedSliceKernel */ |
Michalis Spyrou | 1732da8 | 2020-06-19 12:40:46 +0100 | [diff] [blame] | 38 | class NEStridedSlice : public INEOperator |
Georgios Pinitas | 6d9d6f4 | 2018-12-24 16:10:47 +0000 | [diff] [blame] | 39 | { |
| 40 | public: |
| 41 | /** Configure kernel |
| 42 | * |
| 43 | * @note Supported tensor rank: up to 4 |
| 44 | * |
Michalis Spyrou | 1732da8 | 2020-06-19 12:40:46 +0100 | [diff] [blame] | 45 | * @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 Spyrou | 1732da8 | 2020-06-19 12:40:46 +0100 | [diff] [blame] | 76 | }; |
| 77 | } // namespace experimental |
| 78 | |
| 79 | /** Basic function to run @ref NEStridedSliceKernel */ |
| 80 | class NEStridedSlice : public IFunction |
| 81 | { |
| 82 | public: |
| 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 | * |
Sheri Zhang | a47dcc2 | 2021-04-22 14:41:12 +0100 | [diff] [blame] | 98 | * Valid data layouts: |
| 99 | * - All |
| 100 | * |
| 101 | * Valid data type configurations: |
| 102 | * |src |dst | |
| 103 | * |:------|:------| |
| 104 | * |All |All | |
| 105 | * |
Michalis Spyrou | 1732da8 | 2020-06-19 12:40:46 +0100 | [diff] [blame] | 106 | * @note Supported tensor rank: up to 4 |
| 107 | * |
Georgios Pinitas | 3384356 | 2019-12-10 13:33:18 +0000 | [diff] [blame] | 108 | * @param[in] input Source tensor. Data type supported: All |
Georgios Pinitas | 6d9d6f4 | 2018-12-24 16:10:47 +0000 | [diff] [blame] | 109 | * @param[out] output Destination tensor. Data type supported: Same as @p input |
| 110 | * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input). |
| 111 | * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input). |
| 112 | * @param[in] strides The strides of the dimensions of the input tensor to be sliced. The length must be of rank(input). |
| 113 | * @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. |
| 114 | * @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. |
| 115 | * @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. |
| 116 | * A slice of size 1 starting from starts[i] in the dimension must be preserved. |
| 117 | */ |
| 118 | void configure(const ITensor *input, ITensor *output, |
| 119 | const Coordinates &starts, const Coordinates &ends, const BiStrides &strides, |
| 120 | int32_t begin_mask = 0, int32_t end_mask = 0, int32_t shrink_axis_mask = 0); |
| 121 | |
| 122 | /** Static function to check if given info will lead to a valid configuration of @ref NEStridedSlice |
| 123 | * |
| 124 | * @note Supported tensor rank: up to 4 |
| 125 | * |
Georgios Pinitas | 3384356 | 2019-12-10 13:33:18 +0000 | [diff] [blame] | 126 | * @param[in] input Source tensor info. Data type supported: All |
Georgios Pinitas | 6d9d6f4 | 2018-12-24 16:10:47 +0000 | [diff] [blame] | 127 | * @param[in] output Destination tensor info. Data type supported: Same as @p input |
| 128 | * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input). |
| 129 | * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input). |
| 130 | * @param[in] strides The strides of the dimensions of the input tensor to be sliced. The length must be of rank(input). |
| 131 | * @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. |
| 132 | * @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. |
| 133 | * @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. |
| 134 | * A slice of size 1 starting from starts[i] in the dimension must be preserved. |
| 135 | */ |
| 136 | static Status validate(const ITensorInfo *input, const ITensorInfo *output, |
| 137 | const Coordinates &starts, const Coordinates &ends, const BiStrides &strides, |
| 138 | int32_t begin_mask = 0, int32_t end_mask = 0, int32_t shrink_axis_mask = 0); |
Michalis Spyrou | 1732da8 | 2020-06-19 12:40:46 +0100 | [diff] [blame] | 139 | |
| 140 | // Inherited methods overridden: |
| 141 | void run() override; |
| 142 | |
| 143 | private: |
| 144 | struct Impl; |
| 145 | std::unique_ptr<Impl> _impl; |
Georgios Pinitas | 6d9d6f4 | 2018-12-24 16:10:47 +0000 | [diff] [blame] | 146 | }; |
| 147 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 148 | #endif /* ARM_COMPUTE_NE_STRIDED_SLICE_H */ |