IVGCVSW-3521 CpuAcc V1.2 pad Failures
authorMike Kelly <mike.kelly@arm.com>
Thu, 25 Jul 2019 07:39:31 +0000 (08:39 +0100)
committerMike Kelly <mike.kelly@arm.com>
Thu, 25 Jul 2019 07:39:31 +0000 (08:39 +0100)
 * Pad value for QASYMM8 is no longer stored in quantized form.

Signed-off-by: Mike Kelly <mike.kelly@arm.com>
Change-Id: I048e1d233353c0560ae03a7cc1ed5199295352bc

src/backends/aclCommon/ArmComputeTensorUtils.cpp
src/backends/aclCommon/ArmComputeTensorUtils.hpp
src/backends/cl/workloads/ClPadWorkload.cpp
src/backends/neon/workloads/NeonPadWorkload.cpp
src/backends/reference/workloads/Pad.cpp

index e69232c..fabe9a1 100644 (file)
@@ -210,5 +210,23 @@ arm_compute::Size2D BuildArmComputeSize2D(const unsigned int width, const unsign
     return arm_compute::Size2D(width, height);
 }
 
+arm_compute::PixelValue GetPixelValue(arm_compute::ITensor& input, float pixelValue)
+{
+    switch (input.info()->data_type())
+    {
+        case arm_compute::DataType::QASYMM8:
+            return arm_compute::PixelValue(static_cast<uint8_t>(pixelValue));
+        case arm_compute::DataType::QSYMM16:
+            return arm_compute::PixelValue(static_cast<int16_t>(pixelValue));
+        case arm_compute::DataType::F16:
+            return arm_compute::PixelValue(static_cast<Half>(pixelValue));
+        case arm_compute::DataType::F32:
+            return arm_compute::PixelValue(pixelValue);
+        default:
+            throw InvalidArgumentException("Unsupported DataType: [" +
+                                           std::to_string(static_cast<int>(input.info()->data_type())) + "]");
+    }
+}
+
 } // namespace armcomputetensorutils
 } // namespace armnn
index fa455b7..c9587a7 100644 (file)
@@ -12,6 +12,8 @@
 #include <arm_compute/core/Types.h>
 #include <arm_compute/core/Size2D.h>
 
+#include <Half.hpp>
+
 #include <boost/cast.hpp>
 
 namespace armnn
@@ -58,6 +60,9 @@ arm_compute::PermutationVector BuildArmComputePermutationVector(const armnn::Per
 /// Utility function used to setup an arm_compute::Size2D object from width and height values.
 arm_compute::Size2D BuildArmComputeSize2D(const unsigned int width, const unsigned int height);
 
+/// Gets the appropriate PixelValue for the input DataType
+arm_compute::PixelValue GetPixelValue(arm_compute::ITensor& input, float pixelValue);
+
 /// Utility function used to setup an arm_compute::PadStrideInfo object from an armnn layer descriptor.
 template <typename Descriptor>
 arm_compute::PadStrideInfo BuildArmComputePadStrideInfo(const Descriptor &descriptor)
index 1c072ba..8a8c34a 100644 (file)
@@ -31,7 +31,7 @@ ClPadWorkload::ClPadWorkload(const PadQueueDescriptor& descriptor, const Workloa
 
     arm_compute::PaddingList padList = static_cast<arm_compute::PaddingList>(reversed_PadList);
 
-    arm_compute::PixelValue pixelValue = descriptor.m_Parameters.m_PadValue;
+    arm_compute::PixelValue pixelValue = GetPixelValue(input, descriptor.m_Parameters.m_PadValue);
 
     m_Layer.configure(&input, &output, padList, pixelValue);
 }
index 6bc1176..19cdefc 100644 (file)
@@ -32,7 +32,7 @@ NeonPadWorkload::NeonPadWorkload(const PadQueueDescriptor& descriptor, const Wor
 
     arm_compute::PaddingList padList = static_cast<arm_compute::PaddingList>(reversed_PadList);
 
-    arm_compute::PixelValue pixelValue = descriptor.m_Parameters.m_PadValue;
+    arm_compute::PixelValue pixelValue = GetPixelValue(input, descriptor.m_Parameters.m_PadValue);
 
     auto layer = std::make_unique<arm_compute::NEPadLayer>();
     layer->configure(&input, &output, padList, pixelValue);
index 41435f4..5773cac 100644 (file)
@@ -19,17 +19,6 @@ 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,
@@ -60,7 +49,7 @@ void Pad(const TensorInfo& inputInfo,
     unsigned int outputHeight = 0;
     unsigned int outputWidth = 0;
 
-    T convertedPadValue = ConvertToDataType<T>(padValue, inputInfo);
+    T convertedPadValue = static_cast<T>(padValue);
 
     for (unsigned int i = 0; i < numOutputElements; ++i)
     {