Matthew Jackson | d516610 | 2019-07-31 14:06:28 +0100 | [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. |
Matthew Jackson | d516610 | 2019-07-31 14:06:28 +0100 | [diff] [blame] | 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> |
Colm Donelan | 0c47974 | 2021-12-10 12:43:54 +0000 | [diff] [blame] | 10 | #include <armnn/backends/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) |
Teresa Charlin | 588cbdf | 2022-01-19 15:55:37 +0000 | [diff] [blame] | 50 | : ClBaseWorkload<StackQueueDescriptor>(descriptor, info) |
Matthew Jackson | d516610 | 2019-07-31 14:06:28 +0100 | [diff] [blame] | 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()); |
Kevin May | 9f6862d | 2021-10-22 15:42:28 +0100 | [diff] [blame] | 69 | { |
| 70 | ARMNN_SCOPED_PROFILING_EVENT(Compute::Undefined, "ClStackWorkload_configure"); |
| 71 | m_Layer->configure(clCompileContext, aclInputs, aclAxis, &output); |
| 72 | } |
Matthew Jackson | d516610 | 2019-07-31 14:06:28 +0100 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | void ClStackWorkload::Execute() const |
| 76 | { |
| 77 | if (m_Layer) |
| 78 | { |
Keith Davis | bcd860a | 2021-08-05 14:20:33 +0100 | [diff] [blame] | 79 | ARMNN_SCOPED_PROFILING_EVENT_CL_GUID("ClStackWorkload_Execute", this->GetGuid()); |
Matthew Jackson | d516610 | 2019-07-31 14:06:28 +0100 | [diff] [blame] | 80 | m_Layer->run(); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | } //namespace armnn |