ArmNN
 21.02
RefL2NormalizationWorkload Class Reference

#include <RefL2NormalizationWorkload.hpp>

Inheritance diagram for RefL2NormalizationWorkload:
BaseWorkload< L2NormalizationQueueDescriptor > IWorkload

Public Member Functions

 RefL2NormalizationWorkload (const L2NormalizationQueueDescriptor &descriptor, const WorkloadInfo &info)
 
void Execute () const override
 
- Public Member Functions inherited from BaseWorkload< L2NormalizationQueueDescriptor >
 BaseWorkload (const L2NormalizationQueueDescriptor &descriptor, const WorkloadInfo &info)
 
void PostAllocationConfigure () override
 
const L2NormalizationQueueDescriptorGetData () const
 
profiling::ProfilingGuid GetGuid () const final
 
- Public Member Functions inherited from IWorkload
virtual ~IWorkload ()
 
virtual void RegisterDebugCallback (const DebugCallbackFunction &)
 

Additional Inherited Members

- Protected Attributes inherited from BaseWorkload< L2NormalizationQueueDescriptor >
const L2NormalizationQueueDescriptor m_Data
 
const profiling::ProfilingGuid m_Guid
 

Detailed Description

Definition at line 14 of file RefL2NormalizationWorkload.hpp.

Constructor & Destructor Documentation

◆ RefL2NormalizationWorkload()

Member Function Documentation

◆ Execute()

void Execute ( ) const
overridevirtual

Implements IWorkload.

Definition at line 27 of file RefL2NormalizationWorkload.cpp.

References ARMNN_SCOPED_PROFILING_EVENT, armnn::CpuRef, TensorShape::GetNumDimensions(), armnn::GetTensorInfo(), BaseWorkload< L2NormalizationQueueDescriptor >::m_Data, L2NormalizationDescriptor::m_DataLayout, L2NormalizationDescriptor::m_Eps, QueueDescriptor::m_Inputs, QueueDescriptor::m_Outputs, QueueDescriptorWithParameters< LayerDescriptor >::m_Parameters, and armnn::numeric_cast().

28 {
29  ARMNN_SCOPED_PROFILING_EVENT(Compute::CpuRef, "RefL2NormalizationWorkload_Execute");
30 
31  const TensorInfo& inputInfo = GetTensorInfo(m_Data.m_Inputs[0]);
32  const TensorInfo& outputInfo = GetTensorInfo(m_Data.m_Outputs[0]);
33 
34  auto inputDecoder = MakeDecoder<float>(inputInfo, m_Data.m_Inputs[0]->Map());
35  auto outputEncoder = MakeEncoder<float>(outputInfo, m_Data.m_Outputs[0]->Map());
36 
38 
39  const TensorShape& shape = inputInfo.GetShape();
40  unsigned int paddedShapeArray[4];
41  const int idxShift = 4 - armnn::numeric_cast<int>(shape.GetNumDimensions());
42 
43  const unsigned int batches = (idxShift == 0) ? shape[0] : 1;
44  paddedShapeArray[0] = batches;
45 
46  const int channelsIdx = armnn::numeric_cast<int>(dataLayout.GetChannelsIndex());
47  const unsigned int channels = (channelsIdx - idxShift >= 0)
48  ? shape[armnn::numeric_cast<unsigned int>(channelsIdx - idxShift)]
49  : 1;
50  paddedShapeArray[channelsIdx] = channels;
51 
52  const int heightIdx = armnn::numeric_cast<int>(dataLayout.GetHeightIndex());
53  const unsigned int height = (heightIdx - idxShift >= 0)
54  ? shape[armnn::numeric_cast<unsigned int>(heightIdx - idxShift)]
55  : 1;
56  paddedShapeArray[heightIdx] = height;
57 
58  const int widthIdx = armnn::numeric_cast<int>(dataLayout.GetWidthIndex());
59  const unsigned int width = (widthIdx - idxShift >= 0)
60  ? shape[armnn::numeric_cast<unsigned int>(widthIdx - idxShift)]
61  : 1;
62  paddedShapeArray[widthIdx] = width;
63 
64  const TensorShape& paddedShape = TensorShape(4, paddedShapeArray);
65 
66  for (unsigned int n = 0; n < batches; ++n)
67  {
68  for (unsigned int c = 0; c < channels; ++c)
69  {
70  for (unsigned int h = 0; h < height; ++h)
71  {
72  for (unsigned int w = 0; w < width; ++w)
73  {
74  float reduction = 0.0;
75  for (unsigned int d = 0; d < channels; ++d)
76  {
77  unsigned int inputIndex = dataLayout.GetIndex(paddedShape, n, d, h, w);
78 
79  (*inputDecoder)[inputIndex];
80  const float value = inputDecoder->Get();
81  reduction += value * value;
82  }
83 
84  unsigned int index = dataLayout.GetIndex(paddedShape, n, c, h, w);
85 
86  float maximum = reduction < m_Data.m_Parameters.m_Eps ? m_Data.m_Parameters.m_Eps : reduction;
87 
88  const float scale = 1.0f / sqrtf(maximum);
89 
90  (*inputDecoder)[index];
91  (*outputEncoder)[index];
92  outputEncoder->Set(inputDecoder->Get() * scale);
93  }
94  }
95  }
96  }
97 }
float m_Eps
Used to avoid dividing by zero.
CPU Execution: Reference C++ kernels.
const L2NormalizationQueueDescriptor m_Data
Definition: Workload.hpp:46
#define ARMNN_SCOPED_PROFILING_EVENT(backendId, name)
Definition: Profiling.hpp:173
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
Provides access to the appropriate indexes for Channels, Height and Width based on DataLayout...
std::vector< ITensorHandle * > m_Outputs
unsigned int GetNumDimensions() const
Function that returns the tensor rank.
Definition: Tensor.cpp:174
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
Definition: NumericCast.hpp:35
std::vector< ITensorHandle * > m_Inputs
const TensorInfo & GetTensorInfo(const ITensorHandle *tensorHandle)
float32 helpers

The documentation for this class was generated from the following files: