Matthew Jackson | d516610 | 2019-07-31 14:06:28 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | #include "ClStackWorkload.hpp" |
| 6 | #include "ClWorkloadUtils.hpp" |
| 7 | #include <aclCommon/ArmComputeTensorUtils.hpp> |
Matthew Sloyan | 171214c | 2020-09-09 09:07:37 +0100 | [diff] [blame] | 8 | #include <armnn/utility/NumericCast.hpp> |
Jan Eilers | 3c9e045 | 2020-04-10 13:00:44 +0100 | [diff] [blame] | 9 | #include <armnn/utility/PolymorphicDowncast.hpp> |
James Conroy | 1f58f03 | 2021-04-27 17:13:27 +0100 | [diff] [blame] | 10 | #include <backendsCommon/TensorHandle.hpp> |
Matthew Jackson | d516610 | 2019-07-31 14:06:28 +0100 | [diff] [blame] | 11 | #include <cl/ClTensorHandle.hpp> |
| 12 | #include <cl/ClLayerSupport.hpp> |
| 13 | |
| 14 | #include <arm_compute/core/Types.h> |
| 15 | |
Matthew Jackson | d516610 | 2019-07-31 14:06:28 +0100 | [diff] [blame] | 16 | namespace armnn |
| 17 | { |
| 18 | using namespace armcomputetensorutils; |
| 19 | |
| 20 | namespace |
| 21 | { |
| 22 | int CalcAxis(const unsigned int axis, const unsigned int inputDimensions) |
| 23 | { |
Matthew Sloyan | 171214c | 2020-09-09 09:07:37 +0100 | [diff] [blame] | 24 | const int intAxis = armnn::numeric_cast<int>(axis); |
| 25 | return armnn::numeric_cast<int>(inputDimensions) - intAxis; |
Matthew Jackson | d516610 | 2019-07-31 14:06:28 +0100 | [diff] [blame] | 26 | } |
| 27 | } //namespace |
| 28 | |
| 29 | arm_compute::Status ClStackWorkloadValidate(const std::vector<const TensorInfo*>& inputs, |
| 30 | const TensorInfo& output, |
| 31 | const StackDescriptor& descriptor) |
| 32 | { |
| 33 | std::vector<arm_compute::ITensorInfo*> aclInputPtrs; |
| 34 | arm_compute::TensorInfo aclInputInfo; |
| 35 | for (const TensorInfo* input : inputs) |
| 36 | { |
| 37 | aclInputInfo = BuildArmComputeTensorInfo(*input); |
| 38 | aclInputPtrs.emplace_back(&aclInputInfo); |
| 39 | } |
| 40 | const arm_compute::TensorInfo aclOutputInfo = BuildArmComputeTensorInfo(output); |
| 41 | |
| 42 | int aclAxis = CalcAxis(descriptor.m_Axis, descriptor.m_InputShape.GetNumDimensions()); |
| 43 | |
| 44 | return arm_compute::CLStackLayer::validate(aclInputPtrs, aclAxis, &aclOutputInfo); |
| 45 | } |
| 46 | |
Sadik Armagan | e944475 | 2020-12-02 11:28:58 +0000 | [diff] [blame] | 47 | ClStackWorkload::ClStackWorkload(const StackQueueDescriptor& descriptor, |
| 48 | const WorkloadInfo& info, |
| 49 | const arm_compute::CLCompileContext& clCompileContext) |
Matthew Jackson | d516610 | 2019-07-31 14:06:28 +0100 | [diff] [blame] | 50 | : BaseWorkload<StackQueueDescriptor>(descriptor, info) |
| 51 | { |
Keith Davis | bcd860a | 2021-08-05 14:20:33 +0100 | [diff] [blame] | 52 | // Report Profiling Details |
| 53 | ARMNN_REPORT_PROFILING_WORKLOAD_DESC("ClStackWorkload_Construct", |
| 54 | descriptor.m_Parameters, |
| 55 | info, |
| 56 | this->GetGuid()); |
| 57 | |
Matthew Jackson | d516610 | 2019-07-31 14:06:28 +0100 | [diff] [blame] | 58 | std::vector<arm_compute::ICLTensor*> 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::ICLTensor& aclInput = armnn::PolymorphicPointerDowncast<IClTensorHandle>(input)->GetTensor(); |
Matthew Jackson | d516610 | 2019-07-31 14:06:28 +0100 | [diff] [blame] | 62 | aclInputs.emplace_back(&aclInput); |
| 63 | } |
Jan Eilers | 3c9e045 | 2020-04-10 13:00:44 +0100 | [diff] [blame] | 64 | arm_compute::ICLTensor& output = armnn::PolymorphicPointerDowncast<IClTensorHandle>( |
Matthew Jackson | d516610 | 2019-07-31 14:06:28 +0100 | [diff] [blame] | 65 | m_Data.m_Outputs[0])->GetTensor(); |
| 66 | |
| 67 | m_Layer.reset(new arm_compute::CLStackLayer()); |
| 68 | int aclAxis = CalcAxis(descriptor.m_Parameters.m_Axis, descriptor.m_Parameters.m_InputShape.GetNumDimensions()); |
Sadik Armagan | e944475 | 2020-12-02 11:28:58 +0000 | [diff] [blame] | 69 | m_Layer->configure(clCompileContext, aclInputs, aclAxis, &output); |
Matthew Jackson | d516610 | 2019-07-31 14:06:28 +0100 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | void ClStackWorkload::Execute() const |
| 73 | { |
| 74 | if (m_Layer) |
| 75 | { |
Keith Davis | bcd860a | 2021-08-05 14:20:33 +0100 | [diff] [blame] | 76 | ARMNN_SCOPED_PROFILING_EVENT_CL_GUID("ClStackWorkload_Execute", this->GetGuid()); |
Matthew Jackson | d516610 | 2019-07-31 14:06:28 +0100 | [diff] [blame] | 77 | m_Layer->run(); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | } //namespace armnn |