15 #include <boost/numeric/conversion/cast.hpp> 35 auto inputDecoder = MakeDecoder<float>(inputInfo,
m_Data.
m_Inputs[0]->Map());
36 auto outputEncoder = MakeEncoder<float>(outputInfo,
m_Data.
m_Outputs[0]->Map());
41 unsigned int paddedShapeArray[4];
44 const unsigned int batches = (idxShift == 0) ? shape[0] : 1;
45 paddedShapeArray[0] = batches;
47 const int channelsIdx = boost::numeric_cast<
int>(dataLayout.GetChannelsIndex());
48 const unsigned int channels = (channelsIdx - idxShift >= 0)
49 ? shape[boost::numeric_cast<unsigned int>(channelsIdx - idxShift)]
51 paddedShapeArray[channelsIdx] = channels;
53 const int heightIdx = boost::numeric_cast<
int>(dataLayout.GetHeightIndex());
54 const unsigned int height = (heightIdx - idxShift >= 0)
55 ? shape[boost::numeric_cast<unsigned int>(heightIdx - idxShift)]
57 paddedShapeArray[heightIdx] = height;
59 const int widthIdx = boost::numeric_cast<
int>(dataLayout.GetWidthIndex());
60 const unsigned int width = (widthIdx - idxShift >= 0)
61 ? shape[boost::numeric_cast<unsigned int>(widthIdx - idxShift)]
63 paddedShapeArray[widthIdx] = width;
67 for (
unsigned int n = 0; n < batches; ++n)
69 for (
unsigned int c = 0; c < channels; ++c)
71 for (
unsigned int h = 0; h < height; ++h)
73 for (
unsigned int w = 0; w < width; ++w)
75 float reduction = 0.0;
76 for (
unsigned int d = 0; d < channels; ++d)
78 unsigned int inputIndex = dataLayout.GetIndex(paddedShape, n, d, h, w);
80 (*inputDecoder)[inputIndex];
81 const float value = inputDecoder->Get();
82 reduction += value * value;
85 unsigned int index = dataLayout.GetIndex(paddedShape, n, c, h, w);
89 const float scale = 1.0f / sqrtf(maximum);
91 (*inputDecoder)[index];
92 (*outputEncoder)[index];
93 outputEncoder->Set(inputDecoder->Get() * scale);
#define ARMNN_SCOPED_PROFILING_EVENT(backendId, name)
unsigned int GetNumDimensions() const
LayerDescriptor m_Parameters
RefL2NormalizationWorkload(const L2NormalizationQueueDescriptor &descriptor, const WorkloadInfo &info)
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
const L2NormalizationQueueDescriptor m_Data
void Execute() const override
CPU Execution: Reference C++ kernels.
std::vector< ITensorHandle * > m_Outputs
std::vector< ITensorHandle * > m_Inputs
const TensorInfo & GetTensorInfo(const ITensorHandle *tensorHandle)
float32 helpers
float m_Eps
Used to avoid dividing by zero.