diff --git a/Eigen/src/Core/util/Macros.h b/Eigen/src/Core/util/Macros.h index 183300928..bdc0de0ea 100644 --- a/Eigen/src/Core/util/Macros.h +++ b/Eigen/src/Core/util/Macros.h @@ -763,8 +763,6 @@ #if EIGEN_MAX_CPP_VER>=14 && (EIGEN_COMP_CXXVER >= 11 && (EIGEN_COMP_CLANG || EIGEN_COMP_NVCC >= 70500)) #define EIGEN_HAS_CONSTEXPR 1 #endif - #elif defined(EIGEN_HIPCC) - // Skip const_expr on the HIP platform #elif EIGEN_MAX_CPP_VER>=14 && (__has_feature(cxx_relaxed_constexpr) || (EIGEN_COMP_CXXVER >= 14) || \ (EIGEN_GNUC_AT_LEAST(4,8) && (EIGEN_COMP_CXXVER >= 11)) || \ (EIGEN_COMP_CLANG >= 306 && (EIGEN_COMP_CXXVER >= 11))) diff --git a/Eigen/src/Core/util/Meta.h b/Eigen/src/Core/util/Meta.h index 85d35fc4e..f66325f89 100755 --- a/Eigen/src/Core/util/Meta.h +++ b/Eigen/src/Core/util/Meta.h @@ -275,7 +275,7 @@ template struct enable_if; template struct enable_if { typedef T type; }; -#if defined(EIGEN_GPU_COMPILE_PHASE) +#if defined(EIGEN_GPU_COMPILE_PHASE) && !EIGEN_HAS_CXX11 #if !defined(__FLT_EPSILON__) #define __FLT_EPSILON__ FLT_EPSILON #define __DBL_EPSILON__ DBL_EPSILON @@ -296,7 +296,7 @@ template<> struct numeric_limits { EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static float epsilon() { return __FLT_EPSILON__; } - EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR + EIGEN_DEVICE_FUNC static float (max)() { #if defined(EIGEN_CUDA_ARCH) return CUDART_MAX_NORMAL_F; @@ -306,7 +306,7 @@ template<> struct numeric_limits } EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static float (min)() { return FLT_MIN; } - EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR + EIGEN_DEVICE_FUNC static float infinity() { #if defined(EIGEN_CUDA_ARCH) return CUDART_INF_F; @@ -314,7 +314,7 @@ template<> struct numeric_limits return HIPRT_INF_F; #endif } - EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR + EIGEN_DEVICE_FUNC static float quiet_NaN() { #if defined(EIGEN_CUDA_ARCH) return CUDART_NAN_F; @@ -331,7 +331,7 @@ template<> struct numeric_limits static double (max)() { return DBL_MAX; } EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static double (min)() { return DBL_MIN; } - EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR + EIGEN_DEVICE_FUNC static double infinity() { #if defined(EIGEN_CUDA_ARCH) return CUDART_INF; @@ -339,7 +339,7 @@ template<> struct numeric_limits return HIPRT_INF; #endif } - EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR + EIGEN_DEVICE_FUNC static double quiet_NaN() { #if defined(EIGEN_CUDA_ARCH) return CUDART_NAN; @@ -414,7 +414,7 @@ template<> struct numeric_limits } -#endif +#endif // defined(EIGEN_GPU_COMPILE_PHASE) && !EIGEN_HAS_CXX11 /** \internal * A base class do disable default copy ctor and copy assignment operator. @@ -761,7 +761,7 @@ template EIGEN_DEVICE_FUNC void swap(T &a, T &b) { T tmp = b; b = template EIGEN_STRONG_INLINE void swap(T &a, T &b) { std::swap(a,b); } #endif -#if defined(EIGEN_GPU_COMPILE_PHASE) +#if defined(EIGEN_GPU_COMPILE_PHASE) && !EIGEN_HAS_CXX11 using internal::device::numeric_limits; #else using std::numeric_limits; diff --git a/test/gpu_basic.cu b/test/gpu_basic.cu index b2e657e72..bf8dcacde 100644 --- a/test/gpu_basic.cu +++ b/test/gpu_basic.cu @@ -343,6 +343,21 @@ struct matrix_inverse { } }; +template +struct numeric_limits_test { + EIGEN_DEVICE_FUNC + void operator()(int i, const typename T::Scalar* in, typename T::Scalar* out) const + { + EIGEN_UNUSED_VARIABLE(in) + int out_idx = i * 5; + out[out_idx++] = numext::numeric_limits::epsilon(); + out[out_idx++] = (numext::numeric_limits::max)(); + out[out_idx++] = (numext::numeric_limits::min)(); + out[out_idx++] = numext::numeric_limits::infinity(); + out[out_idx++] = numext::numeric_limits::quiet_NaN(); + } +}; + template bool verifyIsApproxWithInfsNans(const Type1& a, const Type2& b, typename Type1::Scalar* = 0) // Enabled for Eigen's type only { @@ -434,6 +449,9 @@ EIGEN_DECLARE_TEST(gpu_basic) CALL_SUBTEST( run_and_compare_to_gpu(complex_operators(), nthreads, cfin, cfout) ); CALL_SUBTEST( test_with_infs_nans(complex_sqrt(), nthreads, cfin, cfout) ); + // numeric_limits + CALL_SUBTEST( test_with_infs_nans(numeric_limits_test(), 1, in, out) ); + #if defined(__NVCC__) // FIXME // These subtests compiles only with nvcc and fail with HIPCC and clang-cuda