• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
NeonReduceWorkloadValidate(const TensorInfo & input,const TensorInfo & output,const ReduceDescriptor & descriptor)19 arm_compute::Status NeonReduceWorkloadValidate(const TensorInfo& input,
20                                                const TensorInfo& output,
21                                                const ReduceDescriptor& descriptor)
22 {
23     if ( descriptor.m_vAxis.size()==1 || descriptor.m_vAxis.empty())
24     {
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                                                                               descriptor.m_vAxis);
31 
32         return arm_compute::NEReductionOperation::validate(&aclInputInfo,
33                                                            &aclOutputInfo,
34                                                            static_cast<unsigned int>(coords[0]),
35                                                            ConvertReductionOperationToAcl(descriptor),
36                                                            descriptor.m_KeepDims);
37     }
38     else
39     {
40         // Validate layer if there are multiple axes.
41         arm_compute::Status status;
42         IS_MULTI_AXES_REDUCE_SUPPORTED(NeonReduceWorkloadValidate, input, descriptor, status);
43         return status;
44     }
45 }
46 
NeonReduceWorkload(const ReduceQueueDescriptor & descriptor,const WorkloadInfo & info)47 NeonReduceWorkload::NeonReduceWorkload(const ReduceQueueDescriptor& descriptor, const WorkloadInfo& info)
48     : NeonBaseWorkload<ReduceQueueDescriptor>(descriptor, info)
49 {
50     // Report Profiling Details
51     ARMNN_REPORT_PROFILING_WORKLOAD_DESC("NeonReduceWorkload_Construct",
52                                          descriptor.m_Parameters,
53                                          info,
54                                          this->GetGuid());
55 
56     m_Data.ValidateInputsOutputs("NeonReduceWorkload", 1, 1);
57 
58     arm_compute::ITensor& input  = static_cast<IAclTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
59     arm_compute::ITensor& output = static_cast<IAclTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
60 
61     arm_compute::Coordinates coords = BuildArmComputeReductionCoordinates(input.info()->num_dimensions(),
62                                                                           info.m_InputTensorInfos[0].GetNumDimensions(),
63                                                                           m_Data.m_Parameters.m_vAxis);
64 
65     m_Layer.configure(&input,
66                       &output,
67                       static_cast<unsigned int>(coords[0]),
68                       ConvertReductionOperationToAcl(m_Data.m_Parameters),
69                       m_Data.m_Parameters.m_KeepDims);
70 }
71 
Execute() const72 void NeonReduceWorkload::Execute() const
73 {
74     ARMNN_SCOPED_PROFILING_EVENT_NEON_GUID("NeonReduceWorkload_Execute", this->GetGuid());
75     m_Layer.run();
76 }
77 
78 } //namespace armnn
79