Guard use of long double on GPU device.

This commit is contained in:
Antonio Sánchez 2023-02-24 21:49:59 +00:00 committed by Rasmus Munk Larsen
parent e4598fedbe
commit bc5cdc7a67
3 changed files with 20 additions and 1 deletions

View File

@ -1015,11 +1015,15 @@ template<typename T> EIGEN_DEVICE_FUNC bool isinf_msvc_helper(T x)
}
//MSVC defines a _isnan builtin function, but for double only
#ifndef EIGEN_GPU_COMPILE_PHASE
EIGEN_DEVICE_FUNC inline bool isnan_impl(const long double& x) { return _isnan(x)!=0; }
#endif
EIGEN_DEVICE_FUNC inline bool isnan_impl(const double& x) { return _isnan(x)!=0; }
EIGEN_DEVICE_FUNC inline bool isnan_impl(const float& x) { return _isnan(x)!=0; }
#ifndef EIGEN_GPU_COMPILE_PHASE
EIGEN_DEVICE_FUNC inline bool isinf_impl(const long double& x) { return isinf_msvc_helper(x); }
#endif
EIGEN_DEVICE_FUNC inline bool isinf_impl(const double& x) { return isinf_msvc_helper(x); }
EIGEN_DEVICE_FUNC inline bool isinf_impl(const float& x) { return isinf_msvc_helper(x); }
@ -1033,12 +1037,16 @@ EIGEN_DEVICE_FUNC inline bool isinf_impl(const float& x) { return isinf_ms
#define EIGEN_TMP_NOOPT_ATTRIB EIGEN_DEVICE_FUNC inline __attribute__((noinline,optimize("no-finite-math-only")))
#endif
#ifndef EIGEN_GPU_COMPILE_PHASE
template<> EIGEN_TMP_NOOPT_ATTRIB bool isnan_impl(const long double& x) { return __builtin_isnan(x); }
#endif
template<> EIGEN_TMP_NOOPT_ATTRIB bool isnan_impl(const double& x) { return __builtin_isnan(x); }
template<> EIGEN_TMP_NOOPT_ATTRIB bool isnan_impl(const float& x) { return __builtin_isnan(x); }
template<> EIGEN_TMP_NOOPT_ATTRIB bool isinf_impl(const double& x) { return __builtin_isinf(x); }
template<> EIGEN_TMP_NOOPT_ATTRIB bool isinf_impl(const float& x) { return __builtin_isinf(x); }
#ifndef EIGEN_GPU_COMPILE_PHASE
template<> EIGEN_TMP_NOOPT_ATTRIB bool isinf_impl(const long double& x) { return __builtin_isinf(x); }
#endif
#undef EIGEN_TMP_NOOPT_ATTRIB
@ -1095,6 +1103,8 @@ EIGEN_ALWAYS_INLINE double mini(const double& x, const double& y)
{
return fmin(x, y);
}
#ifndef EIGEN_GPU_COMPILE_PHASE
template<>
EIGEN_DEVICE_FUNC
EIGEN_ALWAYS_INLINE long double mini(const long double& x, const long double& y)
@ -1106,6 +1116,7 @@ EIGEN_ALWAYS_INLINE long double mini(const long double& x, const long double& y)
return fminl(x, y);
#endif
}
#endif
template<typename T>
EIGEN_DEVICE_FUNC
@ -1125,6 +1136,7 @@ EIGEN_ALWAYS_INLINE double maxi(const double& x, const double& y)
{
return fmax(x, y);
}
#ifndef EIGEN_GPU_COMPILE_PHASE
template<>
EIGEN_DEVICE_FUNC
EIGEN_ALWAYS_INLINE long double maxi(const long double& x, const long double& y)
@ -1137,6 +1149,7 @@ EIGEN_ALWAYS_INLINE long double maxi(const long double& x, const long double& y)
#endif
}
#endif
#endif
#if defined(SYCL_DEVICE_ONLY)
@ -1300,8 +1313,8 @@ EIGEN_ALWAYS_INLINE double absdiff(const double& x, const double& y)
return fabs(x - y);
}
#if !defined(EIGEN_GPUCC)
// HIP and CUDA do not support long double.
#ifndef EIGEN_GPU_COMPILE_PHASE
template<>
EIGEN_DEVICE_FUNC
EIGEN_ALWAYS_INLINE long double absdiff(const long double& x, const long double& y) {

View File

@ -243,6 +243,8 @@ template<> struct NumTraits<double> : GenericNumTraits<double>
static inline double dummy_precision() { return 1e-12; }
};
// GPU devices treat `long double` as `double`.
#ifndef EIGEN_GPU_COMPILE_PHASE
template<> struct NumTraits<long double>
: GenericNumTraits<long double>
{
@ -259,6 +261,7 @@ template<> struct NumTraits<long double>
}
#endif
};
#endif
template<typename Real_> struct NumTraits<std::complex<Real_> >
: GenericNumTraits<std::complex<Real_> >

View File

@ -135,7 +135,10 @@ using remove_all_t = typename remove_all<T>::type;
template<typename T> struct is_arithmetic { enum { value = false }; };
template<> struct is_arithmetic<float> { enum { value = true }; };
template<> struct is_arithmetic<double> { enum { value = true }; };
// GPU devices treat `long double` as `double`.
#ifndef EIGEN_GPU_COMPILE_PHASE
template<> struct is_arithmetic<long double> { enum { value = true }; };
#endif
template<> struct is_arithmetic<bool> { enum { value = true }; };
template<> struct is_arithmetic<char> { enum { value = true }; };
template<> struct is_arithmetic<signed char> { enum { value = true }; };