ArmNN
 22.05
NeonL2NormalizationFloatWorkload.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
7 
8 #include "NeonWorkloadUtils.hpp"
9 
12 
13 #include <arm_compute/runtime/NEON/functions/NEL2NormalizeLayer.h>
14 
15 namespace armnn
16 {
17 using namespace armcomputetensorutils;
18 
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 
32  const WorkloadInfo& info, std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager)
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 
58 {
59  ARMNN_SCOPED_PROFILING_EVENT_NEON_GUID("NeonL2NormalizationFloatWorkload_Execute", this->GetGuid());
60  m_Layer->run();
61 }
62 
64 {
65  ITensorHandle* backupHandle = this->m_Data.m_Inputs[slot];
66  this->m_Data.m_Inputs[slot] = tensorHandle;
67  try
68  {
69  Reconfigure();
70  }
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
81 {
82  ITensorHandle* backupHandle = this->m_Data.m_Inputs[slot];
83  this->m_Data.m_Inputs[slot] = tensorHandle;
84  try
85  {
86  Reconfigure();
87  }
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 
96 void NeonL2NormalizationFloatWorkload::Reconfigure()
97 {
98  throw armnn::UnimplementedException("Reconfigure not implemented for this workload");
99 }
100 
101 } //namespace armnn
float m_Eps
Used to avoid dividing by zero.
DataLayout
Definition: Types.hpp:62
void ReplaceInputTensorHandle(ITensorHandle *tensorHandle, unsigned int slot) override
arm::pipe::ProfilingGuid GetGuid() const final
Definition: Workload.hpp:59
void ValidateInputsOutputs(const std::string &descName, unsigned int numExpectedIn, unsigned int numExpectedOut) const
Copyright (c) 2021 ARM Limited and Contributors.
void ReplaceOutputTensorHandle(ITensorHandle *tensorHandle, unsigned int slot) override
arm_compute::Status NeonL2NormalizationWorkloadValidate(const TensorInfo &input, const TensorInfo &output, const L2NormalizationDescriptor &descriptor)
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
A L2NormalizationDescriptor for the L2NormalizationLayer.
QueueDescriptor m_Data
Definition: Workload.hpp:81
Status
enumeration
Definition: Types.hpp:42
NeonL2NormalizationFloatWorkload(const L2NormalizationQueueDescriptor &descriptor, const WorkloadInfo &info, std::shared_ptr< arm_compute::MemoryManagerOnDemand > &memoryManager)
std::vector< ITensorHandle * > m_Outputs
#define ARMNN_REPORT_PROFILING_WORKLOAD_DESC(name, desc, infos, guid)
Definition: Profiling.hpp:227
Contains information about TensorInfos of a layer.
std::vector< ITensorHandle * > m_Inputs
#define ARMNN_SCOPED_PROFILING_EVENT_NEON_GUID(name, guid)