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