blob: 23c398cb41b548b72757aef4df3613f6bb030e72 [file] [log] [blame]
Georgios Pinitasc1a72452018-08-24 11:25:32 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2018-2020 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;
34
Michalis Spyrouf20d6d62020-07-16 17:46:51 +010035namespace experimental
36{
Georgios Pinitasc1a72452018-08-24 11:25:32 +010037/** Basic function to perform tensor slicing */
Michalis Spyrouf20d6d62020-07-16 17:46:51 +010038class CLSlice : public ICLOperator
Georgios Pinitasc1a72452018-08-24 11:25:32 +010039{
40public:
41 /** Configure kernel
42 *
43 * @note Supported tensor rank: up to 4
44 * @note Start indices must be non-negative. 0 <= starts[i]
45 * @note End coordinates can be negative, which represents the number of elements before the end of that dimension.
46 * @note End indices are not inclusive unless negative.
47 *
Michalis Spyrouf20d6d62020-07-16 17:46:51 +010048 * @param[in] compile_context The compile context to be used.
49 * @param[in] input Source tensor info. Data type supported: All.
50 * @param[out] output Destination tensor info. Data type supported: Same as @p input
51 * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input).
52 * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input).
53 */
54 void configure(const CLCompileContext &compile_context, const ITensorInfo *input, ITensorInfo *output, const Coordinates &starts, const Coordinates &ends);
55
56 /** Static function to check if given info will lead to a valid configuration of @ref CLSlice
57 *
58 * @note Supported tensor rank: up to 4
59 * @note Start indices must be non-negative. 0 <= starts[i]
60 * @note End coordinates can be negative, which represents the number of elements before the end of that dimension.
61 * @note End indices are not inclusive unless negative.
62 *
63 * @param[in] input Source tensor info. Data type supported: All
64 * @param[in] output Destination tensor info. Data type supported: Same as @p input
65 * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input).
66 * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input).
67 *
68 * @return A status
69 */
70 static Status validate(const ITensorInfo *input, const ITensorInfo *output, const Coordinates &starts, const Coordinates &ends);
Michalis Spyrouf20d6d62020-07-16 17:46:51 +010071};
72} // namespace experimental
73
74/** Basic function to perform tensor slicing */
75class CLSlice : public IFunction
76{
77public:
78 /** Default Constructor */
79 CLSlice();
80 /** Default Destructor */
81 ~CLSlice();
82 /** Prevent instances of this class from being copied (As this class contains pointers) */
83 CLSlice(const CLSlice &) = delete;
84 /** Default move constructor */
85 CLSlice(CLSlice &&);
86 /** Prevent instances of this class from being copied (As this class contains pointers) */
87 CLSlice &operator=(const CLSlice &) = delete;
88 /** Default move assignment operator */
89 CLSlice &operator=(CLSlice &&);
90 /** Configure kernel
91 *
92 * @note Supported tensor rank: up to 4
93 * @note Start indices must be non-negative. 0 <= starts[i]
94 * @note End coordinates can be negative, which represents the number of elements before the end of that dimension.
95 * @note End indices are not inclusive unless negative.
96 *
Manuel Bottini8481d832019-12-10 15:28:40 +000097 * @param[in] input Source tensor. Data type supported: All.
Georgios Pinitasc1a72452018-08-24 11:25:32 +010098 * @param[out] output Destination tensor. Data type supported: Same as @p input
99 * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input).
100 * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input).
101 */
102 void configure(const ICLTensor *input, ICLTensor *output, const Coordinates &starts, const Coordinates &ends);
Manuel Bottini2b84be52020-04-08 10:15:51 +0100103 /** Configure kernel
104 *
105 * @note Supported tensor rank: up to 4
106 * @note Start indices must be non-negative. 0 <= starts[i]
107 * @note End coordinates can be negative, which represents the number of elements before the end of that dimension.
108 * @note End indices are not inclusive unless negative.
109 *
110 * @param[in] compile_context The compile context to be used.
111 * @param[in] input Source tensor. Data type supported: All.
112 * @param[out] output Destination tensor. Data type supported: Same as @p input
113 * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input).
114 * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input).
115 */
116 void configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output, const Coordinates &starts, const Coordinates &ends);
Georgios Pinitasc1a72452018-08-24 11:25:32 +0100117
118 /** Static function to check if given info will lead to a valid configuration of @ref CLSlice
119 *
120 * @note Supported tensor rank: up to 4
121 * @note Start indices must be non-negative. 0 <= starts[i]
122 * @note End coordinates can be negative, which represents the number of elements before the end of that dimension.
123 * @note End indices are not inclusive unless negative.
124 *
Manuel Bottini8481d832019-12-10 15:28:40 +0000125 * @param[in] input Source tensor info. Data type supported: All.
Georgios Pinitasc1a72452018-08-24 11:25:32 +0100126 * @param[in] output Destination tensor info. Data type supported: Same as @p input
127 * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input).
128 * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input).
129 *
130 * @return A status
131 */
132 static Status validate(const ITensorInfo *input, const ITensorInfo *output, const Coordinates &starts, const Coordinates &ends);
Michalis Spyrouf20d6d62020-07-16 17:46:51 +0100133
134 // Inherited methods overridden:
135 void run() override;
136
137private:
138 struct Impl;
139 std::unique_ptr<Impl> _impl;
Georgios Pinitasc1a72452018-08-24 11:25:32 +0100140};
141} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000142#endif /* ARM_COMPUTE_CL_SLICE_H */