aboutsummaryrefslogtreecommitdiff
path: root/src/backends/reference
diff options
context:
space:
mode:
authorDavid Monahan <david.monahan@arm.com>2019-06-19 11:47:21 +0100
committerMatthew Bentham <matthew.bentham@arm.com>2019-06-24 23:09:02 +0000
commit34757810f8b734f5f59485a542b56934ad4cc5f0 (patch)
treec9859e1eb90fdf1e3ba4fbeadb3952cac3477277 /src/backends/reference
parent84da38b0f11ca3db0a439e510514be780f3933ff (diff)
downloadarmnn-34757810f8b734f5f59485a542b56934ad4cc5f0.tar.gz
IVGCVSW-3235 Add scalar to use as padding value in Reference Pad
Signed-off-by: David Monahan <david.monahan@arm.com> Change-Id: If050f318fcb7626bbfae1b8737a1d232a4a5a915
Diffstat (limited to 'src/backends/reference')
-rw-r--r--src/backends/reference/test/RefLayerTests.cpp2
-rw-r--r--src/backends/reference/workloads/Pad.cpp51
-rw-r--r--src/backends/reference/workloads/Pad.hpp5
-rw-r--r--src/backends/reference/workloads/RefPadWorkload.cpp3
4 files changed, 41 insertions, 20 deletions
diff --git a/src/backends/reference/test/RefLayerTests.cpp b/src/backends/reference/test/RefLayerTests.cpp
index cb9ee4b5a0..9cb8d13adc 100644
--- a/src/backends/reference/test/RefLayerTests.cpp
+++ b/src/backends/reference/test/RefLayerTests.cpp
@@ -645,10 +645,12 @@ ARMNN_AUTO_TEST_CASE(L2NormalizationNonDefaultEpsilon, L2NormalizationNonDefault
// Pad
ARMNN_AUTO_TEST_CASE(PadFloat322d, PadFloat322dTest)
+ARMNN_AUTO_TEST_CASE(PadFloat322dCustomPadding, PadFloat322dCustomPaddingTest)
ARMNN_AUTO_TEST_CASE(PadFloat323d, PadFloat323dTest)
ARMNN_AUTO_TEST_CASE(PadFloat324d, PadFloat324dTest)
ARMNN_AUTO_TEST_CASE(PadUint82d, PadUint82dTest)
+ARMNN_AUTO_TEST_CASE(PadUint82dCustomPadding, PadUint82dCustomPaddingTest)
ARMNN_AUTO_TEST_CASE(PadUint83d, PadUint83dTest)
ARMNN_AUTO_TEST_CASE(PadUint84d, PadUint84dTest)
diff --git a/src/backends/reference/workloads/Pad.cpp b/src/backends/reference/workloads/Pad.cpp
index 7a928a1336..1e58124627 100644
--- a/src/backends/reference/workloads/Pad.cpp
+++ b/src/backends/reference/workloads/Pad.cpp
@@ -5,8 +5,10 @@
#include "Pad.hpp"
#include "backendsCommon/WorkloadData.hpp"
-#include <boost/numeric/conversion/cast.hpp>
#include "TensorBufferArrayView.hpp"
+#include "Encoders.hpp"
+
+#include <boost/numeric/conversion/cast.hpp>
#include <cmath>
#include <cstddef>
#include <functional>
@@ -15,12 +17,25 @@
namespace armnn
{
+
+template <typename T>
+T ConvertToDataType(const float& value,
+ const armnn::TensorInfo& tensorInfo)
+{
+ std::vector<T> output(1);
+ std::unique_ptr<armnn::Encoder<float>> pEncoder = armnn::MakeEncoder<float>(tensorInfo, output.data());
+ armnn::Encoder<float>& rEncoder = *pEncoder;
+ rEncoder.Set(value);
+ return output[0];
+}
+
template <typename T>
void Pad(const TensorInfo& inputInfo,
const TensorInfo& outputInfo,
- std::vector<std::pair<unsigned int, unsigned int>> m_PadList,
+ std::vector<std::pair<unsigned int, unsigned int>> m_padList,
const T* inputData,
- T* outData)
+ T* outData,
+ const float padValue)
{
unsigned int numOutputElements = outputInfo.GetNumElements();
@@ -45,9 +60,11 @@ void Pad(const TensorInfo& inputInfo,
unsigned int outputHeight = 0;
unsigned int outputWidth = 0;
+ T convertedPadValue = ConvertToDataType<T>(padValue, inputInfo);
+
for (unsigned int i = 0; i < numOutputElements; ++i)
{
- outData[i] = 0;
+ outData[i] = convertedPadValue;
}
switch(numInputDimensions) {
@@ -58,7 +75,7 @@ void Pad(const TensorInfo& inputInfo,
for (unsigned int w = 0; w < inputWidth ; w++)
{
- outData[w+std::get<0>(m_PadList[0])] = inputData[w];
+ outData[w+std::get<0>(m_padList[0])] = inputData[w];
}
break;
@@ -74,8 +91,8 @@ void Pad(const TensorInfo& inputInfo,
{
for (unsigned int w = 0; w < inputWidth ; w++)
{
- outData[(h+std::get<0>(m_PadList[0]))*outputWidth
- + (w+std::get<0>(m_PadList[1]))] = inputData[h * inputWidth + w];
+ outData[(h+std::get<0>(m_padList[0]))*outputWidth
+ + (w+std::get<0>(m_padList[1]))] = inputData[h * inputWidth + w];
}
}
@@ -96,9 +113,9 @@ void Pad(const TensorInfo& inputInfo,
{
for (unsigned int w = 0; w < inputWidth ; w++)
{
- outData[(c+std::get<0>(m_PadList[0]))*outputHeight*outputWidth
- + (h+std::get<0>(m_PadList[1]))*outputWidth
- + (w+std::get<0>(m_PadList[2]))] = inputData[c * inputHeight * inputWidth
+ outData[(c+std::get<0>(m_padList[0]))*outputHeight*outputWidth
+ + (h+std::get<0>(m_padList[1]))*outputWidth
+ + (w+std::get<0>(m_padList[2]))] = inputData[c * inputHeight * inputWidth
+ h * inputWidth
+ w];
}
@@ -125,10 +142,10 @@ void Pad(const TensorInfo& inputInfo,
{
for (unsigned int w = 0; w < inputWidth ; w++)
{
- outData[(b+std::get<0>(m_PadList[0])) * outputChannels * outputHeight * outputWidth
- + (c+std::get<0>(m_PadList[1])) * outputHeight * outputWidth
- + (h+std::get<0>(m_PadList[2])) * outputWidth
- + (w+std::get<0>(m_PadList[3]))] = inputData[b * inputChannels * inputHeight
+ outData[(b+std::get<0>(m_padList[0])) * outputChannels * outputHeight * outputWidth
+ + (c+std::get<0>(m_padList[1])) * outputHeight * outputWidth
+ + (h+std::get<0>(m_padList[2])) * outputWidth
+ + (w+std::get<0>(m_padList[3]))] = inputData[b * inputChannels * inputHeight
* inputWidth
+ c * inputHeight * inputWidth
+ h * inputWidth
@@ -150,11 +167,13 @@ template void Pad<float>(const TensorInfo& inputInfo,
const TensorInfo& outputInfo,
std::vector<std::pair<unsigned int, unsigned int>> m_PadList,
const float* inputData,
- float* outData);
+ float* outData,
+ const float padValue);
template void Pad<uint8_t>(const TensorInfo& inputInfo,
const TensorInfo& outputInfo,
std::vector<std::pair<unsigned int, unsigned int>> m_PadList,
const uint8_t* inputData,
- uint8_t* outData);
+ uint8_t* outData,
+ const float padValue);
} //namespace armnn \ No newline at end of file
diff --git a/src/backends/reference/workloads/Pad.hpp b/src/backends/reference/workloads/Pad.hpp
index 42318d6fcf..429718596e 100644
--- a/src/backends/reference/workloads/Pad.hpp
+++ b/src/backends/reference/workloads/Pad.hpp
@@ -15,7 +15,8 @@ namespace armnn
template <typename T>
void Pad(const TensorInfo& inputInfo,
const TensorInfo& outputInfo,
- std::vector<std::pair<unsigned int, unsigned int>> m_PadList,
+ std::vector<std::pair<unsigned int, unsigned int>> m_padList,
const T* inputData,
- T* outData);
+ T* outData,
+ const float padValue);
} //namespace armnn
diff --git a/src/backends/reference/workloads/RefPadWorkload.cpp b/src/backends/reference/workloads/RefPadWorkload.cpp
index 16032e7c77..8cb9d883dc 100644
--- a/src/backends/reference/workloads/RefPadWorkload.cpp
+++ b/src/backends/reference/workloads/RefPadWorkload.cpp
@@ -30,8 +30,7 @@ void RefPadWorkload<DataType>::Execute() const
const T* inputData = GetInputTensorData<T>(0, m_Data);
T* outputData = GetOutputTensorData<T>(0, m_Data);
-
- Pad(inputInfo, outputInfo, m_Data.m_Parameters.m_PadList, inputData, outputData);
+ Pad(inputInfo, outputInfo, m_Data.m_Parameters.m_PadList, inputData, outputData, m_Data.m_Parameters.m_padValue);
}
template class RefPadWorkload<DataType::Float32>;