Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 1 | // |
Teresa Charlin | 588cbdf | 2022-01-19 15:55:37 +0000 | [diff] [blame] | 2 | // Copyright © 2017 Arm Ltd and Contributors. All rights reserved. |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
Jim Flynn | 6905941 | 2019-05-17 13:03:57 +0100 | [diff] [blame] | 5 | #include "ClConcatWorkload.hpp" |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 6 | #include "ClWorkloadUtils.hpp" |
| 7 | #include <aclCommon/ArmComputeTensorUtils.hpp> |
Jan Eilers | 3c9e045 | 2020-04-10 13:00:44 +0100 | [diff] [blame] | 8 | #include <armnn/utility/PolymorphicDowncast.hpp> |
Colm Donelan | 0c47974 | 2021-12-10 12:43:54 +0000 | [diff] [blame] | 9 | #include <armnn/backends/TensorHandle.hpp> |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 10 | #include <cl/ClTensorHandle.hpp> |
| 11 | #include <cl/ClLayerSupport.hpp> |
| 12 | |
Derek Lamberti | 0790dce | 2019-04-15 18:37:35 +0100 | [diff] [blame] | 13 | #include <arm_compute/core/Types.h> |
| 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 | { |
Keith Davis | bcd860a | 2021-08-05 14:20:33 +0100 | [diff] [blame] | 21 | size_t CalcAxis(const OriginsDescriptor& descriptor) |
Derek Lamberti | 0790dce | 2019-04-15 18:37:35 +0100 | [diff] [blame] | 22 | { |
Keith Davis | bcd860a | 2021-08-05 14:20:33 +0100 | [diff] [blame] | 23 | return (descriptor.GetNumDimensions() - descriptor.GetConcatAxis()) - 1; |
Derek Lamberti | 0790dce | 2019-04-15 18:37:35 +0100 | [diff] [blame] | 24 | } |
| 25 | } //namespace |
| 26 | |
Jim Flynn | 6905941 | 2019-05-17 13:03:57 +0100 | [diff] [blame] | 27 | arm_compute::Status ClConcatWorkloadValidate(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 | std::vector<arm_compute::TensorInfo> aclInputs; |
| 32 | for (const TensorInfo* input : inputs) |
| 33 | { |
| 34 | arm_compute::TensorInfo aclInputInfo = BuildArmComputeTensorInfo(*input, armnn::DataLayout::NCHW); |
| 35 | aclInputs.emplace_back(aclInputInfo); |
| 36 | } |
| 37 | const arm_compute::TensorInfo aclOutputInfo = BuildArmComputeTensorInfo(output); |
Teresa Charlin | 552ee4d | 2020-07-16 12:44:16 +0100 | [diff] [blame] | 38 | std::vector<const arm_compute::ITensorInfo*> aclInputPtrs; |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 39 | for (arm_compute::ITensorInfo& input : aclInputs) |
| 40 | { |
| 41 | aclInputPtrs.emplace_back(&input); |
| 42 | } |
| 43 | |
Derek Lamberti | 0790dce | 2019-04-15 18:37:35 +0100 | [diff] [blame] | 44 | size_t aclAxis = CalcAxis(descriptor); |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 45 | return arm_compute::CLConcatenateLayer::validate(aclInputPtrs, &aclOutputInfo, aclAxis); |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 46 | } |
| 47 | |
Sadik Armagan | e944475 | 2020-12-02 11:28:58 +0000 | [diff] [blame] | 48 | ClConcatWorkload::ClConcatWorkload(const ConcatQueueDescriptor& descriptor, |
| 49 | const WorkloadInfo& info, |
| 50 | const arm_compute::CLCompileContext& clCompileContext) |
Teresa Charlin | 588cbdf | 2022-01-19 15:55:37 +0000 | [diff] [blame] | 51 | : ClBaseWorkload<ConcatQueueDescriptor>(descriptor, info) |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 52 | { |
Keith Davis | bcd860a | 2021-08-05 14:20:33 +0100 | [diff] [blame] | 53 | // Report Profiling Details |
| 54 | ARMNN_REPORT_PROFILING_WORKLOAD_DESC("ClConcatWorkload_Construct", |
| 55 | descriptor.m_Parameters, |
| 56 | info, |
| 57 | this->GetGuid()); |
| 58 | |
Derek Lamberti | 0790dce | 2019-04-15 18:37:35 +0100 | [diff] [blame] | 59 | bool allInputsAreSubtensors = true; |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 60 | |
Derek Lamberti | 0790dce | 2019-04-15 18:37:35 +0100 | [diff] [blame] | 61 | // Check that all inputs are sub-tensors |
| 62 | for (auto input : descriptor.m_Inputs) |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 63 | { |
Derek Lamberti | 0790dce | 2019-04-15 18:37:35 +0100 | [diff] [blame] | 64 | if (!input->GetParent()) |
| 65 | { |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 66 | // 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] | 67 | allInputsAreSubtensors = false; |
| 68 | break; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | if (allInputsAreSubtensors) |
| 73 | { |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 74 | // Can skip configuring the concat function since it's not executed |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 75 | return; |
| 76 | } |
| 77 | |
Teresa Charlin | 552ee4d | 2020-07-16 12:44:16 +0100 | [diff] [blame] | 78 | std::vector<const arm_compute::ICLTensor *> aclInputs; |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 79 | for (auto input : m_Data.m_Inputs) |
| 80 | { |
Jan Eilers | 3c9e045 | 2020-04-10 13:00:44 +0100 | [diff] [blame] | 81 | arm_compute::ICLTensor& aclInput = armnn::PolymorphicPointerDowncast<IClTensorHandle>(input)->GetTensor(); |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 82 | aclInputs.emplace_back(&aclInput); |
| 83 | } |
Jan Eilers | 3c9e045 | 2020-04-10 13:00:44 +0100 | [diff] [blame] | 84 | |
| 85 | arm_compute::ICLTensor& output = |
| 86 | armnn::PolymorphicPointerDowncast<IClTensorHandle>(m_Data.m_Outputs[0])->GetTensor(); |
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 | // Create the layer function |
Matthew Bentham | 9b3e738 | 2020-02-05 21:39:55 +0000 | [diff] [blame] | 89 | auto layer = std::make_unique<arm_compute::CLConcatenateLayer>(); |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 90 | |
Kevin May | 9f6862d | 2021-10-22 15:42:28 +0100 | [diff] [blame] | 91 | { |
| 92 | ARMNN_SCOPED_PROFILING_EVENT(Compute::Undefined, "ClConcatWorkload_configure"); |
| 93 | // Configure input and output tensors |
| 94 | size_t aclAxis = CalcAxis(descriptor.m_Parameters); |
| 95 | layer->configure(clCompileContext, aclInputs, &output, aclAxis); |
| 96 | } |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 97 | |
Derek Lamberti | 0790dce | 2019-04-15 18:37:35 +0100 | [diff] [blame] | 98 | // Prepare |
Matthew Bentham | 9b3e738 | 2020-02-05 21:39:55 +0000 | [diff] [blame] | 99 | layer->prepare(); |
| 100 | m_Layer = std::move(layer); |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 101 | } |
| 102 | |
Jim Flynn | 6905941 | 2019-05-17 13:03:57 +0100 | [diff] [blame] | 103 | void ClConcatWorkload::Execute() const |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 104 | { |
Derek Lamberti | 0790dce | 2019-04-15 18:37:35 +0100 | [diff] [blame] | 105 | if (m_Layer) |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 106 | { |
Keith Davis | bcd860a | 2021-08-05 14:20:33 +0100 | [diff] [blame] | 107 | ARMNN_SCOPED_PROFILING_EVENT_CL_GUID("ClConcatWorkload_Execute", this->GetGuid()); |
Derek Lamberti | 0790dce | 2019-04-15 18:37:35 +0100 | [diff] [blame] | 108 | m_Layer->run(); |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 109 | } |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 110 | } |
| 111 | |
Matthew Bentham | 9b3e738 | 2020-02-05 21:39:55 +0000 | [diff] [blame] | 112 | } //namespace armnn |