Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
Jim Flynn | 39d487d | 2019-05-17 15:44:36 +0100 | [diff] [blame] | 6 | #include "NeonConcatWorkload.hpp" |
Matthew Bentham | d80a712 | 2019-01-08 17:52:37 +0000 | [diff] [blame] | 7 | |
| 8 | #include "NeonWorkloadUtils.hpp" |
| 9 | |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 10 | #include <aclCommon/ArmComputeTensorUtils.hpp> |
Jan Eilers | 3c9e045 | 2020-04-10 13:00:44 +0100 | [diff] [blame] | 11 | #include <armnn/utility/PolymorphicDowncast.hpp> |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 12 | #include <backendsCommon/CpuTensorHandle.hpp> |
| 13 | #include <neon/NeonTensorHandle.hpp> |
| 14 | |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 15 | namespace armnn |
| 16 | { |
| 17 | using namespace armcomputetensorutils; |
| 18 | |
Derek Lamberti | 0790dce | 2019-04-15 18:37:35 +0100 | [diff] [blame] | 19 | namespace |
| 20 | { |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 21 | size_t CalcAxis(const armnn::OriginsDescriptor& desc) |
Derek Lamberti | 0790dce | 2019-04-15 18:37:35 +0100 | [diff] [blame] | 22 | { |
| 23 | return (desc.GetNumDimensions() - desc.GetConcatAxis()) - 1; |
| 24 | } |
| 25 | } //namespace |
| 26 | |
Jim Flynn | 39d487d | 2019-05-17 15:44:36 +0100 | [diff] [blame] | 27 | arm_compute::Status NeonConcatWorkloadValidate(const std::vector<const TensorInfo*>& inputs, |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 28 | const TensorInfo& output, |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 29 | const OriginsDescriptor& descriptor) |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 30 | |
| 31 | { |
| 32 | std::vector<arm_compute::TensorInfo> aclInputs; |
| 33 | for (const TensorInfo* input : inputs) |
| 34 | { |
Derek Lamberti | 0790dce | 2019-04-15 18:37:35 +0100 | [diff] [blame] | 35 | arm_compute::TensorInfo aclInputInfo = BuildArmComputeTensorInfo(*input, armnn::DataLayout::NCHW); |
| 36 | aclInputs.emplace_back(aclInputInfo); |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 37 | } |
| 38 | const arm_compute::TensorInfo aclOutputInfo = BuildArmComputeTensorInfo(output); |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 39 | std::vector<arm_compute::ITensorInfo*> aclInputPtrs; |
| 40 | for (arm_compute::ITensorInfo& input : aclInputs) |
| 41 | { |
| 42 | aclInputPtrs.emplace_back(&input); |
| 43 | } |
| 44 | |
Derek Lamberti | 0790dce | 2019-04-15 18:37:35 +0100 | [diff] [blame] | 45 | size_t aclAxis = CalcAxis(descriptor); |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 46 | return arm_compute::NEConcatenateLayer::validate(aclInputPtrs, &aclOutputInfo, aclAxis); |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 47 | } |
| 48 | |
Jim Flynn | 39d487d | 2019-05-17 15:44:36 +0100 | [diff] [blame] | 49 | NeonConcatWorkload::NeonConcatWorkload( |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 50 | const ConcatQueueDescriptor& descriptor, const WorkloadInfo& info) |
| 51 | : BaseWorkload<ConcatQueueDescriptor>(descriptor, info) |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 52 | { |
Derek Lamberti | 0790dce | 2019-04-15 18:37:35 +0100 | [diff] [blame] | 53 | bool allInputsAreSubtensors = true; |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 54 | |
Derek Lamberti | 0790dce | 2019-04-15 18:37:35 +0100 | [diff] [blame] | 55 | // Check that all inputs are sub-tensors |
| 56 | for (auto input : descriptor.m_Inputs) |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 57 | { |
Derek Lamberti | 0790dce | 2019-04-15 18:37:35 +0100 | [diff] [blame] | 58 | if (!input->GetParent()) |
| 59 | { |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 60 | // Non sub-tensor input found so we need to execute the concat function |
Derek Lamberti | 0790dce | 2019-04-15 18:37:35 +0100 | [diff] [blame] | 61 | allInputsAreSubtensors = false; |
| 62 | break; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | if (allInputsAreSubtensors) |
| 67 | { |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 68 | // Can skip configuring the concat function since it's not executed |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 69 | return; |
| 70 | } |
| 71 | |
| 72 | std::vector<arm_compute::ITensor *> aclInputs; |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 73 | for (auto input : m_Data.m_Inputs) |
| 74 | { |
Jan Eilers | 3c9e045 | 2020-04-10 13:00:44 +0100 | [diff] [blame] | 75 | arm_compute::ITensor& aclInput = armnn::PolymorphicPointerDowncast<IAclTensorHandle>(input)->GetTensor(); |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 76 | aclInputs.emplace_back(&aclInput); |
| 77 | } |
Jan Eilers | 3c9e045 | 2020-04-10 13:00:44 +0100 | [diff] [blame] | 78 | arm_compute::ITensor& output = armnn::PolymorphicPointerDowncast<IAclTensorHandle>( |
Derek Lamberti | 0790dce | 2019-04-15 18:37:35 +0100 | [diff] [blame] | 79 | m_Data.m_Outputs[0])->GetTensor(); |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 80 | |
Derek Lamberti | 0790dce | 2019-04-15 18:37:35 +0100 | [diff] [blame] | 81 | // Create the layer function |
| 82 | m_Layer.reset(new arm_compute::NEConcatenateLayer()); |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 83 | |
Derek Lamberti | 0790dce | 2019-04-15 18:37:35 +0100 | [diff] [blame] | 84 | // Configure input and output tensors |
| 85 | size_t aclAxis = CalcAxis(descriptor.m_Parameters); |
| 86 | m_Layer->configure(aclInputs, &output, aclAxis); |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 87 | |
Derek Lamberti | 0790dce | 2019-04-15 18:37:35 +0100 | [diff] [blame] | 88 | // Prepare |
Matthew Bentham | d80a712 | 2019-01-08 17:52:37 +0000 | [diff] [blame] | 89 | m_Layer->prepare(); |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 90 | } |
| 91 | |
Jim Flynn | 39d487d | 2019-05-17 15:44:36 +0100 | [diff] [blame] | 92 | void NeonConcatWorkload::Execute() const |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 93 | { |
Derek Lamberti | 0790dce | 2019-04-15 18:37:35 +0100 | [diff] [blame] | 94 | if (m_Layer) |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 95 | { |
Jim Flynn | 39d487d | 2019-05-17 15:44:36 +0100 | [diff] [blame] | 96 | ARMNN_SCOPED_PROFILING_EVENT_NEON("NeonConcatWorkload_Execute"); |
Matthew Bentham | d80a712 | 2019-01-08 17:52:37 +0000 | [diff] [blame] | 97 | m_Layer->run(); |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 98 | } |
| 99 | } |
| 100 | |
| 101 | } //namespace armnn |
| 102 | |