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 "NeonReduceWorkload.hpp" |
| 7 | |
| 8 | #include <aclCommon/ArmComputeUtils.hpp> |
| 9 | #include <aclCommon/ArmComputeTensorUtils.hpp> |
| 10 | |
| 11 | #include <neon/NeonTensorHandle.hpp> |
| 12 | |
| 13 | #include "NeonWorkloadUtils.hpp" |
| 14 | |
| 15 | namespace armnn |
| 16 | { |
| 17 | using namespace armcomputetensorutils; |
| 18 | |
| 19 | arm_compute::Status NeonReduceWorkloadValidate(const TensorInfo& input, |
| 20 | const TensorInfo& output, |
| 21 | const ReduceDescriptor& desc) |
| 22 | { |
Matthew Sloyan | 5fc0fd6 | 2021-05-03 12:22:03 +0100 | [diff] [blame] | 23 | if ( desc.m_vAxis.size()==1 || desc.m_vAxis.empty()) |
Matthew Sloyan | ae12306 | 2021-05-07 14:18:01 +0000 | [diff] [blame] | 24 | { |
Matthew Sloyan | 5fc0fd6 | 2021-05-03 12:22:03 +0100 | [diff] [blame] | 25 | const arm_compute::TensorInfo aclInputInfo = armcomputetensorutils::BuildArmComputeTensorInfo(input); |
| 26 | const arm_compute::TensorInfo aclOutputInfo = armcomputetensorutils::BuildArmComputeTensorInfo(output); |
| 27 | |
| 28 | arm_compute::Coordinates coords = BuildArmComputeReductionCoordinates(aclInputInfo.num_dimensions(), |
| 29 | input.GetNumDimensions(), |
| 30 | desc.m_vAxis); |
| 31 | |
| 32 | return arm_compute::NEReductionOperation::validate(&aclInputInfo, |
| 33 | &aclOutputInfo, |
| 34 | static_cast<unsigned int>(coords[0]), |
| 35 | ConvertReductionOperationToAcl(desc), |
| 36 | desc.m_KeepDims); |
Matthew Sloyan | ae12306 | 2021-05-07 14:18:01 +0000 | [diff] [blame] | 37 | } |
Matthew Sloyan | 5fc0fd6 | 2021-05-03 12:22:03 +0100 | [diff] [blame] | 38 | else |
| 39 | { |
| 40 | // Validate layer if there are multiple axes. |
| 41 | arm_compute::Status status; |
| 42 | IS_MULTI_AXES_REDUCE_SUPPORTED(NeonReduceWorkloadValidate, input, desc, status); |
| 43 | return status; |
| 44 | } |
Sadik Armagan | a274748 | 2021-02-09 10:28:54 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | NeonReduceWorkload::NeonReduceWorkload(const ReduceQueueDescriptor& descriptor, const WorkloadInfo& info) |
| 48 | : BaseWorkload<ReduceQueueDescriptor>(descriptor, info) |
| 49 | { |
| 50 | m_Data.ValidateInputsOutputs("NeonReduceWorkload", 1, 1); |
| 51 | |
| 52 | arm_compute::ITensor& input = static_cast<IAclTensorHandle*>(m_Data.m_Inputs[0])->GetTensor(); |
| 53 | arm_compute::ITensor& output = static_cast<IAclTensorHandle*>(m_Data.m_Outputs[0])->GetTensor(); |
| 54 | |
| 55 | arm_compute::Coordinates coords = BuildArmComputeReductionCoordinates(input.info()->num_dimensions(), |
| 56 | info.m_InputTensorInfos[0].GetNumDimensions(), |
| 57 | m_Data.m_Parameters.m_vAxis); |
Matthew Sloyan | 5fc0fd6 | 2021-05-03 12:22:03 +0100 | [diff] [blame] | 58 | |
Sadik Armagan | a274748 | 2021-02-09 10:28:54 +0000 | [diff] [blame] | 59 | m_Layer.configure(&input, |
| 60 | &output, |
| 61 | static_cast<unsigned int>(coords[0]), |
| 62 | ConvertReductionOperationToAcl(m_Data.m_Parameters), |
| 63 | m_Data.m_Parameters.m_KeepDims); |
| 64 | } |
| 65 | |
| 66 | void NeonReduceWorkload::Execute() const |
| 67 | { |
| 68 | ARMNN_SCOPED_PROFILING_EVENT_NEON("NeonReduceWorkload_Execute"); |
| 69 | m_Layer.run(); |
| 70 | } |
| 71 | |
| 72 | } //namespace armnn |