未验证 提交 96964ff8 编写于 作者: L Leo Chen 提交者: GitHub

[bf16] change bf16 print behavior (#39370)

上级 f57b21e6
......@@ -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
......
......@@ -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<const unsigned short*>(&val);
x = *reinterpret_cast<const unsigned short*>(&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<const unsigned short*>(&val);
x = *reinterpret_cast<const unsigned short*>(&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<float>(a);
return os;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册