Michalis Spyrou | a9c4472 | 2019-04-05 17:18:36 +0100 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2019-2020 Arm Limited. |
Michalis Spyrou | a9c4472 | 2019-04-05 17:18:36 +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/GLES_COMPUTE/functions/GCConcatenateLayer.h" |
| 25 | |
| 26 | #include "arm_compute/core/Error.h" |
| 27 | #include "arm_compute/core/GLES_COMPUTE/IGCTensor.h" |
| 28 | #include "arm_compute/core/PixelValue.h" |
| 29 | #include "arm_compute/core/Types.h" |
| 30 | #include "arm_compute/core/utils/misc/ShapeCalculator.h" |
| 31 | #include "arm_compute/runtime/GLES_COMPUTE/GCScheduler.h" |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame^] | 32 | #include "src/core/helpers/AutoConfiguration.h" |
| 33 | |
Matthew Bentham | 9204646 | 2020-03-07 22:15:55 +0000 | [diff] [blame] | 34 | #include "support/MemorySupport.h" |
Michalis Spyrou | a9c4472 | 2019-04-05 17:18:36 +0100 | [diff] [blame] | 35 | |
| 36 | namespace arm_compute |
| 37 | { |
| 38 | GCConcatenateLayer::GCConcatenateLayer() |
| 39 | : _concat_kernels(), |
| 40 | _num_inputs(0), |
| 41 | _axis(Window::DimZ) |
| 42 | { |
| 43 | } |
| 44 | |
| 45 | void GCConcatenateLayer::configure(std::vector<IGCTensor *> inputs_vector, IGCTensor *output, size_t axis) |
| 46 | { |
| 47 | ARM_COMPUTE_ERROR_ON(inputs_vector.size() < 2); |
| 48 | |
| 49 | _num_inputs = inputs_vector.size(); |
| 50 | _axis = axis; |
| 51 | |
| 52 | TensorShape output_shape = arm_compute::misc::shape_calculator::calculate_concatenate_shape(inputs_vector, axis); |
| 53 | |
| 54 | // Output auto inizialitation if not yet initialized |
| 55 | auto_init_if_empty(*output->info(), output_shape, 1, inputs_vector[0]->info()->data_type()); |
| 56 | |
| 57 | unsigned int offset = 0; |
| 58 | switch(axis) |
| 59 | { |
| 60 | case Window::DimZ: |
| 61 | { |
| 62 | for(unsigned int i = 0; i < _num_inputs; ++i) |
| 63 | { |
| 64 | auto kernel = support::cpp14::make_unique<GCDepthConcatenateLayerKernel>(); |
| 65 | kernel->configure(inputs_vector.at(i), offset, output); |
| 66 | offset += inputs_vector.at(i)->info()->dimension(axis); |
| 67 | _concat_kernels.emplace_back(std::move(kernel)); |
| 68 | } |
| 69 | break; |
| 70 | } |
| 71 | default: |
| 72 | ARM_COMPUTE_ERROR("Axis not supported"); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | void GCConcatenateLayer::run() |
| 77 | { |
| 78 | for(auto &kernel : _concat_kernels) |
| 79 | { |
| 80 | GCScheduler::get().dispatch(*kernel, true); |
| 81 | } |
| 82 | } |
| 83 | } // namespace arm_compute |