| 21 | namespace test { |
| 22 | |
| 23 | float float_from_bytes(uint32_t sign, uint32_t exponent, uint32_t fraction) { |
| 24 | // reference: pytorch/c10/test/util/bfloat16_test.cpp |
| 25 | // https://github.com/pytorch/pytorch/blob/release/1.12/c10/test/util/bfloat16_test.cpp |
| 26 | uint32_t bytes = 0; |
| 27 | bytes |= sign; |
| 28 | bytes <<= 8; |
| 29 | bytes |= exponent; |
| 30 | bytes <<= 23; |
| 31 | bytes |= fraction; |
| 32 | float res = NAN; |
| 33 | std::memcpy(&res, &bytes, sizeof(res)); |
| 34 | return res; |
| 35 | } |
| 36 | |
| 37 | TEST(BFLOAT16MATH, Add) { |
| 38 | // 6.25 |