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 | */ |
| 24 | #include "arm_compute/runtime/CL/functions/CLConcatenateLayer.h" |
| 25 | |
Vidhya Sudhan Loganathan | 338595b | 2019-06-28 14:09:53 +0100 | [diff] [blame] | 26 | #include "arm_compute/core/CL/kernels/CLBatchConcatenateLayerKernel.h" |
Georgios Pinitas | 09f2497 | 2019-05-17 18:14:40 +0100 | [diff] [blame] | 27 | #include "arm_compute/core/CL/kernels/CLDepthConcatenateLayerKernel.h" |
Pablo Tello | 6a14adb | 2019-03-05 17:33:08 +0000 | [diff] [blame] | 28 | #include "arm_compute/core/CL/kernels/CLHeightConcatenateLayerKernel.h" |
Georgios Pinitas | 09f2497 | 2019-05-17 18:14:40 +0100 | [diff] [blame] | 29 | #include "arm_compute/core/CL/kernels/CLWidthConcatenate2TensorsKernel.h" |
| 30 | #include "arm_compute/core/CL/kernels/CLWidthConcatenate4TensorsKernel.h" |
| 31 | #include "arm_compute/core/CL/kernels/CLWidthConcatenateLayerKernel.h" |
Pablo Tello | 6a14adb | 2019-03-05 17:33:08 +0000 | [diff] [blame] | 32 | #include "arm_compute/core/utils/misc/ShapeCalculator.h" |
| 33 | #include "arm_compute/runtime/CL/CLScheduler.h" |
Georgios Pinitas | e29acf1 | 2018-07-16 14:40:09 +0100 | [diff] [blame] | 34 | |
| 35 | #include "arm_compute/core/CL/ICLTensor.h" |
| 36 | #include "arm_compute/core/Error.h" |
| 37 | #include "arm_compute/core/TensorInfo.h" |
| 38 | #include "arm_compute/core/Types.h" |
Matthew Bentham | 9204646 | 2020-03-07 22:15:55 +0000 | [diff] [blame] | 39 | #include "support/MemorySupport.h" |
Georgios Pinitas | e29acf1 | 2018-07-16 14:40:09 +0100 | [diff] [blame] | 40 | |
| 41 | namespace arm_compute |
| 42 | { |
Michele Di Giorgio | f932d2c | 2020-07-06 11:27:21 +0100 | [diff] [blame] | 43 | namespace experimental |
| 44 | { |
Georgios Pinitas | 09cad72 | 2020-07-22 12:11:20 +0100 | [diff] [blame] | 45 | CLConcatenation::CLConcatenation() |
Michalis Spyrou | 8c57169 | 2019-04-05 11:29:52 +0100 | [diff] [blame] | 46 | : _concat_kernels(), |
Pablo Tello | 6a14adb | 2019-03-05 17:33:08 +0000 | [diff] [blame] | 47 | _num_inputs(0), |
| 48 | _axis(Window::DimX) |
Georgios Pinitas | e29acf1 | 2018-07-16 14:40:09 +0100 | [diff] [blame] | 49 | { |
| 50 | } |
| 51 | |
Georgios Pinitas | 09cad72 | 2020-07-22 12:11:20 +0100 | [diff] [blame] | 52 | void CLConcatenation::configure(const CLCompileContext &compile_context, const std::vector<ITensorInfo *> &inputs_vector, ITensorInfo *output, size_t axis) |
Pablo Tello | 6a14adb | 2019-03-05 17:33:08 +0000 | [diff] [blame] | 53 | { |
Michalis Spyrou | 8c57169 | 2019-04-05 11:29:52 +0100 | [diff] [blame] | 54 | ARM_COMPUTE_ERROR_ON(output == nullptr); |
Georgios Pinitas | 9e4824c | 2019-04-12 13:15:58 +0100 | [diff] [blame] | 55 | _axis = axis; |
Pablo Tello | 6a14adb | 2019-03-05 17:33:08 +0000 | [diff] [blame] | 56 | _num_inputs = inputs_vector.size(); |
| 57 | |
Michele Di Giorgio | f932d2c | 2020-07-06 11:27:21 +0100 | [diff] [blame] | 58 | TensorShape output_shape = arm_compute::misc::shape_calculator::calculate_concatenate_shape(inputs_vector, _axis); |
| 59 | std::vector<const ITensorInfo *> const_inputs_vector(inputs_vector.size()); |
| 60 | std::transform(inputs_vector.begin(), inputs_vector.end(), const_inputs_vector.begin(), [](ITensorInfo * t) |
Pablo Tello | 6a14adb | 2019-03-05 17:33:08 +0000 | [diff] [blame] | 61 | { |
| 62 | ARM_COMPUTE_ERROR_ON_NULLPTR(t); |
Michele Di Giorgio | f932d2c | 2020-07-06 11:27:21 +0100 | [diff] [blame] | 63 | return t; |
Pablo Tello | 6a14adb | 2019-03-05 17:33:08 +0000 | [diff] [blame] | 64 | }); |
Pablo Tello | 6a14adb | 2019-03-05 17:33:08 +0000 | [diff] [blame] | 65 | |
| 66 | // Output auto inizialitation if not yet initialized |
Michele Di Giorgio | f932d2c | 2020-07-06 11:27:21 +0100 | [diff] [blame] | 67 | auto_init_if_empty(*output, output_shape, 1, inputs_vector[0]->data_type()); |
| 68 | ARM_COMPUTE_ERROR_THROW_ON(CLConcatenateLayer::validate(const_inputs_vector, output, axis)); |
Pablo Tello | 6a14adb | 2019-03-05 17:33:08 +0000 | [diff] [blame] | 69 | |
Michalis Spyrou | 8c57169 | 2019-04-05 11:29:52 +0100 | [diff] [blame] | 70 | unsigned int offset = 0; |
Pablo Tello | 6a14adb | 2019-03-05 17:33:08 +0000 | [diff] [blame] | 71 | switch(_axis) |
Georgios Pinitas | e29acf1 | 2018-07-16 14:40:09 +0100 | [diff] [blame] | 72 | { |
Michalis Spyrou | 8c57169 | 2019-04-05 11:29:52 +0100 | [diff] [blame] | 73 | case Window::DimX: |
Georgios Pinitas | e29acf1 | 2018-07-16 14:40:09 +0100 | [diff] [blame] | 74 | { |
Michalis Spyrou | 8c57169 | 2019-04-05 11:29:52 +0100 | [diff] [blame] | 75 | switch(_num_inputs) |
| 76 | { |
| 77 | case 2: |
| 78 | { |
| 79 | // Configure WidthConcatenate2Tensors kernel |
| 80 | auto kernel = support::cpp14::make_unique<CLWidthConcatenate2TensorsKernel>(); |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 81 | kernel->configure(compile_context, inputs_vector.at(0), inputs_vector.at(1), output); |
Michalis Spyrou | 8c57169 | 2019-04-05 11:29:52 +0100 | [diff] [blame] | 82 | _concat_kernels.emplace_back(std::move(kernel)); |
| 83 | break; |
| 84 | } |
| 85 | case 4: |
| 86 | { |
| 87 | // Configure WidthConcatenate4Tensors kernel |
| 88 | auto kernel = support::cpp14::make_unique<CLWidthConcatenate4TensorsKernel>(); |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 89 | kernel->configure(compile_context, inputs_vector.at(0), inputs_vector.at(1), inputs_vector.at(2), inputs_vector.at(3), output); |
Michalis Spyrou | 8c57169 | 2019-04-05 11:29:52 +0100 | [diff] [blame] | 90 | _concat_kernels.emplace_back(std::move(kernel)); |
| 91 | break; |
| 92 | } |
| 93 | default: |
| 94 | { |
| 95 | // Configure generic case WidthConcatenate kernels |
| 96 | for(unsigned int i = 0; i < _num_inputs; ++i) |
| 97 | { |
| 98 | auto kernel = support::cpp14::make_unique<CLWidthConcatenateLayerKernel>(); |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 99 | kernel->configure(compile_context, inputs_vector.at(i), offset, output); |
Michele Di Giorgio | f932d2c | 2020-07-06 11:27:21 +0100 | [diff] [blame] | 100 | offset += inputs_vector.at(i)->dimension(_axis); |
Michalis Spyrou | 8c57169 | 2019-04-05 11:29:52 +0100 | [diff] [blame] | 101 | _concat_kernels.emplace_back(std::move(kernel)); |
| 102 | } |
| 103 | break; |
| 104 | } |
| 105 | } |
Georgios Pinitas | e29acf1 | 2018-07-16 14:40:09 +0100 | [diff] [blame] | 106 | break; |
| 107 | } |
Michalis Spyrou | 8c57169 | 2019-04-05 11:29:52 +0100 | [diff] [blame] | 108 | case Window::DimY: |
Pablo Tello | 6a14adb | 2019-03-05 17:33:08 +0000 | [diff] [blame] | 109 | { |
Michalis Spyrou | 8c57169 | 2019-04-05 11:29:52 +0100 | [diff] [blame] | 110 | for(unsigned int i = 0; i < _num_inputs; ++i) |
| 111 | { |
| 112 | auto kernel = support::cpp14::make_unique<CLHeightConcatenateLayerKernel>(); |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 113 | kernel->configure(compile_context, inputs_vector.at(i), offset, output); |
Michele Di Giorgio | f932d2c | 2020-07-06 11:27:21 +0100 | [diff] [blame] | 114 | offset += inputs_vector.at(i)->dimension(_axis); |
Michalis Spyrou | 8c57169 | 2019-04-05 11:29:52 +0100 | [diff] [blame] | 115 | _concat_kernels.emplace_back(std::move(kernel)); |
| 116 | } |
Pablo Tello | 6a14adb | 2019-03-05 17:33:08 +0000 | [diff] [blame] | 117 | break; |
| 118 | } |
Michalis Spyrou | 8c57169 | 2019-04-05 11:29:52 +0100 | [diff] [blame] | 119 | case Window::DimZ: |
Georgios Pinitas | e29acf1 | 2018-07-16 14:40:09 +0100 | [diff] [blame] | 120 | { |
Michalis Spyrou | 8c57169 | 2019-04-05 11:29:52 +0100 | [diff] [blame] | 121 | for(unsigned int i = 0; i < _num_inputs; ++i) |
| 122 | { |
| 123 | auto kernel = support::cpp14::make_unique<CLDepthConcatenateLayerKernel>(); |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 124 | kernel->configure(compile_context, inputs_vector.at(i), offset, output); |
Michele Di Giorgio | f932d2c | 2020-07-06 11:27:21 +0100 | [diff] [blame] | 125 | offset += inputs_vector.at(i)->dimension(_axis); |
Michalis Spyrou | 8c57169 | 2019-04-05 11:29:52 +0100 | [diff] [blame] | 126 | _concat_kernels.emplace_back(std::move(kernel)); |
| 127 | } |
Georgios Pinitas | e29acf1 | 2018-07-16 14:40:09 +0100 | [diff] [blame] | 128 | break; |
| 129 | } |
Vidhya Sudhan Loganathan | 338595b | 2019-06-28 14:09:53 +0100 | [diff] [blame] | 130 | case 3: |
| 131 | { |
| 132 | for(unsigned int i = 0; i < _num_inputs; ++i) |
| 133 | { |
| 134 | auto kernel = support::cpp14::make_unique<CLBatchConcatenateLayerKernel>(); |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 135 | kernel->configure(compile_context, inputs_vector.at(i), offset, output); |
Michele Di Giorgio | f932d2c | 2020-07-06 11:27:21 +0100 | [diff] [blame] | 136 | offset += inputs_vector.at(i)->dimension(_axis); |
Vidhya Sudhan Loganathan | 338595b | 2019-06-28 14:09:53 +0100 | [diff] [blame] | 137 | _concat_kernels.emplace_back(std::move(kernel)); |
| 138 | } |
| 139 | break; |
| 140 | } |
Georgios Pinitas | e29acf1 | 2018-07-16 14:40:09 +0100 | [diff] [blame] | 141 | default: |
Michalis Spyrou | 8c57169 | 2019-04-05 11:29:52 +0100 | [diff] [blame] | 142 | ARM_COMPUTE_ERROR("Axis not supported"); |
Georgios Pinitas | e29acf1 | 2018-07-16 14:40:09 +0100 | [diff] [blame] | 143 | } |
| 144 | } |
| 145 | |
Georgios Pinitas | 09cad72 | 2020-07-22 12:11:20 +0100 | [diff] [blame] | 146 | Status CLConcatenation::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] | 147 | { |
| 148 | ARM_COMPUTE_RETURN_ERROR_ON(output == nullptr); |
Michalis Spyrou | 8c57169 | 2019-04-05 11:29:52 +0100 | [diff] [blame] | 149 | const unsigned int num_inputs = inputs_vector.size(); |
Georgios Pinitas | e29acf1 | 2018-07-16 14:40:09 +0100 | [diff] [blame] | 150 | |
Michalis Spyrou | 8c57169 | 2019-04-05 11:29:52 +0100 | [diff] [blame] | 151 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(output); |
| 152 | ARM_COMPUTE_RETURN_ERROR_ON(num_inputs < 2); |
Michalis Spyrou | 8c57169 | 2019-04-05 11:29:52 +0100 | [diff] [blame] | 153 | |
Michalis Spyrou | 8c57169 | 2019-04-05 11:29:52 +0100 | [diff] [blame] | 154 | unsigned int offset = 0; |
Georgios Pinitas | 9e4824c | 2019-04-12 13:15:58 +0100 | [diff] [blame] | 155 | switch(axis) |
Michalis Spyrou | 8c57169 | 2019-04-05 11:29:52 +0100 | [diff] [blame] | 156 | { |
| 157 | case Window::DimX: |
| 158 | { |
| 159 | switch(num_inputs) |
| 160 | { |
| 161 | case 2: |
| 162 | // Validate WidthConcatenate2Tensors kernels if there are 2 inputs |
| 163 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(inputs_vector[0], inputs_vector[1]); |
Michalis Spyrou | a9c4472 | 2019-04-05 17:18:36 +0100 | [diff] [blame] | 164 | ARM_COMPUTE_RETURN_ON_ERROR(CLWidthConcatenate2TensorsKernel::validate(inputs_vector[0], inputs_vector[1], output)); |
Michalis Spyrou | 8c57169 | 2019-04-05 11:29:52 +0100 | [diff] [blame] | 165 | break; |
| 166 | case 4: |
| 167 | // Validate WidthConcatenate4Tensors kernels if there are 4 inputs |
| 168 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(inputs_vector[0], inputs_vector[1], inputs_vector[2], inputs_vector[3]); |
Michalis Spyrou | a9c4472 | 2019-04-05 17:18:36 +0100 | [diff] [blame] | 169 | ARM_COMPUTE_RETURN_ON_ERROR(CLWidthConcatenate4TensorsKernel::validate(inputs_vector[0], inputs_vector[1], inputs_vector[2], inputs_vector[3], output)); |
Michalis Spyrou | 8c57169 | 2019-04-05 11:29:52 +0100 | [diff] [blame] | 170 | break; |
| 171 | default: |
| 172 | // Validate generic case of WidthConcatenate kernel |
| 173 | for(const auto &input : inputs_vector) |
| 174 | { |
| 175 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input); |
Michalis Spyrou | a9c4472 | 2019-04-05 17:18:36 +0100 | [diff] [blame] | 176 | ARM_COMPUTE_RETURN_ON_ERROR(CLWidthConcatenateLayerKernel::validate(input, offset, output)); |
Georgios Pinitas | 9e4824c | 2019-04-12 13:15:58 +0100 | [diff] [blame] | 177 | offset += input->dimension(axis); |
Michalis Spyrou | 8c57169 | 2019-04-05 11:29:52 +0100 | [diff] [blame] | 178 | } |
| 179 | break; |
| 180 | } |
| 181 | break; |
| 182 | } |
| 183 | case Window::DimY: |
| 184 | { |
| 185 | for(const auto &input : inputs_vector) |
| 186 | { |
Michalis Spyrou | a9c4472 | 2019-04-05 17:18:36 +0100 | [diff] [blame] | 187 | ARM_COMPUTE_RETURN_ON_ERROR(CLHeightConcatenateLayerKernel::validate(input, offset, output)); |
Georgios Pinitas | 9e4824c | 2019-04-12 13:15:58 +0100 | [diff] [blame] | 188 | offset += input->dimension(axis); |
Michalis Spyrou | 8c57169 | 2019-04-05 11:29:52 +0100 | [diff] [blame] | 189 | } |
| 190 | break; |
| 191 | } |
| 192 | case Window::DimZ: |
| 193 | { |
| 194 | for(const auto &input : inputs_vector) |
| 195 | { |
Michalis Spyrou | a9c4472 | 2019-04-05 17:18:36 +0100 | [diff] [blame] | 196 | ARM_COMPUTE_RETURN_ON_ERROR(CLDepthConcatenateLayerKernel::validate(input, offset, output)); |
Georgios Pinitas | 9e4824c | 2019-04-12 13:15:58 +0100 | [diff] [blame] | 197 | offset += input->dimension(axis); |
Michalis Spyrou | 8c57169 | 2019-04-05 11:29:52 +0100 | [diff] [blame] | 198 | } |
| 199 | break; |
| 200 | } |
Vidhya Sudhan Loganathan | 338595b | 2019-06-28 14:09:53 +0100 | [diff] [blame] | 201 | case 3: |
| 202 | { |
| 203 | for(const auto &input : inputs_vector) |
| 204 | { |
| 205 | ARM_COMPUTE_RETURN_ON_ERROR(CLBatchConcatenateLayerKernel::validate(input, offset, output)); |
| 206 | offset += input->dimension(axis); |
| 207 | } |
| 208 | break; |
| 209 | } |
Michalis Spyrou | 8c57169 | 2019-04-05 11:29:52 +0100 | [diff] [blame] | 210 | default: |
| 211 | ARM_COMPUTE_ERROR("Axis not supported"); |
| 212 | } |
| 213 | |
Michalis Spyrou | a9c4472 | 2019-04-05 17:18:36 +0100 | [diff] [blame] | 214 | if(output->total_size() != 0) |
| 215 | { |
| 216 | TensorShape output_shape = arm_compute::misc::shape_calculator::calculate_concatenate_shape(inputs_vector, axis); |
| 217 | ARM_COMPUTE_RETURN_ERROR_ON(output_shape.total_size() != output->tensor_shape().total_size()); |
| 218 | } |
| 219 | |
Georgios Pinitas | e29acf1 | 2018-07-16 14:40:09 +0100 | [diff] [blame] | 220 | return Status{}; |
| 221 | } |
| 222 | |
Georgios Pinitas | 0499dff | 2020-07-31 22:21:38 +0100 | [diff] [blame] | 223 | void CLConcatenation::run(ITensorPack &tensors) |
Michele Di Giorgio | f932d2c | 2020-07-06 11:27:21 +0100 | [diff] [blame] | 224 | { |
Georgios Pinitas | 0499dff | 2020-07-31 22:21:38 +0100 | [diff] [blame] | 225 | if(tensors.empty()) |
Michele Di Giorgio | f932d2c | 2020-07-06 11:27:21 +0100 | [diff] [blame] | 226 | { |
| 227 | ARM_COMPUTE_ERROR("No inputs provided"); |
| 228 | } |
| 229 | |
Georgios Pinitas | 0499dff | 2020-07-31 22:21:38 +0100 | [diff] [blame] | 230 | if(static_cast<int>(tensors.size()) - 1 != static_cast<int>(_num_inputs)) |
Michele Di Giorgio | f932d2c | 2020-07-06 11:27:21 +0100 | [diff] [blame] | 231 | { |
| 232 | ARM_COMPUTE_ERROR("Configured with different number of inputs"); |
| 233 | } |
| 234 | |
| 235 | if(_axis == Window::DimX && (_num_inputs == 2 || _num_inputs == 4)) |
| 236 | { |
| 237 | ARM_COMPUTE_ERROR_ON(_concat_kernels.empty()); |
Georgios Pinitas | 0499dff | 2020-07-31 22:21:38 +0100 | [diff] [blame] | 238 | CLScheduler::get().enqueue_op(*_concat_kernels.at(0), tensors, true); |
Michele Di Giorgio | f932d2c | 2020-07-06 11:27:21 +0100 | [diff] [blame] | 239 | } |
| 240 | else |
| 241 | { |
| 242 | int i = 0; |
| 243 | for(auto &k : _concat_kernels) |
| 244 | { |
Georgios Pinitas | 0499dff | 2020-07-31 22:21:38 +0100 | [diff] [blame] | 245 | ITensorPack pack; |
| 246 | pack.add_tensor(TensorType::ACL_SRC, tensors.get_const_tensor(ACL_SRC_VEC + i)); |
| 247 | pack.add_tensor(TensorType::ACL_DST, tensors.get_tensor(ACL_DST)); |
| 248 | CLScheduler::get().enqueue_op(*k, pack, true); |
Michele Di Giorgio | f932d2c | 2020-07-06 11:27:21 +0100 | [diff] [blame] | 249 | ++i; |
| 250 | } |
| 251 | } |
| 252 | } |
| 253 | } // namespace experimental |
| 254 | |
| 255 | struct CLConcatenateLayer::Impl |
| 256 | { |
Georgios Pinitas | 09cad72 | 2020-07-22 12:11:20 +0100 | [diff] [blame] | 257 | std::vector<const ICLTensor *> srcs{}; |
| 258 | ICLTensor *dst{ nullptr }; |
| 259 | unsigned int num_inputs{ 0 }; |
| 260 | unsigned int axis{ 0 }; |
| 261 | std::unique_ptr<experimental::CLConcatenation> op{ nullptr }; |
Michele Di Giorgio | f932d2c | 2020-07-06 11:27:21 +0100 | [diff] [blame] | 262 | }; |
| 263 | |
| 264 | CLConcatenateLayer::CLConcatenateLayer() |
| 265 | : _impl(support::cpp14::make_unique<Impl>()) |
| 266 | { |
| 267 | } |
| 268 | |
| 269 | CLConcatenateLayer::CLConcatenateLayer(CLConcatenateLayer &&) = default; |
| 270 | |
| 271 | CLConcatenateLayer &CLConcatenateLayer::operator=(CLConcatenateLayer &&) = default; |
| 272 | |
| 273 | CLConcatenateLayer::~CLConcatenateLayer() = default; |
| 274 | |
| 275 | void CLConcatenateLayer::configure(std::vector<const ICLTensor *> &inputs_vector, ICLTensor *output, size_t axis) |
| 276 | { |
| 277 | configure(CLKernelLibrary::get().get_compile_context(), inputs_vector, output, axis); |
| 278 | } |
| 279 | |
| 280 | void CLConcatenateLayer::configure(const CLCompileContext &compile_context, std::vector<const ICLTensor *> &inputs_vector, ICLTensor *output, size_t axis) |
| 281 | { |
| 282 | ARM_COMPUTE_ERROR_ON(output == nullptr); |
| 283 | |
| 284 | _impl->srcs = inputs_vector; |
| 285 | _impl->dst = output; |
| 286 | _impl->axis = axis; |
| 287 | _impl->num_inputs = inputs_vector.size(); |
Georgios Pinitas | 09cad72 | 2020-07-22 12:11:20 +0100 | [diff] [blame] | 288 | _impl->op = arm_compute::support::cpp14::make_unique<experimental::CLConcatenation>(); |
Michele Di Giorgio | f932d2c | 2020-07-06 11:27:21 +0100 | [diff] [blame] | 289 | |
| 290 | std::vector<ITensorInfo *> inputs_vector_info; |
| 291 | for(unsigned int i = 0; i < inputs_vector.size(); ++i) |
| 292 | { |
| 293 | ARM_COMPUTE_ERROR_ON_NULLPTR(inputs_vector.at(i)); |
| 294 | inputs_vector_info.emplace_back(inputs_vector.at(i)->info()); |
| 295 | } |
| 296 | _impl->op->configure(compile_context, inputs_vector_info, _impl->dst->info(), axis); |
| 297 | } |
| 298 | |
| 299 | Status CLConcatenateLayer::validate(const std::vector<const ITensorInfo *> &inputs_vector, const ITensorInfo *output, size_t axis) |
| 300 | { |
Georgios Pinitas | 09cad72 | 2020-07-22 12:11:20 +0100 | [diff] [blame] | 301 | return experimental::CLConcatenation::validate(inputs_vector, output, axis); |
Michele Di Giorgio | f932d2c | 2020-07-06 11:27:21 +0100 | [diff] [blame] | 302 | } |
| 303 | |
Georgios Pinitas | e29acf1 | 2018-07-16 14:40:09 +0100 | [diff] [blame] | 304 | void CLConcatenateLayer::run() |
| 305 | { |
Georgios Pinitas | 0499dff | 2020-07-31 22:21:38 +0100 | [diff] [blame] | 306 | ITensorPack pack; |
Michele Di Giorgio | f932d2c | 2020-07-06 11:27:21 +0100 | [diff] [blame] | 307 | for(unsigned i = 0; i < _impl->num_inputs; ++i) |
Pablo Tello | 6a14adb | 2019-03-05 17:33:08 +0000 | [diff] [blame] | 308 | { |
Georgios Pinitas | 0499dff | 2020-07-31 22:21:38 +0100 | [diff] [blame] | 309 | pack.add_tensor(TensorType::ACL_SRC_VEC + i, _impl->srcs.at(i)); |
Pablo Tello | 6a14adb | 2019-03-05 17:33:08 +0000 | [diff] [blame] | 310 | } |
Georgios Pinitas | 0499dff | 2020-07-31 22:21:38 +0100 | [diff] [blame] | 311 | pack.add_tensor(TensorType::ACL_DST, _impl->dst); |
Michele Di Giorgio | f932d2c | 2020-07-06 11:27:21 +0100 | [diff] [blame] | 312 | |
Georgios Pinitas | 0499dff | 2020-07-31 22:21:38 +0100 | [diff] [blame] | 313 | _impl->op->run(pack); |
Georgios Pinitas | e29acf1 | 2018-07-16 14:40:09 +0100 | [diff] [blame] | 314 | } |
| 315 | } // namespace arm_compute |