James Conroy | d47a064 | 2019-09-17 14:22:06 +0100 | [diff] [blame^] | 1 | // |
| 2 | // Copyright © 2019 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "NeonArgMinMaxWorkload.hpp" |
| 7 | #include "NeonWorkloadUtils.hpp" |
| 8 | |
| 9 | #include <aclCommon/ArmComputeTensorUtils.hpp> |
| 10 | #include <backendsCommon/CpuTensorHandle.hpp> |
| 11 | #include <TensorUtils.hpp> |
| 12 | |
| 13 | #include <arm_compute/runtime/NEON/functions/NEArgMinMaxLayer.h> |
| 14 | |
| 15 | namespace |
| 16 | { |
| 17 | unsigned int CalcAclAxis(unsigned int numDimensions, unsigned int axisIndex) |
| 18 | { |
| 19 | return (numDimensions - axisIndex) - 1; |
| 20 | } |
| 21 | |
| 22 | } //namespace |
| 23 | |
| 24 | namespace armnn |
| 25 | { |
| 26 | |
| 27 | arm_compute::Status NeonArgMinMaxWorkloadValidate(const TensorInfo& input, |
| 28 | const TensorInfo& output, |
| 29 | const ArgMinMaxDescriptor& descriptor) |
| 30 | { |
| 31 | const arm_compute::TensorInfo aclInput = armcomputetensorutils::BuildArmComputeTensorInfo(input); |
| 32 | const arm_compute::TensorInfo aclOutput = armcomputetensorutils::BuildArmComputeTensorInfo(output); |
| 33 | |
| 34 | auto numDims = input.GetNumDimensions(); |
| 35 | auto unsignedAxis = armnnUtils::GetUnsignedAxis(numDims, descriptor.m_Axis); |
| 36 | int aclAxis = boost::numeric_cast<int>(CalcAclAxis(numDims, unsignedAxis)); |
| 37 | |
| 38 | if (descriptor.m_Function == ArgMinMaxFunction::Max) |
| 39 | { |
| 40 | return arm_compute::NEArgMinMaxLayer::validate(&aclInput, aclAxis, &aclOutput, |
| 41 | arm_compute::ReductionOperation::ARG_IDX_MAX); |
| 42 | } |
| 43 | else |
| 44 | { |
| 45 | return arm_compute::NEArgMinMaxLayer::validate(&aclInput, aclAxis, &aclOutput, |
| 46 | arm_compute::ReductionOperation::ARG_IDX_MIN); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | |
| 51 | NeonArgMinMaxWorkload::NeonArgMinMaxWorkload(const ArgMinMaxQueueDescriptor& descriptor, |
| 52 | const WorkloadInfo& info) |
| 53 | : BaseWorkload<ArgMinMaxQueueDescriptor>(descriptor, info) |
| 54 | { |
| 55 | arm_compute::ITensor& input = boost::polymorphic_downcast<IAclTensorHandle*>(m_Data.m_Inputs[0])->GetTensor(); |
| 56 | arm_compute::ITensor& output = boost::polymorphic_downcast<IAclTensorHandle*>(m_Data.m_Outputs[0])->GetTensor(); |
| 57 | |
| 58 | auto numDims = info.m_InputTensorInfos[0].GetNumDimensions(); |
| 59 | auto unsignedAxis = armnnUtils::GetUnsignedAxis(numDims, m_Data.m_Parameters.m_Axis); |
| 60 | int aclAxis = boost::numeric_cast<int>(CalcAclAxis(numDims, unsignedAxis)); |
| 61 | |
| 62 | if (m_Data.m_Parameters.m_Function == ArgMinMaxFunction::Max) |
| 63 | { |
| 64 | m_ArgMinMaxLayer.configure(&input, aclAxis, &output, arm_compute::ReductionOperation::ARG_IDX_MAX); |
| 65 | } |
| 66 | else |
| 67 | { |
| 68 | m_ArgMinMaxLayer.configure(&input, aclAxis, &output, arm_compute::ReductionOperation::ARG_IDX_MIN); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | void NeonArgMinMaxWorkload::Execute() const |
| 73 | { |
| 74 | ARMNN_SCOPED_PROFILING_EVENT_NEON("NeonArgMinMaxWorkload_Execute"); |
| 75 | m_ArgMinMaxLayer.run(); |
| 76 | } |
| 77 | |
| 78 | } //namespace armnn |
| 79 | |