1 //
2 // Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5
6 #include "NeonL2NormalizationFloatWorkload.hpp"
7
8 #include "NeonWorkloadUtils.hpp"
9
10 #include <aclCommon/ArmComputeUtils.hpp>
11 #include <armnn/utility/PolymorphicDowncast.hpp>
12
13 #include <arm_compute/runtime/NEON/functions/NEL2NormalizeLayer.h>
14
15 namespace armnn
16 {
17 using namespace armcomputetensorutils;
18
NeonL2NormalizationWorkloadValidate(const TensorInfo & input,const TensorInfo & output,const L2NormalizationDescriptor & descriptor)19 arm_compute::Status NeonL2NormalizationWorkloadValidate(const TensorInfo& input,
20 const TensorInfo& output,
21 const L2NormalizationDescriptor& descriptor)
22 {
23 const arm_compute::TensorInfo aclInput = BuildArmComputeTensorInfo(input, descriptor.m_DataLayout);
24 const arm_compute::TensorInfo aclOutput = BuildArmComputeTensorInfo(output, descriptor.m_DataLayout);
25
26 int axis = (descriptor.m_DataLayout == DataLayout::NCHW) ? 2 : 0;
27
28 return arm_compute::NEL2NormalizeLayer::validate(&aclInput, &aclOutput, axis, descriptor.m_Eps);
29 }
30
NeonL2NormalizationFloatWorkload(const L2NormalizationQueueDescriptor & descriptor,const WorkloadInfo & info,std::shared_ptr<arm_compute::MemoryManagerOnDemand> & memoryManager)31 NeonL2NormalizationFloatWorkload::NeonL2NormalizationFloatWorkload(const L2NormalizationQueueDescriptor& descriptor,
32 const WorkloadInfo& info, std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager)
33 : FloatWorkload<L2NormalizationQueueDescriptor>(descriptor, info)
34 {
35 // Report Profiling Details
36 ARMNN_REPORT_PROFILING_WORKLOAD_DESC("NeonL2NormalizationFloatWorkload_Construct",
37 descriptor.m_Parameters,
38 info,
39 this->GetGuid());
40
41 m_Data.ValidateInputsOutputs("NeonL2NormalizationFloatWorkload", 1, 1);
42
43 arm_compute::ITensor& input = PolymorphicDowncast<IAclTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
44 arm_compute::ITensor& output = PolymorphicDowncast<IAclTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
45
46 arm_compute::DataLayout aclDataLayout = ConvertDataLayout(m_Data.m_Parameters.m_DataLayout);
47 input.info()->set_data_layout(aclDataLayout);
48 output.info()->set_data_layout(aclDataLayout);
49
50 int axis = (m_Data.m_Parameters.m_DataLayout == DataLayout::NCHW) ? 2 : 0;
51
52 auto layer = std::make_unique<arm_compute::NEL2NormalizeLayer>(memoryManager);
53 layer->configure(&input, &output, axis, m_Data.m_Parameters.m_Eps);
54 m_Layer.reset(layer.release());
55 }
56
Execute() const57 void NeonL2NormalizationFloatWorkload::Execute() const
58 {
59 ARMNN_SCOPED_PROFILING_EVENT_NEON_GUID("NeonL2NormalizationFloatWorkload_Execute", this->GetGuid());
60 m_Layer->run();
61 }
62
ReplaceInputTensorHandle(ITensorHandle * tensorHandle,unsigned int slot)63 void NeonL2NormalizationFloatWorkload::ReplaceInputTensorHandle(ITensorHandle* tensorHandle, unsigned int slot)
64 {
65 ITensorHandle* backupHandle = this->m_Data.m_Inputs[slot];
66 this->m_Data.m_Inputs[slot] = tensorHandle;
67 try
68 {
69 Reconfigure();
70 }
71 catch(armnn::UnimplementedException& e)
72 {
73 // Cannot reconfigure, revert the slot back and throw the exception.
74 this->m_Data.m_Inputs[slot] = backupHandle;
75 throw e;
76 }
77 }
78
79 // Replace output tensor handle with the given TensorHandle
ReplaceOutputTensorHandle(ITensorHandle * tensorHandle,unsigned int slot)80 void NeonL2NormalizationFloatWorkload::ReplaceOutputTensorHandle(ITensorHandle* tensorHandle, unsigned int slot)
81 {
82 ITensorHandle* backupHandle = this->m_Data.m_Inputs[slot];
83 this->m_Data.m_Inputs[slot] = tensorHandle;
84 try
85 {
86 Reconfigure();
87 }
88 catch(armnn::UnimplementedException& e)
89 {
90 // Cannot reconfigure, revert the slot back and throw the exception.
91 this->m_Data.m_Inputs[slot] = backupHandle;
92 throw e;
93 }
94 }
95
Reconfigure()96 void NeonL2NormalizationFloatWorkload::Reconfigure()
97 {
98 throw armnn::UnimplementedException("Reconfigure not implemented for this workload");
99 }
100
101 } //namespace armnn
102