blob: 297bcd86fed8563f73a00d04afa9a3191fb41e28 [file] [log] [blame]
Georgios Pinitasc1a72452018-08-24 11:25:32 +01001/*
Sheri Zhanga47dcc22021-04-22 14:41:12 +01002 * Copyright (c) 2018-2021 Arm Limited.
Georgios Pinitasc1a72452018-08-24 11:25:32 +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_SLICE_H
25#define ARM_COMPUTE_CL_SLICE_H
Georgios Pinitasc1a72452018-08-24 11:25:32 +010026
Michalis Spyrouf20d6d62020-07-16 17:46:51 +010027#include "arm_compute/runtime/CL/ICLOperator.h"
28#include "arm_compute/runtime/IFunction.h"
Georgios Pinitasc1a72452018-08-24 11:25:32 +010029
30namespace arm_compute
31{
32// Forward Declarations
33class ICLTensor;
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +010034class CLCompileContext;
35class ITensorInfo;
Georgios Pinitasc1a72452018-08-24 11:25:32 +010036
Michalis Spyrouf20d6d62020-07-16 17:46:51 +010037/** Basic function to perform tensor slicing */
38class CLSlice : public IFunction
39{
40public:
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 Zhanga47dcc22021-04-22 14:41:12 +010055 * Valid data layouts:
56 * - All
57 *
58 * Valid data type configurations:
59 * |src |dst |
60 * |:--------------|:--------------|
61 * |All |All |
62 *
Michalis Spyrouf20d6d62020-07-16 17:46:51 +010063 * @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 Bottini8481d832019-12-10 15:28:40 +000068 * @param[in] input Source tensor. Data type supported: All.
Georgios Pinitasc1a72452018-08-24 11:25:32 +010069 * @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 Bottini2b84be52020-04-08 10:15:51 +010074 /** 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 Pinitasc1a72452018-08-24 11:25:32 +010088
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 Bottini8481d832019-12-10 15:28:40 +000096 * @param[in] input Source tensor info. Data type supported: All.
Georgios Pinitasc1a72452018-08-24 11:25:32 +010097 * @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 Spyrouf20d6d62020-07-16 17:46:51 +0100104
105 // Inherited methods overridden:
106 void run() override;
107
108private:
109 struct Impl;
110 std::unique_ptr<Impl> _impl;
Georgios Pinitasc1a72452018-08-24 11:25:32 +0100111};
Georgios Pinitas856f66e2021-04-22 21:13:21 +0100112
113namespace experimental
114{
115/** Basic function to perform tensor slicing */
116class CLSlice : public ICLOperator
117{
118public:
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 Pinitasc1a72452018-08-24 11:25:32 +0100151} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000152#endif /* ARM_COMPUTE_CL_SLICE_H */