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 | { |
| 23 | const arm_compute::TensorInfo aclInputInfo = armcomputetensorutils::BuildArmComputeTensorInfo(input); |
| 24 | const arm_compute::TensorInfo aclOutputInfo = armcomputetensorutils::BuildArmComputeTensorInfo(output); |
| 25 | if (!desc.m_vAxis.empty() && desc.m_vAxis.size() > 1) |
| 26 | { |
| 27 | return arm_compute::Status(arm_compute::ErrorCode::RUNTIME_ERROR, |
| 28 | "NeonReduceWorkload: Reduction is supported only on 1 axis."); |
| 29 | } |
| 30 | |
| 31 | arm_compute::Coordinates coords = BuildArmComputeReductionCoordinates(aclInputInfo.num_dimensions(), |
| 32 | input.GetNumDimensions(), |
| 33 | desc.m_vAxis); |
| 34 | |
| 35 | return arm_compute::NEReductionOperation::validate(&aclInputInfo, |
| 36 | &aclOutputInfo, |
| 37 | static_cast<unsigned int>(coords[0]), |
| 38 | ConvertReductionOperationToAcl(desc), |
| 39 | desc.m_KeepDims); |
| 40 | } |
| 41 | |
| 42 | NeonReduceWorkload::NeonReduceWorkload(const ReduceQueueDescriptor& descriptor, const WorkloadInfo& info) |
| 43 | : BaseWorkload<ReduceQueueDescriptor>(descriptor, info) |
| 44 | { |
| 45 | m_Data.ValidateInputsOutputs("NeonReduceWorkload", 1, 1); |
| 46 | |
| 47 | arm_compute::ITensor& input = static_cast<IAclTensorHandle*>(m_Data.m_Inputs[0])->GetTensor(); |
| 48 | arm_compute::ITensor& output = static_cast<IAclTensorHandle*>(m_Data.m_Outputs[0])->GetTensor(); |
| 49 | |
| 50 | arm_compute::Coordinates coords = BuildArmComputeReductionCoordinates(input.info()->num_dimensions(), |
| 51 | info.m_InputTensorInfos[0].GetNumDimensions(), |
| 52 | m_Data.m_Parameters.m_vAxis); |
| 53 | m_Layer.configure(&input, |
| 54 | &output, |
| 55 | static_cast<unsigned int>(coords[0]), |
| 56 | ConvertReductionOperationToAcl(m_Data.m_Parameters), |
| 57 | m_Data.m_Parameters.m_KeepDims); |
| 58 | } |
| 59 | |
| 60 | void NeonReduceWorkload::Execute() const |
| 61 | { |
| 62 | ARMNN_SCOPED_PROFILING_EVENT_NEON("NeonReduceWorkload_Execute"); |
| 63 | m_Layer.run(); |
| 64 | } |
| 65 | |
| 66 | } //namespace armnn |