Skip to content

Commit 8055dd1

Browse files
committed
Final fixes
Signed-off-by: Dmitry Sidorov <dmitry.sidorov@intel.com>
1 parent 0636c0b commit 8055dd1

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <CL/__spirv/spirv_ops.hpp>
1212
#include <CL/sycl/half_type.hpp>
1313

14+
#include <cmath>
15+
1416
__SYCL_INLINE_NAMESPACE(cl) {
1517
namespace sycl {
1618
namespace ext {

sycl/test/extensions/a.out

-14.1 KB
Binary file not shown.

sycl/test/extensions/bfloat16_host.cpp

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
#include <limits>
1818
#include <string>
1919

20-
using sycl::ext::intel::experimental::bfloat16;
21-
2220
// Helper to convert the expected bits to float value to compare with the result
2321
typedef union {
2422
float Value;
@@ -29,30 +27,35 @@ typedef union {
2927
} RawData;
3028
} floatConvHelper;
3129

32-
float bitsToFloatConv(std::string &Bits) {
33-
floatConvHelper &Helper;
30+
float bitsToFloatConv(std::string Bits) {
31+
floatConvHelper Helper;
3432
Helper.RawData.Sign = static_cast<uint32_t>(Bits[0] - '0');
3533
uint32_t Exponent = 0;
3634
for (size_t I = 1; I != 9; ++I)
3735
Exponent = Exponent + static_cast<uint32_t>(Bits[I] - '0') * pow(2, 8 - I);
3836
Helper.RawData.Exponent = Exponent;
3937
uint32_t Mantissa = 0;
4038
for (size_t I = 9; I != 32; ++I)
41-
Mantissa = Mantissa + static_cast<uint32_t>(Bits[I] - '0') * pow(2, 8 - I);
39+
Mantissa = Mantissa + static_cast<uint32_t>(Bits[I] - '0') * pow(2, 31 - I);
4240
Helper.RawData.Mantissa = Mantissa;
41+
return Helper.Value;
4342
}
4443

45-
inline bool check_bf16_from_float(float &Val, uint16_t &Expected) {
46-
if (from_float(Val) != Expected) {
47-
std::cout << "from_float check for Val = " << Val << " failed!\n";
44+
bool check_bf16_from_float(float Val, uint16_t Expected) {
45+
uint16_t Result = sycl::ext::intel::experimental::bfloat16::from_float(Val);
46+
if (Result != Expected) {
47+
std::cout << "from_float check for Val = " << Val << " failed!\n"
48+
<< "Expected " << Expected << " Got " << Result << "\n";
4849
return false;
4950
}
5051
return true;
5152
}
5253

53-
inline bool check_bf16_to_float(uint16_t &Val, float &Expected) {
54-
if (to_float(Val) != Expected) {
55-
std::cout << "to_float check for Val = " << Val << " failed!\n";
54+
bool check_bf16_to_float(uint16_t Val, float Expected) {
55+
float Result = sycl::ext::intel::experimental::bfloat16::to_float(Val);
56+
if (Result != Expected) {
57+
std::cout << "to_float check for Val = " << Val << " failed!\n"
58+
<< "Expected " << Expected << " Got " << Result << "\n";
5659
return false;
5760
}
5861
return true;
@@ -71,14 +74,14 @@ int main() {
7174
std::stoi("1111111111000001", nullptr, 2));
7275

7376
Success &= check_bf16_to_float(
74-
to_float(0), bitsToFloatConv("00000000000000000000000000000000"));
77+
0, bitsToFloatConv(std::string("00000000000000000000000000000000")));
7578
Success &= check_bf16_to_float(
76-
to_float(1), bitsToFloatConv("01000111100000000000000000000000"));
79+
1, bitsToFloatConv(std::string("01000111100000000000000000000000")));
7780
Success &= check_bf16_to_float(
78-
to_float(42), bitsToFloatConv("00000000001010100000000000000000"));
79-
Success &=
80-
check_bf16_to_float(to_float(std::numeric_limits<uint16_t>::max()),
81-
bitsToFloatConv("11111111111111110000000000000000"));
81+
42, bitsToFloatConv(std::string("01001010001010000000000000000000")));
82+
Success &= check_bf16_to_float(
83+
std::numeric_limits<uint16_t>::max(),
84+
bitsToFloatConv(std::string("01001111011111111111111100000000")));
8285
if (!Success)
8386
return -1;
8487
return 0;

0 commit comments

Comments
 (0)