• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright © 2019 Arm Ltd and Contributors. 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 
11 #include <armnn/backends/TensorHandle.hpp>
12 
13 #include <armnn/utility/NumericCast.hpp>
14 #include <armnn/utility/PolymorphicDowncast.hpp>
15 #include <armnnUtils/TensorUtils.hpp>
16 
17 #include <arm_compute/runtime/NEON/functions/NEArgMinMaxLayer.h>
18 
19 namespace
20 {
CalcAclAxis(unsigned int numDimensions,unsigned int axisIndex)21 unsigned int CalcAclAxis(unsigned int numDimensions, unsigned int axisIndex)
22 {
23     return (numDimensions - axisIndex) - 1;
24 }
25 
26 } //namespace
27 
28 namespace armnn
29 {
30 
NeonArgMinMaxWorkloadValidate(const TensorInfo & input,const TensorInfo & output,const ArgMinMaxDescriptor & descriptor)31 arm_compute::Status NeonArgMinMaxWorkloadValidate(const TensorInfo& input,
32                                                   const TensorInfo& output,
33                                                   const ArgMinMaxDescriptor& descriptor)
34 {
35     const arm_compute::TensorInfo aclInput = armcomputetensorutils::BuildArmComputeTensorInfo(input);
36     const arm_compute::TensorInfo aclOutput = armcomputetensorutils::BuildArmComputeTensorInfo(output);
37 
38     auto numDims = input.GetNumDimensions();
39     auto unsignedAxis = armnnUtils::GetUnsignedAxis(numDims, descriptor.m_Axis);
40     int aclAxis = armnn::numeric_cast<int>(CalcAclAxis(numDims, unsignedAxis));
41 
42     if (descriptor.m_Function == ArgMinMaxFunction::Max)
43     {
44         return arm_compute::NEArgMinMaxLayer::validate(&aclInput, aclAxis, &aclOutput,
45                                                        arm_compute::ReductionOperation::ARG_IDX_MAX);
46     }
47     else
48     {
49         return arm_compute::NEArgMinMaxLayer::validate(&aclInput, aclAxis, &aclOutput,
50                                                        arm_compute::ReductionOperation::ARG_IDX_MIN);
51     }
52 }
53 
54 
NeonArgMinMaxWorkload(const ArgMinMaxQueueDescriptor & descriptor,const WorkloadInfo & info)55 NeonArgMinMaxWorkload::NeonArgMinMaxWorkload(const ArgMinMaxQueueDescriptor& descriptor,
56                                              const WorkloadInfo& info)
57         : NeonBaseWorkload<ArgMinMaxQueueDescriptor>(descriptor, info)
58 {
59     // Report Profiling Details
60     ARMNN_REPORT_PROFILING_WORKLOAD_DESC("NeonArgMinMaxWorkload_Construct",
61                                          descriptor.m_Parameters,
62                                          info,
63                                          this->GetGuid());
64 
65     arm_compute::ITensor& input = PolymorphicDowncast<IAclTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
66     arm_compute::ITensor& output = PolymorphicDowncast<IAclTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
67 
68     auto numDims = info.m_InputTensorInfos[0].GetNumDimensions();
69     auto unsignedAxis = armnnUtils::GetUnsignedAxis(numDims, m_Data.m_Parameters.m_Axis);
70     int aclAxis = armnn::numeric_cast<int>(CalcAclAxis(numDims, unsignedAxis));
71 
72     auto layer = std::make_unique<arm_compute::NEArgMinMaxLayer>();
73 
74     if (m_Data.m_Parameters.m_Function == ArgMinMaxFunction::Max)
75     {
76         layer->configure(&input, aclAxis, &output, arm_compute::ReductionOperation::ARG_IDX_MAX);
77     }
78     else
79     {
80         layer->configure(&input, aclAxis, &output, arm_compute::ReductionOperation::ARG_IDX_MIN);
81     }
82 
83     m_ArgMinMaxLayer.reset(layer.release());
84 }
85 
Execute() const86 void NeonArgMinMaxWorkload::Execute() const
87 {
88     ARMNN_SCOPED_PROFILING_EVENT_NEON_GUID("NeonArgMinMaxWorkload_Execute", this->GetGuid());
89     m_ArgMinMaxLayer->run();
90 }
91 
92 } //namespace armnn
93 
94