Georgios Pinitas | e29acf1 | 2018-07-16 14:40:09 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 ARM Limited. |
| 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 | |
| 26 | #include "arm_compute/runtime/CL/functions/CLDepthConcatenateLayer.h" |
| 27 | #include "arm_compute/runtime/CL/functions/CLWidthConcatenateLayer.h" |
| 28 | |
| 29 | #include "arm_compute/core/CL/ICLTensor.h" |
| 30 | #include "arm_compute/core/Error.h" |
| 31 | #include "arm_compute/core/TensorInfo.h" |
| 32 | #include "arm_compute/core/Types.h" |
| 33 | #include "support/ToolchainSupport.h" |
| 34 | |
| 35 | namespace arm_compute |
| 36 | { |
| 37 | CLConcatenateLayer::CLConcatenateLayer() |
| 38 | : _concat_function(nullptr) |
| 39 | { |
| 40 | } |
| 41 | |
Georgios Pinitas | ae54e02 | 2018-07-16 15:41:27 +0100 | [diff] [blame] | 42 | void CLConcatenateLayer::configure(const std::vector<ICLTensor *> &inputs_vector, ICLTensor *output, DataLayoutDimension axis) |
Georgios Pinitas | e29acf1 | 2018-07-16 14:40:09 +0100 | [diff] [blame] | 43 | { |
| 44 | ARM_COMPUTE_ERROR_ON(output == nullptr); |
| 45 | |
| 46 | switch(get_data_layout_dimension_index(output->info()->data_layout(), axis)) |
| 47 | { |
| 48 | case 0: |
| 49 | { |
| 50 | auto func = support::cpp14::make_unique<CLWidthConcatenateLayer>(); |
Georgios Pinitas | ae54e02 | 2018-07-16 15:41:27 +0100 | [diff] [blame] | 51 | func->configure(inputs_vector, output); |
Georgios Pinitas | e29acf1 | 2018-07-16 14:40:09 +0100 | [diff] [blame] | 52 | _concat_function = std::move(func); |
| 53 | break; |
| 54 | } |
| 55 | case 2: |
| 56 | { |
| 57 | auto func = support::cpp14::make_unique<CLDepthConcatenateLayer>(); |
Georgios Pinitas | ae54e02 | 2018-07-16 15:41:27 +0100 | [diff] [blame] | 58 | func->configure(inputs_vector, output); |
Georgios Pinitas | e29acf1 | 2018-07-16 14:40:09 +0100 | [diff] [blame] | 59 | _concat_function = std::move(func); |
| 60 | break; |
| 61 | } |
| 62 | default: |
| 63 | ARM_COMPUTE_ERROR("Concatenation is supported across width and depth only!"); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | Status CLConcatenateLayer::validate(const std::vector<ITensorInfo *> &inputs_vector, const ITensorInfo *output, DataLayoutDimension axis) |
| 68 | { |
| 69 | ARM_COMPUTE_RETURN_ERROR_ON(output == nullptr); |
| 70 | |
| 71 | switch(get_data_layout_dimension_index(output->data_layout(), axis)) |
| 72 | { |
| 73 | case 0: |
| 74 | ARM_COMPUTE_RETURN_ON_ERROR(CLWidthConcatenateLayer::validate(inputs_vector, output)); |
| 75 | break; |
| 76 | case 2: |
| 77 | ARM_COMPUTE_RETURN_ON_ERROR(CLDepthConcatenateLayer::validate(inputs_vector, output)); |
| 78 | break; |
| 79 | default: |
| 80 | ARM_COMPUTE_RETURN_ERROR_MSG("Concatenation is supported across width and depth only!"); |
| 81 | } |
| 82 | return Status{}; |
| 83 | } |
| 84 | |
| 85 | void CLConcatenateLayer::run() |
| 86 | { |
| 87 | ARM_COMPUTE_ERROR_ON(_concat_function == nullptr); |
| 88 | _concat_function->run(); |
| 89 | } |
| 90 | } // namespace arm_compute |