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, |
| 20 | const ReduceDescriptor& desc) |
| 21 | { |
Matthew Sloyan | 5fc0fd6 | 2021-05-03 12:22:03 +0100 | [diff] [blame] | 22 | if ( desc.m_vAxis.size()==1 || desc.m_vAxis.empty()) |
Matthew Sloyan | ae12306 | 2021-05-07 14:18:01 +0000 | [diff] [blame] | 23 | { |
Matthew Sloyan | 5fc0fd6 | 2021-05-03 12:22:03 +0100 | [diff] [blame] | 24 | const arm_compute::TensorInfo aclInputInfo = armcomputetensorutils::BuildArmComputeTensorInfo(input); |
| 25 | const arm_compute::TensorInfo aclOutputInfo = armcomputetensorutils::BuildArmComputeTensorInfo(output); |
| 26 | |
| 27 | arm_compute::Coordinates coords = BuildArmComputeReductionCoordinates(aclInputInfo.num_dimensions(), |
| 28 | input.GetNumDimensions(), |
| 29 | desc.m_vAxis); |
| 30 | |
| 31 | return arm_compute::CLReductionOperation::validate(&aclInputInfo, |
| 32 | &aclOutputInfo, |
| 33 | static_cast<unsigned int>(coords[0]), |
| 34 | ConvertReductionOperationToAcl(desc), |
| 35 | desc.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; |
| 41 | IS_MULTI_AXES_REDUCE_SUPPORTED(NeonReduceWorkloadValidate, input, desc, status); |
| 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 | { |
| 49 | m_Data.ValidateInputsOutputs("ClReduceWorkload", 1, 1); |
| 50 | |
| 51 | arm_compute::ICLTensor& input = static_cast<IClTensorHandle*>(m_Data.m_Inputs[0])->GetTensor(); |
| 52 | arm_compute::ICLTensor& output = static_cast<IClTensorHandle*>(m_Data.m_Outputs[0])->GetTensor(); |
| 53 | |
| 54 | arm_compute::Coordinates coords = BuildArmComputeReductionCoordinates(input.info()->num_dimensions(), |
| 55 | info.m_InputTensorInfos[0].GetNumDimensions(), |
| 56 | m_Data.m_Parameters.m_vAxis); |
| 57 | m_Layer.configure(&input, |
| 58 | &output, |
| 59 | static_cast<unsigned int>(coords[0]), |
| 60 | ConvertReductionOperationToAcl(m_Data.m_Parameters), |
| 61 | m_Data.m_Parameters.m_KeepDims); |
| 62 | } |
| 63 | |
| 64 | void ClReduceWorkload::Execute() const |
| 65 | { |
| 66 | ARMNN_SCOPED_PROFILING_EVENT_CL("ClReduceWorkload_Execute"); |
| 67 | m_Layer.run(); |
| 68 | } |
| 69 | |
| 70 | } //namespace armnn |