aboutsummaryrefslogtreecommitdiff
path: root/src/backends/reference/workloads/RefL2NormalizationWorkload.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/backends/reference/workloads/RefL2NormalizationWorkload.cpp')
-rw-r--r--src/backends/reference/workloads/RefL2NormalizationWorkload.cpp37
1 files changed, 30 insertions, 7 deletions
diff --git a/src/backends/reference/workloads/RefL2NormalizationWorkload.cpp b/src/backends/reference/workloads/RefL2NormalizationWorkload.cpp
index 3b2ab50c8b..3764b9a49a 100644
--- a/src/backends/reference/workloads/RefL2NormalizationWorkload.cpp
+++ b/src/backends/reference/workloads/RefL2NormalizationWorkload.cpp
@@ -10,9 +10,10 @@
#include "Encoders.hpp"
#include "DataLayoutIndexed.hpp"
-
#include "Profiling.hpp"
+#include <boost/numeric/conversion/cast.hpp>
+
#include <cmath>
using namespace armnnUtils;
@@ -36,10 +37,32 @@ RefL2NormalizationWorkload::RefL2NormalizationWorkload(
DataLayoutIndexed dataLayout(m_Data.m_Parameters.m_DataLayout);
- const unsigned int batches = inputInfo.GetShape()[0];
- const unsigned int channels = inputInfo.GetShape()[dataLayout.GetChannelsIndex()];
- const unsigned int height = inputInfo.GetShape()[dataLayout.GetHeightIndex()];
- const unsigned int width = inputInfo.GetShape()[dataLayout.GetWidthIndex()];
+ const TensorShape& shape = inputInfo.GetShape();
+ unsigned int paddedShapeArray[4];
+ const int idxShift = 4 - boost::numeric_cast<int>(shape.GetNumDimensions());
+
+ const unsigned int batches = (idxShift == 0) ? shape[0] : 1;
+ paddedShapeArray[0] = batches;
+
+ const int channelsIdx = boost::numeric_cast<int>(dataLayout.GetChannelsIndex());
+ const unsigned int channels = (channelsIdx - idxShift >= 0)
+ ? shape[boost::numeric_cast<unsigned int>(channelsIdx - idxShift)]
+ : 1;
+ paddedShapeArray[channelsIdx] = channels;
+
+ const int heightIdx = boost::numeric_cast<int>(dataLayout.GetHeightIndex());
+ const unsigned int height = (heightIdx - idxShift >= 0)
+ ? shape[boost::numeric_cast<unsigned int>(heightIdx - idxShift)]
+ : 1;
+ paddedShapeArray[heightIdx] = height;
+
+ const int widthIdx = boost::numeric_cast<int>(dataLayout.GetWidthIndex());
+ const unsigned int width = (widthIdx - idxShift >= 0)
+ ? shape[boost::numeric_cast<unsigned int>(widthIdx - idxShift)]
+ : 1;
+ paddedShapeArray[widthIdx] = width;
+
+ const TensorShape& paddedShape = TensorShape(4, paddedShapeArray);
for (unsigned int n = 0; n < batches; ++n)
{
@@ -52,14 +75,14 @@ RefL2NormalizationWorkload::RefL2NormalizationWorkload(
float reduction = 0.0;
for (unsigned int d = 0; d < channels; ++d)
{
- unsigned int inputIndex = dataLayout.GetIndex(inputInfo.GetShape(), n, d, h, w);
+ unsigned int inputIndex = dataLayout.GetIndex(paddedShape, n, d, h, w);
(*inputDecoder)[inputIndex];
const float value = inputDecoder->Get();
reduction += value * value;
}
- unsigned int index = dataLayout.GetIndex(inputInfo.GetShape(), n, c, h, w);
+ unsigned int index = dataLayout.GetIndex(paddedShape, n, c, h, w);
float maximum = reduction < m_Data.m_Parameters.m_Eps ? m_Data.m_Parameters.m_Eps : reduction;