From 252df3a8b6bbf70a21f81d1bf239d08f8b09086f Mon Sep 17 00:00:00 2001 From: Matthew Jackson Date: Wed, 11 Sep 2019 09:19:18 +0100 Subject: IVGCVSW-3845 Add Reference FP16 support for required layers * Working on layers required by FSRCNN, FCRN and DeepSpeaker * Updates RefLayerSupport and RefWorkloadFactory methods * Adds RefPadFloat16Workload * Tested by successful execution of these networks on Reference FP16 backend Signed-off-by: Matthew Jackson Change-Id: I4817dca0a89bba6902f0feffc494b27a26a0ab2d --- src/backends/reference/RefLayerSupport.cpp | 45 ++++++++++++++-------- src/backends/reference/RefWorkloadFactory.cpp | 32 ++------------- src/backends/reference/workloads/Pad.cpp | 6 +++ .../reference/workloads/RefPadWorkload.cpp | 1 + .../reference/workloads/RefPadWorkload.hpp | 5 ++- 5 files changed, 44 insertions(+), 45 deletions(-) diff --git a/src/backends/reference/RefLayerSupport.cpp b/src/backends/reference/RefLayerSupport.cpp index 5692f9e143..4958968175 100644 --- a/src/backends/reference/RefLayerSupport.cpp +++ b/src/backends/reference/RefLayerSupport.cpp @@ -100,8 +100,9 @@ bool RefLayerSupport::IsActivationSupported(const TensorInfo& input, bool supported = true; // Define supported types. - std::array supportedTypes = { + std::array supportedTypes = { DataType::Float32, + DataType::Float16, DataType::QuantisedAsymm8, DataType::QuantisedSymm16 }; @@ -162,8 +163,9 @@ bool RefLayerSupport::IsAdditionSupported(const TensorInfo& input0, { bool supported = true; - std::array supportedTypes = { + std::array supportedTypes = { DataType::Float32, + DataType::Float16, DataType::QuantisedAsymm8, DataType::QuantisedSymm16 }; @@ -375,8 +377,9 @@ bool RefLayerSupport::IsConvolution2dSupported(const TensorInfo& input, bool supported = true; // Define supported types. - std::array supportedTypes = { + std::array supportedTypes = { DataType::Float32, + DataType::Float16, DataType::QuantisedAsymm8, DataType::QuantisedSymm16 }; @@ -398,8 +401,9 @@ bool RefLayerSupport::IsConvolution2dSupported(const TensorInfo& input, if (biases.has_value()) { - std::array biasesSupportedTypes = { + std::array biasesSupportedTypes = { DataType::Float32, + DataType::Float16, DataType::Signed32 }; supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported, @@ -445,9 +449,10 @@ bool RefLayerSupport::IsDepthwiseConvolutionSupported(const TensorInfo& input, bool supported = true; // Define supported types. - std::array supportedTypes = + std::array supportedTypes = { DataType::Float32, + DataType::Float16, DataType::QuantisedAsymm8, DataType::QuantisedSymm16 }; @@ -469,9 +474,10 @@ bool RefLayerSupport::IsDepthwiseConvolutionSupported(const TensorInfo& input, if (biases.has_value()) { - std::array biasesSupportedTypes = + std::array biasesSupportedTypes = { DataType::Float32, + DataType::Float16, DataType::Signed32 }; supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported, @@ -656,9 +662,10 @@ bool RefLayerSupport::IsFullyConnectedSupported(const TensorInfo& input, bool supported = true; // Define supported types. - std::array supportedTypes = + std::array supportedTypes = { DataType::Float32, + DataType::Float16, DataType::QuantisedAsymm8, DataType::QuantisedSymm16 }; @@ -681,10 +688,11 @@ bool RefLayerSupport::IsFullyConnectedSupported(const TensorInfo& input, if (descriptor.m_BiasEnabled) { // Defined supported types for bias - std::array + std::array supportedBiasTypes = { DataType::Float32, + DataType::Float16, DataType::Signed32 }; @@ -772,9 +780,10 @@ bool RefLayerSupport::IsL2NormalizationSupported(const TensorInfo& input, { ignore_unused(descriptor); // Define supported types - std::array supportedTypes = + std::array supportedTypes = { DataType::Float32, + DataType::Float16, DataType::QuantisedAsymm8, DataType::QuantisedSymm16 }; @@ -950,9 +959,10 @@ bool RefLayerSupport::IsMeanSupported(const TensorInfo& input, std::string meanLayerStr = "Mean"; std::string outputTensorStr = "output"; - std::array supportedTypes = + std::array supportedTypes = { DataType::Float32, + DataType::Float16, DataType::QuantisedAsymm8, DataType::QuantisedSymm16 }; @@ -1077,8 +1087,9 @@ bool RefLayerSupport::IsMultiplicationSupported(const TensorInfo& input0, { bool supported = true; - std::array supportedTypes = { + std::array supportedTypes = { DataType::Float32, + DataType::Float16, DataType::QuantisedAsymm8, DataType::QuantisedSymm16 }; @@ -1150,9 +1161,10 @@ bool RefLayerSupport::IsPadSupported(const TensorInfo& input, bool supported = true; // Define supported output and inputs types. - std::array supportedTypes = + std::array supportedTypes = { DataType::Float32, + DataType::Float16, DataType::QuantisedAsymm8, DataType::QuantisedSymm16 }; @@ -1206,9 +1218,10 @@ bool RefLayerSupport::IsPooling2dSupported(const TensorInfo& input, bool supported = true; // Define supported output and inputs types. - std::array supportedTypes = + std::array supportedTypes = { DataType::Float32, + DataType::Float16, DataType::QuantisedAsymm8, DataType::QuantisedSymm16 }; @@ -1606,9 +1619,10 @@ bool RefLayerSupport::IsTransposeConvolution2dSupported(const TensorInfo& input, { bool supported = true; - std::array supportedTypes = + std::array supportedTypes = { DataType::Float32, + DataType::Float16, DataType::QuantisedAsymm8, DataType::QuantisedSymm16 }; @@ -1630,9 +1644,10 @@ bool RefLayerSupport::IsTransposeConvolution2dSupported(const TensorInfo& input, if (biases.has_value()) { - std::array biasesSupportedTypes = + std::array biasesSupportedTypes = { DataType::Float32, + DataType::Float16, DataType::Signed32 }; supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported, diff --git a/src/backends/reference/RefWorkloadFactory.cpp b/src/backends/reference/RefWorkloadFactory.cpp index f2dfb980b3..a3d4bf08c2 100644 --- a/src/backends/reference/RefWorkloadFactory.cpp +++ b/src/backends/reference/RefWorkloadFactory.cpp @@ -131,10 +131,6 @@ std::unique_ptr RefWorkloadFactory::CreateOutput(const OutputQueueDes std::unique_ptr RefWorkloadFactory::CreateActivation(const ActivationQueueDescriptor& descriptor, const WorkloadInfo& info) const { - if (IsFloat16(info)) - { - return MakeWorkload(descriptor, info); - } return std::make_unique(descriptor, info); } @@ -184,10 +180,6 @@ std::unique_ptr RefWorkloadFactory::CreatePermute(const Permut std::unique_ptr RefWorkloadFactory::CreatePooling2d(const Pooling2dQueueDescriptor& descriptor, const WorkloadInfo& info) const { - if (IsFloat16(info)) - { - return MakeWorkload(descriptor, info); - } return std::make_unique(descriptor, info); } @@ -218,20 +210,12 @@ std::unique_ptr RefWorkloadFactory::CreateNormalization( std::unique_ptr RefWorkloadFactory::CreateAddition(const AdditionQueueDescriptor& descriptor, const WorkloadInfo& info) const { - if (IsFloat16(info)) - { - return MakeWorkload(descriptor, info); - } return std::make_unique(descriptor, info); } std::unique_ptr RefWorkloadFactory::CreateMultiplication( const MultiplicationQueueDescriptor& descriptor, const WorkloadInfo& info) const { - if (IsFloat16(info)) - { - return MakeWorkload(descriptor, info); - } return std::make_unique(descriptor, info); } @@ -293,10 +277,6 @@ std::unique_ptr RefWorkloadFactory::CreateFakeQuantization( std::unique_ptr RefWorkloadFactory::CreateL2Normalization(const L2NormalizationQueueDescriptor& descriptor, const WorkloadInfo& info) const { - if (IsFloat16(info)) - { - return MakeWorkload(descriptor, info); - } return std::make_unique(descriptor, info); } @@ -401,10 +381,6 @@ std::unique_ptr RefWorkloadFactory::CreateMaximum( std::unique_ptr RefWorkloadFactory::CreateMean( const MeanQueueDescriptor& descriptor, const WorkloadInfo& info) const { - if (IsFloat16(info)) - { - return MakeWorkload(descriptor, info); - } return std::make_unique(descriptor, info); } @@ -425,6 +401,10 @@ std::unique_ptr RefWorkloadFactory::CreatePad(const PadQueueDescripto { return std::make_unique(descriptor, info); } + else if (IsFloat16(info)) + { + return std::make_unique(descriptor, info); + } return MakeWorkload(descriptor, info); } @@ -518,10 +498,6 @@ std::unique_ptr RefWorkloadFactory::CreateTransposeConvolution2d( const TransposeConvolution2dQueueDescriptor& descriptor, const WorkloadInfo& info) const { - if (IsFloat16(info)) - { - return MakeWorkload(descriptor, info); - } return std::make_unique(descriptor, info); } diff --git a/src/backends/reference/workloads/Pad.cpp b/src/backends/reference/workloads/Pad.cpp index 5773cac6a8..42291b8661 100644 --- a/src/backends/reference/workloads/Pad.cpp +++ b/src/backends/reference/workloads/Pad.cpp @@ -158,6 +158,12 @@ template void Pad(const TensorInfo& inputInfo, const float* inputData, float* outData, const float padValue); +template void Pad(const TensorInfo& inputInfo, + const TensorInfo& outputInfo, + std::vector> m_PadList, + const Half* inputData, + Half* outData, + const float padValue); template void Pad(const TensorInfo& inputInfo, const TensorInfo& outputInfo, std::vector> m_PadList, diff --git a/src/backends/reference/workloads/RefPadWorkload.cpp b/src/backends/reference/workloads/RefPadWorkload.cpp index 5e59d83dc9..c4b9daeb4c 100644 --- a/src/backends/reference/workloads/RefPadWorkload.cpp +++ b/src/backends/reference/workloads/RefPadWorkload.cpp @@ -34,6 +34,7 @@ void RefPadWorkload::Execute() const } template class RefPadWorkload; +template class RefPadWorkload; template class RefPadWorkload; template class RefPadWorkload; diff --git a/src/backends/reference/workloads/RefPadWorkload.hpp b/src/backends/reference/workloads/RefPadWorkload.hpp index b1de53e930..d1521f4f8d 100644 --- a/src/backends/reference/workloads/RefPadWorkload.hpp +++ b/src/backends/reference/workloads/RefPadWorkload.hpp @@ -31,7 +31,8 @@ public: }; using RefPadFloat32Workload = RefPadWorkload; -using RefPadQAsymm8Workload = RefPadWorkload; -using RefPadQSymm16Workload = RefPadWorkload; +using RefPadFloat16Workload = RefPadWorkload; +using RefPadQAsymm8Workload = RefPadWorkload; +using RefPadQSymm16Workload = RefPadWorkload; } //namespace armnn -- cgit v1.2.1