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_STRIDED_SLICE_KERNEL_H 25 #define ARM_COMPUTE_CL_STRIDED_SLICE_KERNEL_H 26 27 #include "arm_compute/core/Types.h" 28 #include "src/core/CL/ICLKernel.h" 29 30 #include <cstdint> 31 32 namespace arm_compute 33 { 34 /** Interface for the kernel to perform tensor strided slicing */ 35 class CLStridedSliceKernel : public ICLKernel 36 { 37 public: 38 /** Default constructor */ 39 CLStridedSliceKernel(); 40 41 /** Configure kernel 42 * 43 * @note Supported tensor rank: up to 4 44 * 45 * @param[in] compile_context The compile context to be used. 46 * @param[in] input Source tensor info. Data type supported: All. 47 * @param[out] output Destination tensor info. Data type supported: Same as @p input 48 * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input). 49 * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input). 50 * @param[in] strides The strides of the dimensions of the input tensor to be sliced. The length must be of rank(input). 51 * @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. 52 * @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. 53 * @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. 54 * A slice of size 1 starting from starts[i] in the dimension must be preserved. 55 */ 56 void configure(const CLCompileContext &compile_context, const ITensorInfo *input, ITensorInfo *output, 57 const Coordinates &starts, const Coordinates &ends, const BiStrides &strides, 58 int32_t begin_mask, int32_t end_mask, int32_t shrink_axis_mask); 59 60 /** Static function to check if given info will lead to a valid configuration of @ref CLStridedSliceKernel 61 * 62 * @note Supported tensor rank: up to 4 63 * 64 * @param[in] input Source tensor. Data type supported: All. 65 * @param[in] output Destination tensor. Data type supported: Same as @p input 66 * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input). 67 * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input). 68 * @param[in] strides The strides of the dimensions of the input tensor to be sliced. The length must be of rank(input). 69 * @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. 70 * @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. 71 * @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. 72 * A slice of size 1 starting from starts[i] in the dimension must be preserved. 73 */ 74 static Status validate(const ITensorInfo *input, const ITensorInfo *output, 75 const Coordinates &starts, const Coordinates &ends, const BiStrides &strides, 76 int32_t begin_mask, int32_t end_mask, int32_t shrink_axis_mask); 77 78 // Inherited methods overridden: 79 void run_op(ITensorPack &tensors, const Window &window, cl::CommandQueue &queue) override; 80 }; 81 } // namespace arm_compute 82 #endif /*ARM_COMPUTE_CL_STRIDED_SLICE_KERNEL_H */ 83