Matthew Jackson | 87f65ea | 2019-08-01 10:01:34 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | #include "NeonStackWorkload.hpp" |
| 6 | #include "NeonWorkloadUtils.hpp" |
| 7 | |
| 8 | #include <aclCommon/ArmComputeTensorUtils.hpp> |
Matthew Sloyan | 171214c | 2020-09-09 09:07:37 +0100 | [diff] [blame] | 9 | #include <armnn/utility/NumericCast.hpp> |
Jan Eilers | 3c9e045 | 2020-04-10 13:00:44 +0100 | [diff] [blame] | 10 | #include <armnn/utility/PolymorphicDowncast.hpp> |
James Conroy | 1f58f03 | 2021-04-27 17:13:27 +0100 | [diff] [blame] | 11 | #include <backendsCommon/TensorHandle.hpp> |
Matthew Jackson | 87f65ea | 2019-08-01 10:01:34 +0100 | [diff] [blame] | 12 | #include <neon/NeonTensorHandle.hpp> |
| 13 | |
Matthew Jackson | 87f65ea | 2019-08-01 10:01:34 +0100 | [diff] [blame] | 14 | namespace armnn |
| 15 | { |
| 16 | using namespace armcomputetensorutils; |
| 17 | |
| 18 | namespace |
| 19 | { |
| 20 | int CalcAxis(const unsigned int axis, const unsigned int inputDimensions) |
| 21 | { |
Matthew Sloyan | 171214c | 2020-09-09 09:07:37 +0100 | [diff] [blame] | 22 | const int intAxis = armnn::numeric_cast<int>(axis); |
| 23 | return armnn::numeric_cast<int>(inputDimensions) - intAxis; |
Matthew Jackson | 87f65ea | 2019-08-01 10:01:34 +0100 | [diff] [blame] | 24 | } |
| 25 | } //namespace |
| 26 | |
| 27 | arm_compute::Status NeonStackWorkloadValidate(const std::vector<const TensorInfo*>& inputs, |
| 28 | const TensorInfo& output, |
| 29 | const StackDescriptor& descriptor) |
| 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 | |
| 38 | std::vector<arm_compute::ITensorInfo*> aclInputPtrs; |
| 39 | for (arm_compute::ITensorInfo& input : aclInputs) |
| 40 | { |
| 41 | aclInputPtrs.emplace_back(&input); |
| 42 | } |
| 43 | |
| 44 | const arm_compute::TensorInfo aclOutputInfo = BuildArmComputeTensorInfo(output); |
| 45 | int aclAxis = CalcAxis(descriptor.m_Axis, descriptor.m_InputShape.GetNumDimensions()); |
| 46 | return arm_compute::NEStackLayer::validate(aclInputPtrs, aclAxis, &aclOutputInfo); |
| 47 | } |
| 48 | |
| 49 | NeonStackWorkload::NeonStackWorkload(const StackQueueDescriptor& descriptor, const WorkloadInfo& info) |
| 50 | : BaseWorkload<StackQueueDescriptor>(descriptor, info) |
| 51 | { |
Keith Davis | 2d0679f | 2021-08-05 11:35:00 +0100 | [diff] [blame] | 52 | // Report Profiling Details |
| 53 | ARMNN_REPORT_PROFILING_WORKLOAD_DESC("NeonStackWorkload_Construct", |
| 54 | descriptor.m_Parameters, |
| 55 | info, |
| 56 | this->GetGuid()); |
| 57 | |
Matthew Jackson | 87f65ea | 2019-08-01 10:01:34 +0100 | [diff] [blame] | 58 | std::vector<arm_compute::ITensor*> aclInputs; |
| 59 | for (auto input : m_Data.m_Inputs) |
| 60 | { |
Jan Eilers | 3c9e045 | 2020-04-10 13:00:44 +0100 | [diff] [blame] | 61 | arm_compute::ITensor& aclInput = PolymorphicPointerDowncast<IAclTensorHandle>(input)->GetTensor(); |
Matthew Jackson | 87f65ea | 2019-08-01 10:01:34 +0100 | [diff] [blame] | 62 | aclInputs.emplace_back(&aclInput); |
| 63 | } |
Jan Eilers | 3c9e045 | 2020-04-10 13:00:44 +0100 | [diff] [blame] | 64 | arm_compute::ITensor& output = PolymorphicPointerDowncast<IAclTensorHandle>( |
Matthew Jackson | 87f65ea | 2019-08-01 10:01:34 +0100 | [diff] [blame] | 65 | m_Data.m_Outputs[0])->GetTensor(); |
| 66 | |
| 67 | m_Layer.reset(new arm_compute::NEStackLayer()); |
| 68 | int aclAxis = CalcAxis(descriptor.m_Parameters.m_Axis, descriptor.m_Parameters.m_InputShape.GetNumDimensions()); |
| 69 | m_Layer->configure(aclInputs, aclAxis, &output); |
| 70 | } |
| 71 | |
| 72 | void NeonStackWorkload::Execute() const |
| 73 | { |
| 74 | if (m_Layer) |
| 75 | { |
Keith Davis | 2d0679f | 2021-08-05 11:35:00 +0100 | [diff] [blame] | 76 | ARMNN_SCOPED_PROFILING_EVENT_NEON_GUID("NeonStackWorkload_Execute", this->GetGuid()); |
Matthew Jackson | 87f65ea | 2019-08-01 10:01:34 +0100 | [diff] [blame] | 77 | m_Layer->run(); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | } //namespace armnn |