[ROCm] float16.h should use __HIP__ not USE_ROCM (#13684)

The float16.h header is shared between the CPU and ROCm EPs. The
USE_ROCM macro is defined universally, but for the float16.h header we
only wish to detect the hip-clang compiler. Otherwise, the CPU EP fails
to build because of -Werror -Wuninitialized caused by the USE_ROCM code
additions, and the CPU EP should be using a different code path.
This commit is contained in:
Jeff Daily 2022-12-13 15:34:42 -08:00 committed by GitHub
parent 9dd593e18f
commit c9edc01c0b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -41,7 +41,7 @@ inline bool operator<(const MLFloat16& left, const MLFloat16& right) { return le
// BFloat16
struct BFloat16 {
uint16_t val{0};
#if defined(USE_ROCM)
#if defined(__HIP__)
ORT_HOST_DEVICE BFloat16() = default;
#else
BFloat16() = default;
@ -54,7 +54,7 @@ struct BFloat16 {
inline ORT_HOST_DEVICE BFloat16(float v) {
#if defined(CUDA_VERSION) && CUDA_VERSION >= 11000 && defined(__CUDA_ARCH__) && __CUDA_ARCH__ >= 800
val = __bfloat16_as_ushort(__float2bfloat16(v));
#elif defined(USE_ROCM)
#elif defined(__HIP__)
// We should be using memcpy in order to respect the strict aliasing rule but it fails in the HIP environment.
if (v != v) { // isnan
val = UINT16_C(0x7FC0);
@ -81,7 +81,7 @@ struct BFloat16 {
inline ORT_HOST_DEVICE float ToFloat() const {
#if defined(CUDA_VERSION) && CUDA_VERSION >= 11000
return __bfloat162float(*reinterpret_cast<const __nv_bfloat16*>(&val));
#elif defined(USE_ROCM)
#elif defined(__HIP__)
// We should be using memcpy in order to respect the strict aliasing rule but it fails in the HIP environment.
float result = 0;
uint32_t tmp = val;