blob: ebe1b388789e88723e004435e5d84b3099164f07 [file] [log] [blame]
Georgios Pinitas77589b52018-08-21 14:41:35 +01001/*
Manuel Bottini8481d832019-12-10 15:28:40 +00002 * Copyright (c) 2018-2020 ARM Limited.
Georgios Pinitas77589b52018-08-21 14:41:35 +01003 *
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 Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_CL_STRIDED_SLICE_KERNEL_H
25#define ARM_COMPUTE_CL_STRIDED_SLICE_KERNEL_H
Georgios Pinitas77589b52018-08-21 14:41:35 +010026
27#include "arm_compute/core/CL/ICLKernel.h"
28#include "arm_compute/core/Types.h"
29
30#include <cstdint>
31
32namespace arm_compute
33{
34// Forward declarations
35class ICLTensor;
36
37/** Interface for the kernel to perform tensor strided slicing */
38class CLStridedSliceKernel : public ICLKernel
39{
40public:
41 /** Default constructor */
42 CLStridedSliceKernel();
43 /** Prevent instances of this class from being copied (As this class contains pointers) */
44 CLStridedSliceKernel(const CLStridedSliceKernel &) = delete;
45 /** Prevent instances of this class from being copied (As this class contains pointers) */
46 CLStridedSliceKernel &operator=(const CLStridedSliceKernel &) = delete;
47 /** Allow instances of this class to be moved */
48 CLStridedSliceKernel(CLStridedSliceKernel &&) = default;
49 /** Allow instances of this class to be moved */
50 CLStridedSliceKernel &operator=(CLStridedSliceKernel &&) = default;
51 /** Default destructor */
52 ~CLStridedSliceKernel() = default;
53 /** Configure kernel
54 *
55 * @note Supported tensor rank: up to 4
56 *
Manuel Bottini8481d832019-12-10 15:28:40 +000057 * @param[in] input Source tensor. Data type supported: All.
Georgios Pinitas77589b52018-08-21 14:41:35 +010058 * @param[out] output Destination tensor. Data type supported: Same as @p input
59 * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input).
60 * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input).
61 * @param[in] strides The strides of the dimensions of the input tensor to be sliced. The length must be of rank(input).
62 * @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.
63 * @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.
64 * @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.
65 * A slice of size 1 starting from starts[i] in the dimension must be preserved.
66 */
67 void configure(const ICLTensor *input, ICLTensor *output,
68 const Coordinates &starts, const Coordinates &ends, const BiStrides &strides,
69 int32_t begin_mask, int32_t end_mask, int32_t shrink_axis_mask);
Manuel Bottini4c6bd512020-04-08 10:15:51 +010070 /** Configure kernel
71 *
72 * @note Supported tensor rank: up to 4
73 *
74 * @param[in] compile_context The compile context to be used.
75 * @param[in] input Source tensor. Data type supported: All.
76 * @param[out] output Destination tensor. Data type supported: Same as @p input
77 * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input).
78 * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input).
79 * @param[in] strides The strides of the dimensions of the input tensor to be sliced. The length must be of rank(input).
80 * @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.
81 * @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.
82 * @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.
83 * A slice of size 1 starting from starts[i] in the dimension must be preserved.
84 */
Manuel Bottini2803f702020-04-21 16:20:03 +010085 void configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output,
Manuel Bottini4c6bd512020-04-08 10:15:51 +010086 const Coordinates &starts, const Coordinates &ends, const BiStrides &strides,
87 int32_t begin_mask, int32_t end_mask, int32_t shrink_axis_mask);
Georgios Pinitas77589b52018-08-21 14:41:35 +010088
89 /** Static function to check if given info will lead to a valid configuration of @ref CLStridedSliceKernel
90 *
91 * @note Supported tensor rank: up to 4
92 *
Manuel Bottini8481d832019-12-10 15:28:40 +000093 * @param[in] input Source tensor. Data type supported: All.
Georgios Pinitas77589b52018-08-21 14:41:35 +010094 * @param[in] output Destination tensor. Data type supported: Same as @p input
95 * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input).
96 * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input).
97 * @param[in] strides The strides of the dimensions of the input tensor to be sliced. The length must be of rank(input).
98 * @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.
99 * @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.
100 * @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.
101 * A slice of size 1 starting from starts[i] in the dimension must be preserved.
102 */
103 static Status validate(const ITensorInfo *input, const ITensorInfo *output,
104 const Coordinates &starts, const Coordinates &ends, const BiStrides &strides,
105 int32_t begin_mask, int32_t end_mask, int32_t shrink_axis_mask);
106
107 // Inherited methods overridden:
108 void run(const Window &window, cl::CommandQueue &queue) override;
109
110private:
111 const ICLTensor *_input; /**< Source tensor */
112 ICLTensor *_output; /**< Destination tensor */
113};
114} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000115#endif /*ARM_COMPUTE_CL_STRIDED_SLICE_KERNEL_H */