blob: f535c8ea97f28a3602f8d1b276e1c9073173dddf [file] [log] [blame]
Georgios Pinitase29acf12018-07-16 14:40:09 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2018-2020 Arm Limited.
Georgios Pinitase29acf12018-07-16 14:40:09 +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_CLCONCATENATELAYER_H
25#define ARM_COMPUTE_CLCONCATENATELAYER_H
Georgios Pinitase29acf12018-07-16 14:40:09 +010026
Michele Di Giorgiof932d2c2020-07-06 11:27:21 +010027#include "arm_compute/runtime/CL/ICLOperator.h"
Georgios Pinitase29acf12018-07-16 14:40:09 +010028#include "arm_compute/runtime/IFunction.h"
29
Georgios Pinitas09f24972019-05-17 18:14:40 +010030#include "arm_compute/core/CL/ICLKernel.h"
Georgios Pinitase29acf12018-07-16 14:40:09 +010031#include "arm_compute/core/Types.h"
32
33#include <memory>
34#include <vector>
35
36namespace arm_compute
37{
38// Forward declarations
39class ICLTensor;
40class ITensorInfo;
41class Status;
42
43/** Basic function to execute concatenate tensors along a given axis. This function calls the following kernels:
44 *
Georgios Pinitas09f24972019-05-17 18:14:40 +010045 * -# @ref CLWidthConcatenateLayerKernel (if underlying concatenation axis is 0).
Pablo Tello6a14adb2019-03-05 17:33:08 +000046 * -# @ref CLHeightConcatenateLayerKernel (if underlying concatenation axis is 1).
Georgios Pinitas09f24972019-05-17 18:14:40 +010047 * -# @ref CLDepthConcatenateLayerKernel (if underlying concatenation axis is 2).
Vidhya Sudhan Loganathan338595b2019-06-28 14:09:53 +010048 * -# @ref CLBatchConcatenateLayerKernel (if underlying concatenation axis is 3).
Georgios Pinitase29acf12018-07-16 14:40:09 +010049 */
50class CLConcatenateLayer : public IFunction
51{
52public:
53 /** Default constructor */
54 CLConcatenateLayer();
Michele Di Giorgiof932d2c2020-07-06 11:27:21 +010055 /** Destructor */
56 ~CLConcatenateLayer();
57 /** Prevent instances of this class from being copied (As this class contains pointers) */
58 CLConcatenateLayer(const CLConcatenateLayer &) = delete;
59 /** Default move constructor */
60 CLConcatenateLayer(CLConcatenateLayer &&);
61 /** Prevent instances of this class from being copied (As this class contains pointers) */
62 CLConcatenateLayer &operator=(const CLConcatenateLayer &) = delete;
63 /** Default move assignment operator */
64 CLConcatenateLayer &operator=(CLConcatenateLayer &&);
Georgios Pinitase29acf12018-07-16 14:40:09 +010065 /** Initialise the kernel's inputs vector and output.
66 *
67 * @note Input and output tensor dimensions preconditions defer depending on the concatenation axis.
Georgios Pinitas09f24972019-05-17 18:14:40 +010068 * @note Preconditions can be found respectively at @ref CLWidthConcatenateLayerKernel, @ref CLHeightConcatenateLayerKernel and @ref CLDepthConcatenateLayerKernel.
Georgios Pinitase29acf12018-07-16 14:40:09 +010069 *
Michele Di Giorgiof932d2c2020-07-06 11:27:21 +010070 * @param[in,out] inputs_vector The vectors containing all the tensors to concatenate. Data types supported: All
Georgios Pinitase29acf12018-07-16 14:40:09 +010071 * @param[out] output Output tensor. Data types supported: Same as @p input.
Vidhya Sudhan Loganathan338595b2019-06-28 14:09:53 +010072 * @param[in] axis Concatenation axis. Supported underlying concatenation axis are 0, 1, 2 and 3.
Georgios Pinitase29acf12018-07-16 14:40:09 +010073 */
Manuel Bottini10c53f12019-07-17 16:11:53 +010074 void configure(std::vector<const ICLTensor *> &inputs_vector, ICLTensor *output, size_t axis);
Manuel Bottini2b84be52020-04-08 10:15:51 +010075 /** Initialise the kernel's inputs vector and output.
76 *
77 * @note Input and output tensor dimensions preconditions defer depending on the concatenation axis.
78 * @note Preconditions can be found respectively at @ref CLWidthConcatenateLayerKernel, @ref CLHeightConcatenateLayerKernel and @ref CLDepthConcatenateLayerKernel.
79 *
80 * @param[in] compile_context The compile context to be used.
Michele Di Giorgiof932d2c2020-07-06 11:27:21 +010081 * @param[in,out] inputs_vector The vectors containing all the tensors to concatenate. Data types supported: All
Manuel Bottini2b84be52020-04-08 10:15:51 +010082 * @param[out] output Output tensor. Data types supported: Same as @p input.
83 * @param[in] axis Concatenation axis. Supported underlying concatenation axis are 0, 1, 2 and 3.
84 */
Manuel Bottini2b84be52020-04-08 10:15:51 +010085 void configure(const CLCompileContext &compile_context, std::vector<const ICLTensor *> &inputs_vector, ICLTensor *output, size_t axis);
Georgios Pinitase29acf12018-07-16 14:40:09 +010086 /** Static function to check if given info will lead to a valid configuration of @ref CLConcatenateLayer
87 *
88 * @note Input and output tensor dimensions preconditions defer depending on the concatenation axis.
Georgios Pinitas09f24972019-05-17 18:14:40 +010089 * @note Preconditions can be found respectively at @ref CLWidthConcatenateLayerKernel, @ref CLHeightConcatenateLayerKernel and @ref CLDepthConcatenateLayerKernel.
Georgios Pinitase29acf12018-07-16 14:40:09 +010090 *
Manuel Bottini8481d832019-12-10 15:28:40 +000091 * @param[in] inputs_vector The vectors containing all the tensors info to concatenate. Data types supported: All.
Georgios Pinitase29acf12018-07-16 14:40:09 +010092 * @param[in] output Output tensor info. Data types supported: Same as @p input.
Vidhya Sudhan Loganathan338595b2019-06-28 14:09:53 +010093 * @param[in] axis Concatenation axis. Supported underlying concatenation axis are 0, 1, 2 and 3.
Georgios Pinitase29acf12018-07-16 14:40:09 +010094 *
95 * @return a status
96 */
Manuel Bottini10c53f12019-07-17 16:11:53 +010097 static Status validate(const std::vector<const ITensorInfo *> &inputs_vector, const ITensorInfo *output, size_t axis);
Georgios Pinitase29acf12018-07-16 14:40:09 +010098
99 // Inherited methods overridden:
100 void run() override;
101
102private:
Michele Di Giorgiof932d2c2020-07-06 11:27:21 +0100103 struct Impl;
104 std::unique_ptr<Impl> _impl;
105};
Manuel Bottini10c53f12019-07-17 16:11:53 +0100106
Michele Di Giorgiof932d2c2020-07-06 11:27:21 +0100107namespace experimental
108{
109/** Basic function to execute concatenate tensors along a given axis. This function calls the following kernels:
110 *
111 * -# @ref CLWidthConcatenateLayerKernel (if underlying concatenation axis is 0).
112 * -# @ref CLHeightConcatenateLayerKernel (if underlying concatenation axis is 1).
113 * -# @ref CLDepthConcatenateLayerKernel (if underlying concatenation axis is 2).
114 * -# @ref CLBatchConcatenateLayerKernel (if underlying concatenation axis is 3).
115 */
Georgios Pinitas09cad722020-07-22 12:11:20 +0100116class CLConcatenation : public ICLOperator
Michele Di Giorgiof932d2c2020-07-06 11:27:21 +0100117{
118public:
119 /** Default constructor */
Georgios Pinitas09cad722020-07-22 12:11:20 +0100120 CLConcatenation();
Michele Di Giorgiof932d2c2020-07-06 11:27:21 +0100121 /** Initialise the kernel's inputs vector and output.
122 *
123 * @note Input and output tensor dimensions preconditions defer depending on the concatenation axis.
124 * @note Preconditions can be found respectively at @ref CLWidthConcatenateLayerKernel, @ref CLHeightConcatenateLayerKernel and @ref CLDepthConcatenateLayerKernel.
125 *
126 *
127 * @param[in] compile_context The compile context to be used.
128 * @param[in,out] inputs_vector The vectors containing all the tensors to concatenate. Data types supported: All
129 * @param[out] output Output tensor. Data types supported: Same as @p input.
130 * @param[in] axis Concatenation axis. Supported underlying concatenation axis are 0, 1, 2 and 3.
131 */
132 void configure(const CLCompileContext &compile_context, const std::vector<ITensorInfo *> &inputs_vector, ITensorInfo *output, size_t axis);
133 /** Static function to check if given info will lead to a valid configuration of @ref NEConcatenateLayer
134 *
135 * @note Input and output tensor dimensions preconditions defer depending on the concatenation axis.
136 * @note Preconditions can be found respectively at @ref CLWidthConcatenateLayerKernel, @ref CLHeightConcatenateLayerKernel and @ref CLDepthConcatenateLayerKernel.
137 *
138 * @param[in] inputs_vector The vectors containing all the tensors info to concatenate. Data types supported: All
139 * @param[in] output Output tensor info. Data types supported: Same as @p input.
140 * @param[in] axis Concatenation axis. Supported underlying concatenation axis are 0, 1, 2 and 3.
141 *
142 * @return a status
143 */
144 static Status validate(const std::vector<const ITensorInfo *> &inputs_vector, const ITensorInfo *output, size_t axis);
Manuel Bottini10c53f12019-07-17 16:11:53 +0100145
Michele Di Giorgiof932d2c2020-07-06 11:27:21 +0100146 // Inherited methods overridden:
Georgios Pinitas0499dff2020-07-31 22:21:38 +0100147 void run(ITensorPack &tensors) override;
Michele Di Giorgiof932d2c2020-07-06 11:27:21 +0100148
149private:
Michalis Spyrou8c571692019-04-05 11:29:52 +0100150 std::vector<std::unique_ptr<ICLKernel>> _concat_kernels;
151 unsigned int _num_inputs;
152 unsigned int _axis;
Georgios Pinitase29acf12018-07-16 14:40:09 +0100153};
Michele Di Giorgiof932d2c2020-07-06 11:27:21 +0100154} // namespace experimental
Georgios Pinitas9e4824c2019-04-12 13:15:58 +0100155} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000156#endif /* ARM_COMPUTE_CLCONCATENATELAYER_H */