[ROCm] fix uninitialized warning in BFloat16.h (#149868)

Pull Request resolved: https://github.com/pytorch/pytorch/pull/149868
Approved by: https://github.com/jeffdaily, https://github.com/cyyever
This commit is contained in:
Ethan Wee 2025-03-25 23:36:07 +00:00 committed by PyTorch MergeBot
parent 36eb64d60e
commit c05328e01a

View File

@ -31,7 +31,7 @@ inline C10_HOST_DEVICE float f32_from_bits(uint16_t src) {
uint32_t tmp = src;
tmp <<= 16;
#if defined(USE_ROCM)
#if defined(USE_ROCM) && defined(__HIPCC__)
float* tempRes;
// We should be using memcpy in order to respect the strict aliasing rule
@ -48,7 +48,7 @@ inline C10_HOST_DEVICE float f32_from_bits(uint16_t src) {
inline C10_HOST_DEVICE uint16_t bits_from_f32(float src) {
uint32_t res = 0;
#if defined(USE_ROCM)
#if defined(USE_ROCM) && defined(__HIPCC__)
// We should be using memcpy in order to respect the strict aliasing rule
// but it fails in the HIP environment.
uint32_t* tempRes = reinterpret_cast<uint32_t*>(&src);
@ -61,7 +61,7 @@ inline C10_HOST_DEVICE uint16_t bits_from_f32(float src) {
}
inline C10_HOST_DEVICE uint16_t round_to_nearest_even(float src) {
#if defined(USE_ROCM)
#if defined(USE_ROCM) && defined(__HIPCC__)
if (src != src) {
#elif defined(_MSC_VER)
if (isnan(src)) {
@ -87,7 +87,7 @@ struct alignas(2) BFloat16 {
uint16_t x;
// HIP wants __host__ __device__ tag, CUDA does not
#if defined(USE_ROCM)
#if defined(USE_ROCM) && defined(__HIPCC__)
C10_HOST_DEVICE BFloat16() = default;
#else
BFloat16() = default;