1 /* 2 * Copyright (c) 2018-2021 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_CL_SLICE_H 25 #define ARM_COMPUTE_CL_SLICE_H 26 27 #include "arm_compute/runtime/CL/ICLOperator.h" 28 #include "arm_compute/runtime/IFunction.h" 29 30 namespace arm_compute 31 { 32 // Forward Declarations 33 class ICLTensor; 34 class CLCompileContext; 35 class ITensorInfo; 36 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 * 55 * Valid data layouts: 56 * - All 57 * 58 * Valid data type configurations: 59 * |src |dst | 60 * |:--------------|:--------------| 61 * |All |All | 62 * 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 * 68 * @param[in] input Source tensor. Data type supported: All. 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); 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); 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 * 96 * @param[in] input Source tensor info. Data type supported: All. 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); 104 105 // Inherited methods overridden: 106 void run() override; 107 108 private: 109 struct Impl; 110 std::unique_ptr<Impl> _impl; 111 }; 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 151 } // namespace arm_compute 152 #endif /* ARM_COMPUTE_CL_SLICE_H */ 153