Georgios Pinitas | e29acf1 | 2018-07-16 14:40:09 +0100 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2020 Arm Limited. |
Georgios Pinitas | e29acf1 | 2018-07-16 14:40:09 +0100 | [diff] [blame] | 3 | * |
| 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 Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_CLCONCATENATELAYER_H |
| 25 | #define ARM_COMPUTE_CLCONCATENATELAYER_H |
Georgios Pinitas | e29acf1 | 2018-07-16 14:40:09 +0100 | [diff] [blame] | 26 | |
Michele Di Giorgio | f932d2c | 2020-07-06 11:27:21 +0100 | [diff] [blame] | 27 | #include "arm_compute/runtime/CL/ICLOperator.h" |
Georgios Pinitas | e29acf1 | 2018-07-16 14:40:09 +0100 | [diff] [blame] | 28 | #include "arm_compute/runtime/IFunction.h" |
| 29 | |
Georgios Pinitas | 09f2497 | 2019-05-17 18:14:40 +0100 | [diff] [blame] | 30 | #include "arm_compute/core/CL/ICLKernel.h" |
Georgios Pinitas | e29acf1 | 2018-07-16 14:40:09 +0100 | [diff] [blame] | 31 | #include "arm_compute/core/Types.h" |
| 32 | |
| 33 | #include <memory> |
| 34 | #include <vector> |
| 35 | |
| 36 | namespace arm_compute |
| 37 | { |
| 38 | // Forward declarations |
| 39 | class ICLTensor; |
| 40 | class ITensorInfo; |
| 41 | class Status; |
| 42 | |
| 43 | /** Basic function to execute concatenate tensors along a given axis. This function calls the following kernels: |
| 44 | * |
Georgios Pinitas | 09f2497 | 2019-05-17 18:14:40 +0100 | [diff] [blame] | 45 | * -# @ref CLWidthConcatenateLayerKernel (if underlying concatenation axis is 0). |
Pablo Tello | 6a14adb | 2019-03-05 17:33:08 +0000 | [diff] [blame] | 46 | * -# @ref CLHeightConcatenateLayerKernel (if underlying concatenation axis is 1). |
Georgios Pinitas | 09f2497 | 2019-05-17 18:14:40 +0100 | [diff] [blame] | 47 | * -# @ref CLDepthConcatenateLayerKernel (if underlying concatenation axis is 2). |
Vidhya Sudhan Loganathan | 338595b | 2019-06-28 14:09:53 +0100 | [diff] [blame] | 48 | * -# @ref CLBatchConcatenateLayerKernel (if underlying concatenation axis is 3). |
Georgios Pinitas | e29acf1 | 2018-07-16 14:40:09 +0100 | [diff] [blame] | 49 | */ |
| 50 | class CLConcatenateLayer : public IFunction |
| 51 | { |
| 52 | public: |
| 53 | /** Default constructor */ |
| 54 | CLConcatenateLayer(); |
Michele Di Giorgio | f932d2c | 2020-07-06 11:27:21 +0100 | [diff] [blame] | 55 | /** 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 Pinitas | e29acf1 | 2018-07-16 14:40:09 +0100 | [diff] [blame] | 65 | /** Initialise the kernel's inputs vector and output. |
| 66 | * |
| 67 | * @note Input and output tensor dimensions preconditions defer depending on the concatenation axis. |
Georgios Pinitas | 09f2497 | 2019-05-17 18:14:40 +0100 | [diff] [blame] | 68 | * @note Preconditions can be found respectively at @ref CLWidthConcatenateLayerKernel, @ref CLHeightConcatenateLayerKernel and @ref CLDepthConcatenateLayerKernel. |
Georgios Pinitas | e29acf1 | 2018-07-16 14:40:09 +0100 | [diff] [blame] | 69 | * |
Michele Di Giorgio | f932d2c | 2020-07-06 11:27:21 +0100 | [diff] [blame] | 70 | * @param[in,out] inputs_vector The vectors containing all the tensors to concatenate. Data types supported: All |
Georgios Pinitas | e29acf1 | 2018-07-16 14:40:09 +0100 | [diff] [blame] | 71 | * @param[out] output Output tensor. Data types supported: Same as @p input. |
Vidhya Sudhan Loganathan | 338595b | 2019-06-28 14:09:53 +0100 | [diff] [blame] | 72 | * @param[in] axis Concatenation axis. Supported underlying concatenation axis are 0, 1, 2 and 3. |
Georgios Pinitas | e29acf1 | 2018-07-16 14:40:09 +0100 | [diff] [blame] | 73 | */ |
Manuel Bottini | 10c53f1 | 2019-07-17 16:11:53 +0100 | [diff] [blame] | 74 | void configure(std::vector<const ICLTensor *> &inputs_vector, ICLTensor *output, size_t axis); |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 75 | /** 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 Giorgio | f932d2c | 2020-07-06 11:27:21 +0100 | [diff] [blame] | 81 | * @param[in,out] inputs_vector The vectors containing all the tensors to concatenate. Data types supported: All |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 82 | * @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 Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 85 | void configure(const CLCompileContext &compile_context, std::vector<const ICLTensor *> &inputs_vector, ICLTensor *output, size_t axis); |
Georgios Pinitas | e29acf1 | 2018-07-16 14:40:09 +0100 | [diff] [blame] | 86 | /** 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 Pinitas | 09f2497 | 2019-05-17 18:14:40 +0100 | [diff] [blame] | 89 | * @note Preconditions can be found respectively at @ref CLWidthConcatenateLayerKernel, @ref CLHeightConcatenateLayerKernel and @ref CLDepthConcatenateLayerKernel. |
Georgios Pinitas | e29acf1 | 2018-07-16 14:40:09 +0100 | [diff] [blame] | 90 | * |
Manuel Bottini | 8481d83 | 2019-12-10 15:28:40 +0000 | [diff] [blame] | 91 | * @param[in] inputs_vector The vectors containing all the tensors info to concatenate. Data types supported: All. |
Georgios Pinitas | e29acf1 | 2018-07-16 14:40:09 +0100 | [diff] [blame] | 92 | * @param[in] output Output tensor info. Data types supported: Same as @p input. |
Vidhya Sudhan Loganathan | 338595b | 2019-06-28 14:09:53 +0100 | [diff] [blame] | 93 | * @param[in] axis Concatenation axis. Supported underlying concatenation axis are 0, 1, 2 and 3. |
Georgios Pinitas | e29acf1 | 2018-07-16 14:40:09 +0100 | [diff] [blame] | 94 | * |
| 95 | * @return a status |
| 96 | */ |
Manuel Bottini | 10c53f1 | 2019-07-17 16:11:53 +0100 | [diff] [blame] | 97 | static Status validate(const std::vector<const ITensorInfo *> &inputs_vector, const ITensorInfo *output, size_t axis); |
Georgios Pinitas | e29acf1 | 2018-07-16 14:40:09 +0100 | [diff] [blame] | 98 | |
| 99 | // Inherited methods overridden: |
| 100 | void run() override; |
| 101 | |
| 102 | private: |
Michele Di Giorgio | f932d2c | 2020-07-06 11:27:21 +0100 | [diff] [blame] | 103 | struct Impl; |
| 104 | std::unique_ptr<Impl> _impl; |
| 105 | }; |
Manuel Bottini | 10c53f1 | 2019-07-17 16:11:53 +0100 | [diff] [blame] | 106 | |
Michele Di Giorgio | f932d2c | 2020-07-06 11:27:21 +0100 | [diff] [blame] | 107 | namespace 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 Pinitas | 09cad72 | 2020-07-22 12:11:20 +0100 | [diff] [blame] | 116 | class CLConcatenation : public ICLOperator |
Michele Di Giorgio | f932d2c | 2020-07-06 11:27:21 +0100 | [diff] [blame] | 117 | { |
| 118 | public: |
| 119 | /** Default constructor */ |
Georgios Pinitas | 09cad72 | 2020-07-22 12:11:20 +0100 | [diff] [blame] | 120 | CLConcatenation(); |
Michele Di Giorgio | f932d2c | 2020-07-06 11:27:21 +0100 | [diff] [blame] | 121 | /** 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 Bottini | 10c53f1 | 2019-07-17 16:11:53 +0100 | [diff] [blame] | 145 | |
Michele Di Giorgio | f932d2c | 2020-07-06 11:27:21 +0100 | [diff] [blame] | 146 | // Inherited methods overridden: |
Georgios Pinitas | 0499dff | 2020-07-31 22:21:38 +0100 | [diff] [blame] | 147 | void run(ITensorPack &tensors) override; |
Michele Di Giorgio | f932d2c | 2020-07-06 11:27:21 +0100 | [diff] [blame] | 148 | |
| 149 | private: |
Michalis Spyrou | 8c57169 | 2019-04-05 11:29:52 +0100 | [diff] [blame] | 150 | std::vector<std::unique_ptr<ICLKernel>> _concat_kernels; |
| 151 | unsigned int _num_inputs; |
| 152 | unsigned int _axis; |
Georgios Pinitas | e29acf1 | 2018-07-16 14:40:09 +0100 | [diff] [blame] | 153 | }; |
Michele Di Giorgio | f932d2c | 2020-07-06 11:27:21 +0100 | [diff] [blame] | 154 | } // namespace experimental |
Georgios Pinitas | 9e4824c | 2019-04-12 13:15:58 +0100 | [diff] [blame] | 155 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 156 | #endif /* ARM_COMPUTE_CLCONCATENATELAYER_H */ |