MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / bfloat162float

Function bfloat162float

dnn/include/megdnn/dtype/bfloat16.hpp:395–409  ·  view source on GitHub ↗

Convert bfloat16 to single-precision. \param value binary_t() representation of bfloat16 value \return single-precision value

Source from the content-addressed store, hash-verified

393/// \param value binary_t() representation of bfloat16 value
394/// \return single-precision value
395MEGDNN_HOST MEGDNN_DEVICE inline float bfloat162float(uint16 value) {
396#if HALF_ENABLE_CPP11_STATIC_ASSERT
397 static_assert(std::numeric_limits<float>::is_iec559,
398 "bfloat16 to float conversion needs IEEE 754 conformant "
399 "'float' type");
400 static_assert(sizeof(uint32) == sizeof(float),
401 "bfloat16 to float conversion needs unsigned integer type of "
402 "exactly the size of a 'float'");
403#endif
404 union {
405 uint32_t int_raw;
406 float fraw;
407 } r = {uint32_t(value) << 16};
408 return r.fraw;
409}
410
411/// Convert bfloat16 floating point to integer.
412/// \tparam T type to convert to (buitlin integer type with at least 16 bits

Callers 2

bfloat162intFunction · 0.85
bfloat16Class · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected