From 9f62d33156376c040dac9a4063dc733b95c5ad27 Mon Sep 17 00:00:00 2001 From: Narumol Prangnawarat Date: Tue, 11 Jul 2023 16:49:00 +0100 Subject: IVGCVSW-7783 Add check for FP16 infinity values * Check to round to closest finite FP16 value when convert FP32 to FP16 * Unit tests to be added Signed-off-by: Narumol Prangnawarat Change-Id: If3b982ff3030379ac33c47d4be13edb0bda679f6 --- src/armnnUtils/FloatingPointConverter.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/armnnUtils') diff --git a/src/armnnUtils/FloatingPointConverter.cpp b/src/armnnUtils/FloatingPointConverter.cpp index 7a684f1eb0..024b74eea4 100644 --- a/src/armnnUtils/FloatingPointConverter.cpp +++ b/src/armnnUtils/FloatingPointConverter.cpp @@ -25,6 +25,11 @@ void FloatingPointConverter::ConvertFloat32To16(const float* srcFloat32Buffer, for (size_t i = 0; i < numElements; i++) { pHalf[i] = armnn::Half(srcFloat32Buffer[i]); + if (isinf(pHalf[i])) + { + // If the value of converted Fp16 is infinity, round to the closest finite Fp16 value. + pHalf[i] = copysign(std::numeric_limits::max(), pHalf[i]); + } } } -- cgit v1.2.1