blob: 7a7689c528a819e6b25b9f20c242b1551a481451 [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 +010037namespace experimental
38{
Georgios Pinitasc1a72452018-08-24 11:25:32 +010039/** Basic function to perform tensor slicing */
Michalis Spyrouf20d6d62020-07-16 17:46:51 +010040class CLSlice : public ICLOperator
Georgios Pinitasc1a72452018-08-24 11:25:32 +010041{
42public:
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 *
Michalis Spyrouf20d6d62020-07-16 17:46:51 +010050 * @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);
Michalis Spyrouf20d6d62020-07-16 17:46:51 +010073};
74} // namespace experimental
75
76/** Basic function to perform tensor slicing */
77class CLSlice : public IFunction
78{
79public:
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 *
Sheri Zhanga47dcc22021-04-22 14:41:12 +010094 * Valid data layouts:
95 * - All
96 *
97 * Valid data type configurations:
98 * |src |dst |
99 * |:--------------|:--------------|
100 * |All |All |
101 *
Michalis Spyrouf20d6d62020-07-16 17:46:51 +0100102 * @note Supported tensor rank: up to 4
103 * @note Start indices must be non-negative. 0 <= starts[i]
104 * @note End coordinates can be negative, which represents the number of elements before the end of that dimension.
105 * @note End indices are not inclusive unless negative.
106 *
Manuel Bottini8481d832019-12-10 15:28:40 +0000107 * @param[in] input Source tensor. Data type supported: All.
Georgios Pinitasc1a72452018-08-24 11:25:32 +0100108 * @param[out] output Destination tensor. Data type supported: Same as @p input
109 * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input).
110 * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input).
111 */
112 void configure(const ICLTensor *input, ICLTensor *output, const Coordinates &starts, const Coordinates &ends);
Manuel Bottini2b84be52020-04-08 10:15:51 +0100113 /** Configure kernel
114 *
115 * @note Supported tensor rank: up to 4
116 * @note Start indices must be non-negative. 0 <= starts[i]
117 * @note End coordinates can be negative, which represents the number of elements before the end of that dimension.
118 * @note End indices are not inclusive unless negative.
119 *
120 * @param[in] compile_context The compile context to be used.
121 * @param[in] input Source tensor. Data type supported: All.
122 * @param[out] output Destination tensor. Data type supported: Same as @p input
123 * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input).
124 * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input).
125 */
126 void configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output, const Coordinates &starts, const Coordinates &ends);
Georgios Pinitasc1a72452018-08-24 11:25:32 +0100127
128 /** Static function to check if given info will lead to a valid configuration of @ref CLSlice
129 *
130 * @note Supported tensor rank: up to 4
131 * @note Start indices must be non-negative. 0 <= starts[i]
132 * @note End coordinates can be negative, which represents the number of elements before the end of that dimension.
133 * @note End indices are not inclusive unless negative.
134 *
Manuel Bottini8481d832019-12-10 15:28:40 +0000135 * @param[in] input Source tensor info. Data type supported: All.
Georgios Pinitasc1a72452018-08-24 11:25:32 +0100136 * @param[in] output Destination tensor info. Data type supported: Same as @p input
137 * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input).
138 * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input).
139 *
140 * @return A status
141 */
142 static Status validate(const ITensorInfo *input, const ITensorInfo *output, const Coordinates &starts, const Coordinates &ends);
Michalis Spyrouf20d6d62020-07-16 17:46:51 +0100143
144 // Inherited methods overridden:
145 void run() override;
146
147private:
148 struct Impl;
149 std::unique_ptr<Impl> _impl;
Georgios Pinitasc1a72452018-08-24 11:25:32 +0100150};
151} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000152#endif /* ARM_COMPUTE_CL_SLICE_H */