diff --git a/c10/util/BFloat16.h b/c10/util/BFloat16.h index 09d3051ab71..93d0ec54fb0 100644 --- a/c10/util/BFloat16.h +++ b/c10/util/BFloat16.h @@ -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(&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;