Skip to content

Commit 66e469b

Browse files
authored
[SYCL] Fix bfloat16::to_float() host implementation. (#6675)
* [SYCL] Fix bfloat16::to_float() host implementation. Signed-off-by: Konstantin S Bobrovsky <[email protected]>
1 parent 346a6c5 commit 66e469b

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

sycl/include/sycl/ext/oneapi/experimental/bfloat16.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,9 @@ class bfloat16 {
6363
return __spirv_ConvertBF16ToFINTEL(a);
6464
#endif
6565
#else
66-
// Shift temporary variable to silence the warning
6766
uint32_t bits = a;
6867
bits <<= 16;
69-
return static_cast<float>(bits);
68+
return sycl::bit_cast<float>(bits);
7069
#endif
7170
}
7271

sycl/test/extensions/bfloat16_host.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,17 @@ int main() {
7373
Success &= check_bf16_from_float(std::numeric_limits<float>::quiet_NaN(),
7474
std::stoi("1111111111000001", nullptr, 2));
7575

76+
// see https://float.exposed/b0xffff
7677
Success &= check_bf16_to_float(
7778
0, bitsToFloatConv(std::string("00000000000000000000000000000000")));
7879
Success &= check_bf16_to_float(
79-
1, bitsToFloatConv(std::string("01000111100000000000000000000000")));
80+
1, bitsToFloatConv(std::string("00000000000000010000000000000000")));
8081
Success &= check_bf16_to_float(
81-
42, bitsToFloatConv(std::string("01001010001010000000000000000000")));
82+
42, bitsToFloatConv(std::string("00000000001010100000000000000000")));
8283
Success &= check_bf16_to_float(
83-
std::numeric_limits<uint16_t>::max(),
84-
bitsToFloatConv(std::string("01001111011111111111111100000000")));
84+
// std::numeric_limits<uint16_t>::max() - 0xffff is bfloat16 -Nan and
85+
// -Nan == -Nan check in check_bf16_to_float would fail, so use not Nan:
86+
65407, bitsToFloatConv(std::string("11111111011111110000000000000000")));
8587
if (!Success)
8688
return -1;
8789
return 0;

0 commit comments

Comments
 (0)