blob: 71e84e21b5c3cf98dab3579bfae0ef55f95a4227 [file] [log] [blame]
Georgios Pinitase29acf12018-07-16 14:40:09 +01001/*
Michele Di Giorgio7d61ff02021-01-18 21:15:59 +00002 * Copyright (c) 2018-2021 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
27#include "arm_compute/runtime/IFunction.h"
28
29#include "arm_compute/core/Types.h"
30
31#include <memory>
32#include <vector>
33
34namespace arm_compute
35{
36// Forward declarations
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +010037class CLCompileContext;
Georgios Pinitase29acf12018-07-16 14:40:09 +010038class ICLTensor;
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +010039class ICLKernel;
Georgios Pinitase29acf12018-07-16 14:40:09 +010040class ITensorInfo;
41class Status;
42
43/** Basic function to execute concatenate tensors along a given axis. This function calls the following kernels:
44 *
Michele Di Giorgio7d61ff02021-01-18 21:15:59 +000045 * -# @ref opencl::kernels::ClWidthConcatenateKernel (if underlying concatenation axis is 0).
46 * -# @ref opencl::kernels::ClHeightConcatenateKernel (if underlying concatenation axis is 1).
47 * -# @ref opencl::kernels::ClDepthConcatenateKernel (if underlying concatenation axis is 2).
48 * -# @ref opencl::kernels::ClBatchConcatenateKernel (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 *
Sheri Zhanga47dcc22021-04-22 14:41:12 +010067 * Valid data layouts:
68 * - All
69 *
70 * Valid data type configurations:
71 * |src |dst |
72 * |:--------------|:--------------|
73 * |QASYMM8 |QASYMM8 |
74 * |QASYMM8_SIGNED |QASYMM8_SIGNED |
75 * |F16 |F16 |
76 * |F32 |F32 |
77 *
Georgios Pinitase29acf12018-07-16 14:40:09 +010078 * @note Input and output tensor dimensions preconditions defer depending on the concatenation axis.
Michele Di Giorgio7d61ff02021-01-18 21:15:59 +000079 * @note Preconditions can be found respectively at @ref opencl::kernels::ClWidthConcatenateKernel,
80 * @ref opencl::kernels::ClHeightConcatenateKernel and @ref opencl::kernels::ClDepthConcatenateKernel.
Georgios Pinitase29acf12018-07-16 14:40:09 +010081 *
Sheri Zhanga47dcc22021-04-22 14:41:12 +010082 * @param[in,out] inputs_vector The vectors containing all the tensors to concatenate. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32.
Georgios Pinitase29acf12018-07-16 14:40:09 +010083 * @param[out] output Output tensor. Data types supported: Same as @p input.
Vidhya Sudhan Loganathan338595b2019-06-28 14:09:53 +010084 * @param[in] axis Concatenation axis. Supported underlying concatenation axis are 0, 1, 2 and 3.
Georgios Pinitase29acf12018-07-16 14:40:09 +010085 */
Manuel Bottini10c53f12019-07-17 16:11:53 +010086 void configure(std::vector<const ICLTensor *> &inputs_vector, ICLTensor *output, size_t axis);
Manuel Bottini2b84be52020-04-08 10:15:51 +010087 /** Initialise the kernel's inputs vector and output.
88 *
89 * @note Input and output tensor dimensions preconditions defer depending on the concatenation axis.
Michele Di Giorgio7d61ff02021-01-18 21:15:59 +000090 * @note Preconditions can be found respectively at @ref opencl::kernels::ClWidthConcatenateKernel,
91 * @ref opencl::kernels::ClHeightConcatenateKernel and @ref opencl::kernels::ClDepthConcatenateKernel.
Manuel Bottini2b84be52020-04-08 10:15:51 +010092 *
93 * @param[in] compile_context The compile context to be used.
Sheri Zhanga47dcc22021-04-22 14:41:12 +010094 * @param[in,out] inputs_vector The vectors containing all the tensors to concatenate. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32.
Manuel Bottini2b84be52020-04-08 10:15:51 +010095 * @param[out] output Output tensor. Data types supported: Same as @p input.
96 * @param[in] axis Concatenation axis. Supported underlying concatenation axis are 0, 1, 2 and 3.
97 */
Manuel Bottini2b84be52020-04-08 10:15:51 +010098 void configure(const CLCompileContext &compile_context, std::vector<const ICLTensor *> &inputs_vector, ICLTensor *output, size_t axis);
Georgios Pinitase29acf12018-07-16 14:40:09 +010099 /** Static function to check if given info will lead to a valid configuration of @ref CLConcatenateLayer
100 *
101 * @note Input and output tensor dimensions preconditions defer depending on the concatenation axis.
Michele Di Giorgio7d61ff02021-01-18 21:15:59 +0000102 * @note Preconditions can be found respectively at @ref opencl::kernels::ClWidthConcatenateKernel,
103 * @ref opencl::kernels::ClHeightConcatenateKernel and @ref opencl::kernels::ClDepthConcatenateKernel.
Georgios Pinitase29acf12018-07-16 14:40:09 +0100104 *
Sheri Zhanga47dcc22021-04-22 14:41:12 +0100105 * @param[in] inputs_vector The vectors containing all the tensors info to concatenate. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32.
Georgios Pinitase29acf12018-07-16 14:40:09 +0100106 * @param[in] output Output tensor info. Data types supported: Same as @p input.
Vidhya Sudhan Loganathan338595b2019-06-28 14:09:53 +0100107 * @param[in] axis Concatenation axis. Supported underlying concatenation axis are 0, 1, 2 and 3.
Georgios Pinitase29acf12018-07-16 14:40:09 +0100108 *
109 * @return a status
110 */
Manuel Bottini10c53f12019-07-17 16:11:53 +0100111 static Status validate(const std::vector<const ITensorInfo *> &inputs_vector, const ITensorInfo *output, size_t axis);
Georgios Pinitase29acf12018-07-16 14:40:09 +0100112
113 // Inherited methods overridden:
114 void run() override;
115
116private:
Michele Di Giorgiof932d2c2020-07-06 11:27:21 +0100117 struct Impl;
118 std::unique_ptr<Impl> _impl;
119};
Georgios Pinitas9e4824c2019-04-12 13:15:58 +0100120} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000121#endif /* ARM_COMPUTE_CLCONCATENATELAYER_H */