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_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 namespace experimental 38 { 39 /** Basic function to perform tensor slicing */ 40 class CLSlice : public ICLOperator 41 { 42 public: 43 /** Configure kernel 44 * 45 * @note Supported tensor rank: up to 4 46 * @note Start indices must be non-negative. 0 <= starts[i] 47 * @note End coordinates can be negative, which represents the number of elements before the end of that dimension. 48 * @note End indices are not inclusive unless negative. 49 * 50 * @param[in] compile_context The compile context to be used. 51 * @param[in] input Source tensor info. Data type supported: All. 52 * @param[out] output Destination tensor info. Data type supported: Same as @p input 53 * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input). 54 * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input). 55 */ 56 void configure(const CLCompileContext &compile_context, const ITensorInfo *input, ITensorInfo *output, const Coordinates &starts, const Coordinates &ends); 57 58 /** Static function to check if given info will lead to a valid configuration of @ref CLSlice 59 * 60 * @note Supported tensor rank: up to 4 61 * @note Start indices must be non-negative. 0 <= starts[i] 62 * @note End coordinates can be negative, which represents the number of elements before the end of that dimension. 63 * @note End indices are not inclusive unless negative. 64 * 65 * @param[in] input Source tensor info. Data type supported: All 66 * @param[in] output Destination tensor info. Data type supported: Same as @p input 67 * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input). 68 * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input). 69 * 70 * @return A status 71 */ 72 static Status validate(const ITensorInfo *input, const ITensorInfo *output, const Coordinates &starts, const Coordinates &ends); 73 }; 74 } // namespace experimental 75 76 /** Basic function to perform tensor slicing */ 77 class CLSlice : public IFunction 78 { 79 public: 80 /** Default Constructor */ 81 CLSlice(); 82 /** Default Destructor */ 83 ~CLSlice(); 84 /** Prevent instances of this class from being copied (As this class contains pointers) */ 85 CLSlice(const CLSlice &) = delete; 86 /** Default move constructor */ 87 CLSlice(CLSlice &&); 88 /** Prevent instances of this class from being copied (As this class contains pointers) */ 89 CLSlice &operator=(const CLSlice &) = delete; 90 /** Default move assignment operator */ 91 CLSlice &operator=(CLSlice &&); 92 /** Configure kernel 93 * 94 * @note Supported tensor rank: up to 4 95 * @note Start indices must be non-negative. 0 <= starts[i] 96 * @note End coordinates can be negative, which represents the number of elements before the end of that dimension. 97 * @note End indices are not inclusive unless negative. 98 * 99 * @param[in] input Source tensor. Data type supported: All. 100 * @param[out] output Destination tensor. Data type supported: Same as @p input 101 * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input). 102 * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input). 103 */ 104 void configure(const ICLTensor *input, ICLTensor *output, const Coordinates &starts, const Coordinates &ends); 105 /** Configure kernel 106 * 107 * @note Supported tensor rank: up to 4 108 * @note Start indices must be non-negative. 0 <= starts[i] 109 * @note End coordinates can be negative, which represents the number of elements before the end of that dimension. 110 * @note End indices are not inclusive unless negative. 111 * 112 * @param[in] compile_context The compile context to be used. 113 * @param[in] input Source tensor. Data type supported: All. 114 * @param[out] output Destination tensor. Data type supported: Same as @p input 115 * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input). 116 * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input). 117 */ 118 void configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output, const Coordinates &starts, const Coordinates &ends); 119 120 /** Static function to check if given info will lead to a valid configuration of @ref CLSlice 121 * 122 * @note Supported tensor rank: up to 4 123 * @note Start indices must be non-negative. 0 <= starts[i] 124 * @note End coordinates can be negative, which represents the number of elements before the end of that dimension. 125 * @note End indices are not inclusive unless negative. 126 * 127 * @param[in] input Source tensor info. Data type supported: All. 128 * @param[in] 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 * @return A status 133 */ 134 static Status validate(const ITensorInfo *input, const ITensorInfo *output, const Coordinates &starts, const Coordinates &ends); 135 136 // Inherited methods overridden: 137 void run() override; 138 139 private: 140 struct Impl; 141 std::unique_ptr<Impl> _impl; 142 }; 143 } // namespace arm_compute 144 #endif /* ARM_COMPUTE_CL_SLICE_H */ 145