diff --git a/paddle/fluid/platform/bfloat16_test.cc b/paddle/fluid/platform/bfloat16_test.cc index cac9767dc2948fb1c272f20a5593dc4d3a499cc0..d193f7a0c5b99c3b962eee6d49bf0f5e572d6bdd 100644 --- a/paddle/fluid/platform/bfloat16_test.cc +++ b/paddle/fluid/platform/bfloat16_test.cc @@ -132,7 +132,11 @@ TEST(bfloat16, floating) { TEST(bfloat16, print) { bfloat16 a = bfloat16(1.0f); - std::cout << a << std::endl; + std::cout << "a:" << a << std::endl; + std::stringstream ss1, ss2; + ss1 << a; + ss2 << 1.0f; + EXPECT_EQ(ss1.str(), ss2.str()); } // CPU test diff --git a/paddle/pten/common/bfloat16.h b/paddle/pten/common/bfloat16.h index 0d9db3dbe9b15929e55bdc867d16ad71d0a01598..56ba7fb54f0a0eeeb2188083d4abd4a2404272cf 100644 --- a/paddle/pten/common/bfloat16.h +++ b/paddle/pten/common/bfloat16.h @@ -82,7 +82,7 @@ struct PADDLE_ALIGN(2) bfloat16 { #if defined(PADDLE_CUDA_BF16) HOSTDEVICE inline explicit bfloat16(const __nv_bfloat16& val) { - x = *reinterpret_cast(&val); + x = *reinterpret_cast(&val); // NOLINT } #endif @@ -93,7 +93,7 @@ struct PADDLE_ALIGN(2) bfloat16 { // Assignment operators #if defined(PADDLE_CUDA_BF16) HOSTDEVICE inline bfloat16& operator=(const __nv_bfloat16& val) { - x = *reinterpret_cast(&val); + x = *reinterpret_cast(&val); // NOLINT return *this; } #endif @@ -311,7 +311,7 @@ HOSTDEVICE inline bool(isfinite)(const bfloat16& a) { } inline std::ostream& operator<<(std::ostream& os, const bfloat16& a) { - os << a.x; + os << static_cast(a); return os; }