From b6786ff7bad9fdb0efad67a062a45b8681e7c64a Mon Sep 17 00:00:00 2001 From: Rane2021 <107022189+Rane2021@users.noreply.github.com> Date: Wed, 23 Aug 2023 10:26:27 +0800 Subject: [PATCH] [ROCM]fix bfloat16 to float error! (#56517) --- paddle/phi/common/bfloat16.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/paddle/phi/common/bfloat16.h b/paddle/phi/common/bfloat16.h index ccaf9b82bc5..028851e34c8 100644 --- a/paddle/phi/common/bfloat16.h +++ b/paddle/phi/common/bfloat16.h @@ -157,7 +157,9 @@ struct PADDLE_ALIGN(2) bfloat16 { uint16_t temp = x; uint16_t* temp_ptr = reinterpret_cast(&temp); res = *temp_ptr; - return res; + // return res; + res = res << 16; + return *reinterpret_cast(&res); #else #ifdef PADDLE_CUDA_BF16 return __bfloat162float(*reinterpret_cast(&x)); -- GitLab