Georgios Pinitas | c1a7245 | 2018-08-24 11:25:32 +0100 | [diff] [blame] | 1 | /* |
Sheri Zhang | a47dcc2 | 2021-04-22 14:41:12 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2021 Arm Limited. |
Georgios Pinitas | c1a7245 | 2018-08-24 11:25:32 +0100 | [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_CL_SLICE_H |
| 25 | #define ARM_COMPUTE_CL_SLICE_H |
Georgios Pinitas | c1a7245 | 2018-08-24 11:25:32 +0100 | [diff] [blame] | 26 | |
Michalis Spyrou | f20d6d6 | 2020-07-16 17:46:51 +0100 | [diff] [blame] | 27 | #include "arm_compute/runtime/CL/ICLOperator.h" |
| 28 | #include "arm_compute/runtime/IFunction.h" |
Georgios Pinitas | c1a7245 | 2018-08-24 11:25:32 +0100 | [diff] [blame] | 29 | |
| 30 | namespace arm_compute |
| 31 | { |
| 32 | // Forward Declarations |
| 33 | class ICLTensor; |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame] | 34 | class CLCompileContext; |
| 35 | class ITensorInfo; |
Georgios Pinitas | c1a7245 | 2018-08-24 11:25:32 +0100 | [diff] [blame] | 36 | |
Michalis Spyrou | f20d6d6 | 2020-07-16 17:46:51 +0100 | [diff] [blame] | 37 | /** Basic function to perform tensor slicing */ |
| 38 | class CLSlice : public IFunction |
| 39 | { |
| 40 | public: |
| 41 | /** Default Constructor */ |
| 42 | CLSlice(); |
| 43 | /** Default Destructor */ |
| 44 | ~CLSlice(); |
| 45 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 46 | CLSlice(const CLSlice &) = delete; |
| 47 | /** Default move constructor */ |
| 48 | CLSlice(CLSlice &&); |
| 49 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 50 | CLSlice &operator=(const CLSlice &) = delete; |
| 51 | /** Default move assignment operator */ |
| 52 | CLSlice &operator=(CLSlice &&); |
| 53 | /** Configure kernel |
| 54 | * |
Sheri Zhang | a47dcc2 | 2021-04-22 14:41:12 +0100 | [diff] [blame] | 55 | * Valid data layouts: |
| 56 | * - All |
| 57 | * |
| 58 | * Valid data type configurations: |
| 59 | * |src |dst | |
| 60 | * |:--------------|:--------------| |
| 61 | * |All |All | |
| 62 | * |
Michalis Spyrou | f20d6d6 | 2020-07-16 17:46:51 +0100 | [diff] [blame] | 63 | * @note Supported tensor rank: up to 4 |
| 64 | * @note Start indices must be non-negative. 0 <= starts[i] |
| 65 | * @note End coordinates can be negative, which represents the number of elements before the end of that dimension. |
| 66 | * @note End indices are not inclusive unless negative. |
| 67 | * |
Manuel Bottini | 8481d83 | 2019-12-10 15:28:40 +0000 | [diff] [blame] | 68 | * @param[in] input Source tensor. Data type supported: All. |
Georgios Pinitas | c1a7245 | 2018-08-24 11:25:32 +0100 | [diff] [blame] | 69 | * @param[out] output Destination tensor. Data type supported: Same as @p input |
| 70 | * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input). |
| 71 | * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input). |
| 72 | */ |
| 73 | void configure(const ICLTensor *input, ICLTensor *output, const Coordinates &starts, const Coordinates &ends); |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 74 | /** Configure kernel |
| 75 | * |
| 76 | * @note Supported tensor rank: up to 4 |
| 77 | * @note Start indices must be non-negative. 0 <= starts[i] |
| 78 | * @note End coordinates can be negative, which represents the number of elements before the end of that dimension. |
| 79 | * @note End indices are not inclusive unless negative. |
| 80 | * |
| 81 | * @param[in] compile_context The compile context to be used. |
| 82 | * @param[in] input Source tensor. Data type supported: All. |
| 83 | * @param[out] output Destination tensor. Data type supported: Same as @p input |
| 84 | * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input). |
| 85 | * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input). |
| 86 | */ |
| 87 | void configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output, const Coordinates &starts, const Coordinates &ends); |
Georgios Pinitas | c1a7245 | 2018-08-24 11:25:32 +0100 | [diff] [blame] | 88 | |
| 89 | /** Static function to check if given info will lead to a valid configuration of @ref CLSlice |
| 90 | * |
| 91 | * @note Supported tensor rank: up to 4 |
| 92 | * @note Start indices must be non-negative. 0 <= starts[i] |
| 93 | * @note End coordinates can be negative, which represents the number of elements before the end of that dimension. |
| 94 | * @note End indices are not inclusive unless negative. |
| 95 | * |
Manuel Bottini | 8481d83 | 2019-12-10 15:28:40 +0000 | [diff] [blame] | 96 | * @param[in] input Source tensor info. Data type supported: All. |
Georgios Pinitas | c1a7245 | 2018-08-24 11:25:32 +0100 | [diff] [blame] | 97 | * @param[in] output Destination tensor info. Data type supported: Same as @p input |
| 98 | * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input). |
| 99 | * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input). |
| 100 | * |
| 101 | * @return A status |
| 102 | */ |
| 103 | static Status validate(const ITensorInfo *input, const ITensorInfo *output, const Coordinates &starts, const Coordinates &ends); |
Michalis Spyrou | f20d6d6 | 2020-07-16 17:46:51 +0100 | [diff] [blame] | 104 | |
| 105 | // Inherited methods overridden: |
| 106 | void run() override; |
| 107 | |
| 108 | private: |
| 109 | struct Impl; |
| 110 | std::unique_ptr<Impl> _impl; |
Georgios Pinitas | c1a7245 | 2018-08-24 11:25:32 +0100 | [diff] [blame] | 111 | }; |
Georgios Pinitas | 856f66e | 2021-04-22 21:13:21 +0100 | [diff] [blame] | 112 | |
| 113 | namespace experimental |
| 114 | { |
| 115 | /** Basic function to perform tensor slicing */ |
| 116 | class CLSlice : public ICLOperator |
| 117 | { |
| 118 | public: |
| 119 | /** Configure kernel |
| 120 | * |
| 121 | * @note Supported tensor rank: up to 4 |
| 122 | * @note Start indices must be non-negative. 0 <= starts[i] |
| 123 | * @note End coordinates can be negative, which represents the number of elements before the end of that dimension. |
| 124 | * @note End indices are not inclusive unless negative. |
| 125 | * |
| 126 | * @param[in] compile_context The compile context to be used. |
| 127 | * @param[in] input Source tensor info. Data type supported: All. |
| 128 | * @param[out] output Destination tensor info. Data type supported: Same as @p input |
| 129 | * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input). |
| 130 | * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input). |
| 131 | */ |
| 132 | void configure(const CLCompileContext &compile_context, const ITensorInfo *input, ITensorInfo *output, const Coordinates &starts, const Coordinates &ends); |
| 133 | |
| 134 | /** Static function to check if given info will lead to a valid configuration of @ref CLSlice |
| 135 | * |
| 136 | * @note Supported tensor rank: up to 4 |
| 137 | * @note Start indices must be non-negative. 0 <= starts[i] |
| 138 | * @note End coordinates can be negative, which represents the number of elements before the end of that dimension. |
| 139 | * @note End indices are not inclusive unless negative. |
| 140 | * |
| 141 | * @param[in] input Source tensor info. Data type supported: All |
| 142 | * @param[in] output Destination tensor info. Data type supported: Same as @p input |
| 143 | * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input). |
| 144 | * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input). |
| 145 | * |
| 146 | * @return A status |
| 147 | */ |
| 148 | static Status validate(const ITensorInfo *input, const ITensorInfo *output, const Coordinates &starts, const Coordinates &ends); |
| 149 | }; |
| 150 | } // namespace experimental |
Georgios Pinitas | c1a7245 | 2018-08-24 11:25:32 +0100 | [diff] [blame] | 151 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 152 | #endif /* ARM_COMPUTE_CL_SLICE_H */ |