blob: 953e3fa641f091583153f2b1390bf18220502659 [file] [log] [blame]
Georgios Pinitasae54e022018-07-16 15:41:27 +01001/*
Pablo Tello3dd5b682019-03-04 14:14:02 +00002 * Copyright (c) 2018-2019 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 */
24#ifndef __ARM_COMPUTE_NECONCATENATELAYER_H__
25#define __ARM_COMPUTE_NECONCATENATELAYER_H__
26
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 Pinitasae54e022018-07-16 15:41:27 +010032
33#include <memory>
34#include <vector>
35
36namespace arm_compute
37{
38// Forward declarations
39class ITensor;
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 NEWidthConcatenateLayerKernel (if underlying concatenation axis is 0).
Pablo Tello3dd5b682019-03-04 14:14:02 +000046 * -# @ref NEHeightConcatenateLayerKernel (if underlying concatenation axis is 1).
Georgios Pinitas09f24972019-05-17 18:14:40 +010047 * -# @ref NEDepthConcatenateLayerKernel (if underlying concatenation axis is 2).
Vidhya Sudhan Loganathan338595b2019-06-28 14:09:53 +010048 * -# @ref NEBatchConcatenateLayerKernel (if underlying concatenation axis is 3).
Georgios Pinitasae54e022018-07-16 15:41:27 +010049 */
50class NEConcatenateLayer : public IFunction
51{
52public:
53 /** Default constructor */
54 NEConcatenateLayer();
55 /** Initialise the kernel's inputs vector and output.
56 *
57 * @note Input and output tensor dimensions preconditions defer depending on the concatenation axis.
Georgios Pinitas09f24972019-05-17 18:14:40 +010058 * @note Preconditions can be found respectively at @ref NEWidthConcatenateLayerKernel, @ref NEHeightConcatenateLayerKernel and @ref NEDepthConcatenateLayerKernel.
Georgios Pinitasae54e022018-07-16 15:41:27 +010059 *
60 * @param[in,out] inputs_vector The vectors containing all the tensors to concatenate. Data types supported: QASYMM8/F16/F32.
61 * @param[out] output Output tensor. Data types supported: Same as @p input.
Vidhya Sudhan Loganathan338595b2019-06-28 14:09:53 +010062 * @param[in] axis Concatenation axis. Supported underlying concatenation axis are 0, 1, 2 and 3.
Georgios Pinitasae54e022018-07-16 15:41:27 +010063 */
Georgios Pinitas09f24972019-05-17 18:14:40 +010064 void configure(std::vector<ITensor *> inputs_vector, ITensor *output, size_t axis);
65 void configure(std::vector<const ITensor *> inputs_vector, ITensor *output, size_t axis);
Georgios Pinitasae54e022018-07-16 15:41:27 +010066 /** Static function to check if given info will lead to a valid configuration of @ref NEConcatenateLayer
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 *
71 * @param[in] inputs_vector The vectors containing all the tensors info to concatenate. Data types supported: QASYMM8/F16/F32.
72 * @param[in] output Output tensor info. 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 *
75 * @return a status
76 */
Georgios Pinitas9e4824c2019-04-12 13:15:58 +010077 static Status validate(const std::vector<ITensorInfo *> &inputs_vector, const ITensorInfo *output, size_t axis);
Georgios Pinitas09f24972019-05-17 18:14:40 +010078 static Status validate(const std::vector<const ITensorInfo *> &inputs_vector, const ITensorInfo *output, size_t axis);
Georgios Pinitasae54e022018-07-16 15:41:27 +010079
80 // Inherited methods overridden:
81 void run() override;
82
83private:
Georgios Pinitas09f24972019-05-17 18:14:40 +010084 template <typename TensorType, REQUIRES_TA(std::is_same<typename std::remove_cv<TensorType>::type, ITensor>::value)>
85 void configure_internal(std::vector<TensorType *> &&inputs_vector, ITensor *output, size_t axis);
86
87 template <typename TensorInfoType, REQUIRES_TA(std::is_same<typename std::remove_cv<TensorInfoType>::type, ITensorInfo>::value)>
88 static Status validate_internal(const std::vector<TensorInfoType *> &inputs_vector, const ITensorInfo *output, size_t axis);
89
90private:
Michalis Spyrou9f15c5e2019-04-03 19:48:54 +010091 std::vector<std::unique_ptr<INEKernel>> _concat_kernels;
92 unsigned int _num_inputs;
93 unsigned int _axis;
Georgios Pinitasae54e022018-07-16 15:41:27 +010094};
Pablo Tello3dd5b682019-03-04 14:14:02 +000095} // namespace arm_compute
Georgios Pinitasae54e022018-07-16 15:41:27 +010096#endif /* __ARM_COMPUTE_NECONCATENATELAYER_H__ */