blob: 1d703ae729d9a6a0b9737773ed899f989d5c1ef9 [file] [log] [blame]
Georgios Pinitasae54e022018-07-16 15:41:27 +01001/*
Georgios Pinitas4667ddd2020-07-13 21:21:33 +01002 * Copyright (c) 2018-2020 Arm Limited.
Georgios Pinitasae54e022018-07-16 15:41:27 +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_NECONCATENATELAYER_H
25#define ARM_COMPUTE_NECONCATENATELAYER_H
Georgios Pinitasae54e022018-07-16 15:41:27 +010026
27#include "arm_compute/runtime/IFunction.h"
28
Georgios Pinitas09f24972019-05-17 18:14:40 +010029#include "arm_compute/core/NEON/INEKernel.h"
Georgios Pinitasae54e022018-07-16 15:41:27 +010030#include "arm_compute/core/Types.h"
Georgios Pinitas09f24972019-05-17 18:14:40 +010031#include "arm_compute/core/utils/misc/Requires.h"
Georgios Pinitas4667ddd2020-07-13 21:21:33 +010032#include "arm_compute/runtime/NEON/INEOperator.h"
Georgios Pinitasae54e022018-07-16 15:41:27 +010033
34#include <memory>
35#include <vector>
36
37namespace arm_compute
38{
39// Forward declarations
40class ITensor;
41class ITensorInfo;
42class Status;
43
44/** Basic function to execute concatenate tensors along a given axis. This function calls the following kernels:
45 *
Georgios Pinitas09f24972019-05-17 18:14:40 +010046 * -# @ref NEWidthConcatenateLayerKernel (if underlying concatenation axis is 0).
Pablo Tello3dd5b682019-03-04 14:14:02 +000047 * -# @ref NEHeightConcatenateLayerKernel (if underlying concatenation axis is 1).
Georgios Pinitas09f24972019-05-17 18:14:40 +010048 * -# @ref NEDepthConcatenateLayerKernel (if underlying concatenation axis is 2).
Vidhya Sudhan Loganathan338595b2019-06-28 14:09:53 +010049 * -# @ref NEBatchConcatenateLayerKernel (if underlying concatenation axis is 3).
Georgios Pinitasae54e022018-07-16 15:41:27 +010050 */
51class NEConcatenateLayer : public IFunction
52{
53public:
54 /** Default constructor */
55 NEConcatenateLayer();
Georgios Pinitas4667ddd2020-07-13 21:21:33 +010056 /** Destructor */
57 ~NEConcatenateLayer();
58 /** Prevent instances of this class from being copied (As this class contains pointers) */
59 NEConcatenateLayer(const NEConcatenateLayer &) = delete;
60 /** Default move constructor */
61 NEConcatenateLayer(NEConcatenateLayer &&);
62 /** Prevent instances of this class from being copied (As this class contains pointers) */
63 NEConcatenateLayer &operator=(const NEConcatenateLayer &) = delete;
64 /** Default move assignment operator */
65 NEConcatenateLayer &operator=(NEConcatenateLayer &&);
Georgios Pinitasae54e022018-07-16 15:41:27 +010066 /** Initialise the kernel's inputs vector and output.
67 *
68 * @note Input and output tensor dimensions preconditions defer depending on the concatenation axis.
Georgios Pinitas09f24972019-05-17 18:14:40 +010069 * @note Preconditions can be found respectively at @ref NEWidthConcatenateLayerKernel, @ref NEHeightConcatenateLayerKernel and @ref NEDepthConcatenateLayerKernel.
Georgios Pinitasae54e022018-07-16 15:41:27 +010070 *
Georgios Pinitas33843562019-12-10 13:33:18 +000071 * @param[in,out] inputs_vector The vectors containing all the tensors to concatenate. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32.
Georgios Pinitasae54e022018-07-16 15:41:27 +010072 * @param[out] output Output tensor. Data types supported: Same as @p input.
Vidhya Sudhan Loganathan338595b2019-06-28 14:09:53 +010073 * @param[in] axis Concatenation axis. Supported underlying concatenation axis are 0, 1, 2 and 3.
Georgios Pinitasae54e022018-07-16 15:41:27 +010074 */
Georgios Pinitas09f24972019-05-17 18:14:40 +010075 void configure(std::vector<const ITensor *> inputs_vector, ITensor *output, size_t axis);
Georgios Pinitasae54e022018-07-16 15:41:27 +010076 /** Static function to check if given info will lead to a valid configuration of @ref NEConcatenateLayer
77 *
78 * @note Input and output tensor dimensions preconditions defer depending on the concatenation axis.
Georgios Pinitas09f24972019-05-17 18:14:40 +010079 * @note Preconditions can be found respectively at @ref NEWidthConcatenateLayerKernel, @ref NEHeightConcatenateLayerKernel and @ref NEDepthConcatenateLayerKernel.
Georgios Pinitasae54e022018-07-16 15:41:27 +010080 *
Georgios Pinitas33843562019-12-10 13:33:18 +000081 * @param[in] inputs_vector The vectors containing all the tensors info to concatenate. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32.
Georgios Pinitasae54e022018-07-16 15:41:27 +010082 * @param[in] output Output tensor info. Data types supported: Same as @p input.
Vidhya Sudhan Loganathan338595b2019-06-28 14:09:53 +010083 * @param[in] axis Concatenation axis. Supported underlying concatenation axis are 0, 1, 2 and 3.
Georgios Pinitasae54e022018-07-16 15:41:27 +010084 *
85 * @return a status
86 */
Georgios Pinitas09f24972019-05-17 18:14:40 +010087 static Status validate(const std::vector<const ITensorInfo *> &inputs_vector, const ITensorInfo *output, size_t axis);
Georgios Pinitasae54e022018-07-16 15:41:27 +010088
89 // Inherited methods overridden:
90 void run() override;
91
92private:
Georgios Pinitas4667ddd2020-07-13 21:21:33 +010093 struct Impl;
94 std::unique_ptr<Impl> _impl;
95};
Georgios Pinitas09f24972019-05-17 18:14:40 +010096
Georgios Pinitas4667ddd2020-07-13 21:21:33 +010097namespace experimental
98{
99/** Basic function to execute concatenate tensors along a given axis. This function calls the following kernels:
100 *
101 * -# @ref NEWidthConcatenateLayerKernel (if underlying concatenation axis is 0).
102 * -# @ref NEHeightConcatenateLayerKernel (if underlying concatenation axis is 1).
103 * -# @ref NEDepthConcatenateLayerKernel (if underlying concatenation axis is 2).
104 * -# @ref NEBatchConcatenateLayerKernel (if underlying concatenation axis is 3).
105 */
Georgios Pinitas09cad722020-07-22 12:11:20 +0100106class NEConcatenation : public INEOperator
Georgios Pinitas4667ddd2020-07-13 21:21:33 +0100107{
108public:
109 /** Default constructor */
Georgios Pinitas09cad722020-07-22 12:11:20 +0100110 NEConcatenation();
Georgios Pinitas4667ddd2020-07-13 21:21:33 +0100111 /** Initialise the kernel's inputs vector and output.
112 *
113 * @note Input and output tensor dimensions preconditions defer depending on the concatenation axis.
114 * @note Preconditions can be found respectively at @ref NEWidthConcatenateLayerKernel, @ref NEHeightConcatenateLayerKernel and @ref NEDepthConcatenateLayerKernel.
115 *
116 * @param[in,out] inputs_vector The vectors containing all the tensors to concatenate. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32.
117 * @param[out] output Output tensor. Data types supported: Same as @p input.
118 * @param[in] axis Concatenation axis. Supported underlying concatenation axis are 0, 1, 2 and 3.
119 */
120 void configure(const std::vector<const ITensorInfo *> &inputs_vector, ITensorInfo *output, size_t axis);
121 /** Static function to check if given info will lead to a valid configuration of @ref NEConcatenateLayer
122 *
123 * @note Input and output tensor dimensions preconditions defer depending on the concatenation axis.
124 * @note Preconditions can be found respectively at @ref NEWidthConcatenateLayerKernel, @ref NEHeightConcatenateLayerKernel and @ref NEDepthConcatenateLayerKernel.
125 *
126 * @param[in] inputs_vector The vectors containing all the tensors info to concatenate. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32.
127 * @param[in] output Output tensor info. Data types supported: Same as @p input.
128 * @param[in] axis Concatenation axis. Supported underlying concatenation axis are 0, 1, 2 and 3.
129 *
130 * @return a status
131 */
132 static Status validate(const std::vector<const ITensorInfo *> &inputs_vector, const ITensorInfo *output, size_t axis);
133
134 // Inherited methods overridden:
Georgios Pinitas0499dff2020-07-31 22:21:38 +0100135 void run(ITensorPack &tensors) override;
Georgios Pinitas09f24972019-05-17 18:14:40 +0100136
137private:
Michalis Spyrou9f15c5e2019-04-03 19:48:54 +0100138 std::vector<std::unique_ptr<INEKernel>> _concat_kernels;
139 unsigned int _num_inputs;
140 unsigned int _axis;
Georgios Pinitasae54e022018-07-16 15:41:27 +0100141};
Georgios Pinitas4667ddd2020-07-13 21:21:33 +0100142} // namespace experimental
Pablo Tello3dd5b682019-03-04 14:14:02 +0000143} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000144#endif /* ARM_COMPUTE_NECONCATENATELAYER_H */