ArmNN
 24.08
FloatingPointConverter Class Reference

#include <FloatingPointConverter.hpp>

Static Public Member Functions

static void ConvertFloat32To16 (const float *srcFloat32Buffer, size_t numElements, void *dstFloat16Buffer)
 Converts a buffer of FP32 values to FP16, and stores in the given dstFloat16Buffer. More...
 
static void ConvertFloat16To32 (const void *srcFloat16Buffer, size_t numElements, float *dstFloat32Buffer)
 
static void ConvertFloat32ToBFloat16 (const float *srcFloat32Buffer, size_t numElements, void *dstBFloat16Buffer)
 
static void ConvertBFloat16ToFloat32 (const void *srcBFloat16Buffer, size_t numElements, float *dstFloat32Buffer)
 

Detailed Description

Definition at line 13 of file FloatingPointConverter.hpp.

Member Function Documentation

◆ ConvertBFloat16ToFloat32()

static void ConvertBFloat16ToFloat32 ( const void *  srcBFloat16Buffer,
size_t  numElements,
float *  dstFloat32Buffer 
)
static

◆ ConvertFloat16To32()

void ConvertFloat16To32 ( const void *  srcFloat16Buffer,
size_t  numElements,
float *  dstFloat32Buffer 
)
static

Definition at line 43 of file FloatingPointConverter.cpp.

46 {
47  if (srcFloat16Buffer == nullptr)
48  {
49  throw armnn::InvalidArgumentException("ConvertFloat16To32: source float16 buffer pointer is null");
50  }
51  if (dstFloat32Buffer == nullptr)
52  {
53  throw armnn::InvalidArgumentException("ConvertFloat16To32: destination float32 buffer pointer is null");
54  }
55 
56  const armnn::Half* pHalf = static_cast<const armnn::Half*>(srcFloat16Buffer);
57 
58  for (size_t i = 0; i < numElements; i++)
59  {
60  dstFloat32Buffer[i] = pHalf[i];
61  }
62 }

Referenced by armnn::AttemptBackendAssignment(), Float16Decoder::DecodeTensor(), NeonConvertFp16ToFp32Workload::Execute(), Float16ToFloat32::Func(), Float16Decoder::Get(), and Float16Encoder::Get().

◆ ConvertFloat32To16()

void ConvertFloat32To16 ( const float *  srcFloat32Buffer,
size_t  numElements,
void *  dstFloat16Buffer 
)
static

Converts a buffer of FP32 values to FP16, and stores in the given dstFloat16Buffer.

dstFloat16Buffer should be (numElements * 2) in size

Definition at line 17 of file FloatingPointConverter.cpp.

20 {
21  if (srcFloat32Buffer == nullptr)
22  {
23  throw armnn::InvalidArgumentException("ConvertFloat32To16: source float32 buffer pointer is null");
24  }
25  if (dstFloat16Buffer == nullptr)
26  {
27  throw armnn::InvalidArgumentException("ConvertFloat32To16: destination float16 buffer pointer is null");
28  }
29 
30  armnn::Half* pHalf = static_cast<armnn::Half*>(dstFloat16Buffer);
31 
32  for (size_t i = 0; i < numElements; i++)
33  {
34  pHalf[i] = armnn::Half(srcFloat32Buffer[i]);
35  if (isinf(pHalf[i]))
36  {
37  // If the value of converted Fp16 is infinity, round to the closest finite Fp16 value.
38  pHalf[i] = copysign(std::numeric_limits<armnn::Half>::max(), pHalf[i]);
39  }
40  }
41 }

Referenced by NeonConvertFp32ToFp16Workload::Execute(), Float32ToFloat16::Func(), and Float16Encoder::Set().

◆ ConvertFloat32ToBFloat16()

static void ConvertFloat32ToBFloat16 ( const float *  srcFloat32Buffer,
size_t  numElements,
void *  dstBFloat16Buffer 
)
static

The documentation for this class was generated from the following files:
armnn::Half
half_float::half Half
Definition: Half.hpp:22
armnn::InvalidArgumentException
Definition: Exceptions.hpp:80