FP16 to FP32 precision utilities¶
Overview¶
Set of functions to convert from FP32 to FP16 and vice versa. More…
// namespaces
namespace InferenceEngine::PrecisionUtils;
namespace InferenceEngine::PrecisionUtils::details;
// typedefs
typedef short InferenceEngine::ie_fp16;
// global functions
ie_fp16 InferenceEngine::PrecisionUtils::f32tof16(float x);
float InferenceEngine::PrecisionUtils::f16tof32(ie_fp16 x);
void InferenceEngine::PrecisionUtils::f16tof32Arrays(
float \* dst,
const ie_fp16 \* src,
size_t nelem,
float scale = 1.f,
float bias = 0.f
);
void InferenceEngine::PrecisionUtils::f32tof16Arrays(
ie_fp16 \* dst,
const float \* src,
size_t nelem,
float scale = 1.f,
float bias = 0.f
);
template <
class OutT,
class InT,
typename std::enable_if<std::is_integral<OutT>::value&&std::is_integral<InT>::value&&std::is_signed<InT>::value&&!std::is_same<OutT, InT>::value>::type \* = nullptr
>
OutT InferenceEngine::PrecisionUtils::saturate_cast(const InT& value);
template <class InT>
InT InferenceEngine::PrecisionUtils::saturate_cast(const InT& value);
Detailed Documentation¶
Set of functions to convert from FP32 to FP16 and vice versa.
Typedefs¶
typedef short InferenceEngine::ie_fp16
A type difinition for FP16 data type. Defined as a singed short.
Global Functions¶
ie_fp16 InferenceEngine::PrecisionUtils::f32tof16(float x)
Converts a single-precision floating point value to a half-precision floating poit value.
Parameters:
x |
A single-precision floating point value |
Returns:
A half-precision floating point value
float InferenceEngine::PrecisionUtils::f16tof32(ie_fp16 x)
Convers a half-precision floating point value to a single-precision floating point value.
Parameters:
x |
A half-precision floating point value |
Returns:
A single-precision floating point value
void InferenceEngine::PrecisionUtils::f16tof32Arrays(
float \* dst,
const ie_fp16 \* src,
size_t nelem,
float scale = 1.f,
float bias = 0.f
)
Converts a half-precision floating point array to single-precision floating point array and applies scale
and bias
is needed.
Parameters:
dst |
A destination array of single-precision floating point values |
src |
A source array of half-precision floating point values |
nelem |
A number of elements in arrays |
scale |
An optional scale parameter |
bias |
An optional bias parameter |
void InferenceEngine::PrecisionUtils::f32tof16Arrays(
ie_fp16 \* dst,
const float \* src,
size_t nelem,
float scale = 1.f,
float bias = 0.f
)
Converts a single-precision floating point array to a half-precision floating point array and applies scale
and bias
if needed.
Parameters:
dst |
A destination array of half-precision floating point values |
src |
A sources array of single-precision floating point values |
nelem |
A number of elements in arrays |
scale |
An optional scale parameter |
bias |
An optional bias parameter |
template <
class OutT,
class InT,
typename std::enable_if<std::is_integral<OutT>::value&&std::is_integral<InT>::value&&std::is_signed<InT>::value&&!std::is_same<OutT, InT>::value>::type \* = nullptr
>
OutT InferenceEngine::PrecisionUtils::saturate_cast(const InT& value)
Converts one integral type to another saturating the result if the source value doesn’t fit into destination type range.
Parameters:
value |
Value to be converted |
Returns:
A saturated value
template <class InT>
InT InferenceEngine::PrecisionUtils::saturate_cast(const InT& value)
Converts one integral type to another saturating the result if the source value doesn’t fit into destination type range.
Parameters:
value |
Value to be converted |
Returns:
A saturated value