File tree Expand file tree Collapse file tree 2 files changed +7
-6
lines changed
include/sycl/ext/oneapi/experimental Expand file tree Collapse file tree 2 files changed +7
-6
lines changed Original file line number Diff line number Diff line change @@ -63,10 +63,9 @@ class bfloat16 {
63
63
return __spirv_ConvertBF16ToFINTEL (a);
64
64
#endif
65
65
#else
66
- // Shift temporary variable to silence the warning
67
66
uint32_t bits = a;
68
67
bits <<= 16 ;
69
- return static_cast <float >(bits);
68
+ return sycl::bit_cast <float >(bits);
70
69
#endif
71
70
}
72
71
Original file line number Diff line number Diff line change @@ -73,15 +73,17 @@ int main() {
73
73
Success &= check_bf16_from_float (std::numeric_limits<float >::quiet_NaN (),
74
74
std::stoi (" 1111111111000001" , nullptr , 2 ));
75
75
76
+ // see https://float.exposed/b0xffff
76
77
Success &= check_bf16_to_float (
77
78
0 , bitsToFloatConv (std::string (" 00000000000000000000000000000000" )));
78
79
Success &= check_bf16_to_float (
79
- 1 , bitsToFloatConv (std::string (" 01000111100000000000000000000000 " )));
80
+ 1 , bitsToFloatConv (std::string (" 00000000000000010000000000000000 " )));
80
81
Success &= check_bf16_to_float (
81
- 42 , bitsToFloatConv (std::string (" 01001010001010000000000000000000 " )));
82
+ 42 , bitsToFloatConv (std::string (" 00000000001010100000000000000000 " )));
82
83
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" )));
85
87
if (!Success)
86
88
return -1 ;
87
89
return 0 ;
You can’t perform that action at this time.
0 commit comments