Sadik Armagan | a274748 | 2021-02-09 10:28:54 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2021 Arm Ltd and Contributors. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "ClReduceWorkload.hpp" |
| 7 | |
| 8 | #include <cl/ClTensorHandle.hpp> |
| 9 | #include <aclCommon/ArmComputeUtils.hpp> |
| 10 | #include <aclCommon/ArmComputeTensorUtils.hpp> |
| 11 | |
| 12 | #include "ClWorkloadUtils.hpp" |
| 13 | |
| 14 | namespace armnn |
| 15 | { |
| 16 | using namespace armcomputetensorutils; |
| 17 | |
| 18 | arm_compute::Status ClReduceWorkloadValidate(const TensorInfo& input, |
| 19 | const TensorInfo& output, |
Keith Davis | bcd860a | 2021-08-05 14:20:33 +0100 | [diff] [blame] | 20 | const ReduceDescriptor& descriptor) |
Sadik Armagan | a274748 | 2021-02-09 10:28:54 +0000 | [diff] [blame] | 21 | { |
Keith Davis | bcd860a | 2021-08-05 14:20:33 +0100 | [diff] [blame] | 22 | if (descriptor.m_vAxis.size() == 1 || descriptor.m_vAxis.empty()) |
Matthew Sloyan | ae12306 | 2021-05-07 14:18:01 +0000 | [diff] [blame] | 23 | { |
Keith Davis | bcd860a | 2021-08-05 14:20:33 +0100 | [diff] [blame] | 24 | const arm_compute::TensorInfo aclInputInfo = armcomputetensorutils::BuildArmComputeTensorInfo(input); |
Matthew Sloyan | 5fc0fd6 | 2021-05-03 12:22:03 +0100 | [diff] [blame] | 25 | const arm_compute::TensorInfo aclOutputInfo = armcomputetensorutils::BuildArmComputeTensorInfo(output); |
| 26 | |
| 27 | arm_compute::Coordinates coords = BuildArmComputeReductionCoordinates(aclInputInfo.num_dimensions(), |
| 28 | input.GetNumDimensions(), |
Keith Davis | bcd860a | 2021-08-05 14:20:33 +0100 | [diff] [blame] | 29 | descriptor.m_vAxis); |
Matthew Sloyan | 5fc0fd6 | 2021-05-03 12:22:03 +0100 | [diff] [blame] | 30 | |
| 31 | return arm_compute::CLReductionOperation::validate(&aclInputInfo, |
| 32 | &aclOutputInfo, |
| 33 | static_cast<unsigned int>(coords[0]), |
Keith Davis | bcd860a | 2021-08-05 14:20:33 +0100 | [diff] [blame] | 34 | ConvertReductionOperationToAcl(descriptor), |
| 35 | descriptor.m_KeepDims); |
Matthew Sloyan | ae12306 | 2021-05-07 14:18:01 +0000 | [diff] [blame] | 36 | } |
Matthew Sloyan | 5fc0fd6 | 2021-05-03 12:22:03 +0100 | [diff] [blame] | 37 | else |
| 38 | { |
| 39 | // Validate layer if there are multiple axes. |
| 40 | arm_compute::Status status; |
Keith Davis | bcd860a | 2021-08-05 14:20:33 +0100 | [diff] [blame] | 41 | IS_MULTI_AXES_REDUCE_SUPPORTED(ClReduceWorkloadValidate, input, descriptor, status); |
Matthew Sloyan | 5fc0fd6 | 2021-05-03 12:22:03 +0100 | [diff] [blame] | 42 | return status; |
| 43 | } |
Sadik Armagan | a274748 | 2021-02-09 10:28:54 +0000 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | ClReduceWorkload::ClReduceWorkload(const ReduceQueueDescriptor& descriptor, const WorkloadInfo& info) |
| 47 | : BaseWorkload<ReduceQueueDescriptor>(descriptor, info) |
| 48 | { |
Keith Davis | bcd860a | 2021-08-05 14:20:33 +0100 | [diff] [blame] | 49 | // Report Profiling Details |
| 50 | ARMNN_REPORT_PROFILING_WORKLOAD_DESC("ClReduceWorkload_Construct", |
| 51 | descriptor.m_Parameters, |
| 52 | info, |
| 53 | this->GetGuid()); |
| 54 | |
Sadik Armagan | a274748 | 2021-02-09 10:28:54 +0000 | [diff] [blame] | 55 | m_Data.ValidateInputsOutputs("ClReduceWorkload", 1, 1); |
| 56 | |
| 57 | arm_compute::ICLTensor& input = static_cast<IClTensorHandle*>(m_Data.m_Inputs[0])->GetTensor(); |
| 58 | arm_compute::ICLTensor& output = static_cast<IClTensorHandle*>(m_Data.m_Outputs[0])->GetTensor(); |
| 59 | |
| 60 | arm_compute::Coordinates coords = BuildArmComputeReductionCoordinates(input.info()->num_dimensions(), |
| 61 | info.m_InputTensorInfos[0].GetNumDimensions(), |
| 62 | m_Data.m_Parameters.m_vAxis); |
| 63 | m_Layer.configure(&input, |
| 64 | &output, |
| 65 | static_cast<unsigned int>(coords[0]), |
| 66 | ConvertReductionOperationToAcl(m_Data.m_Parameters), |
| 67 | m_Data.m_Parameters.m_KeepDims); |
| 68 | } |
| 69 | |
| 70 | void ClReduceWorkload::Execute() const |
| 71 | { |
Keith Davis | bcd860a | 2021-08-05 14:20:33 +0100 | [diff] [blame] | 72 | ARMNN_SCOPED_PROFILING_EVENT_CL_GUID("ClReduceWorkload_Execute", this->GetGuid()); |
Sadik Armagan | a274748 | 2021-02-09 10:28:54 +0000 | [diff] [blame] | 73 | m_Layer.run(); |
| 74 | } |
| 75 | |
| 76 | } //namespace armnn |