Convert bfloat16 to single-precision. \param value binary_t() representation of bfloat16 value \return single-precision value
| 393 | /// \param value binary_t() representation of bfloat16 value |
| 394 | /// \return single-precision value |
| 395 | MEGDNN_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 |
no outgoing calls
no test coverage detected