Make half/bfloat16 constructor take inputs by value, fix powerpc test.

Since `numeric_limits<half>::max_exponent` is a static inline constant,
it cannot be directly passed by reference. This triggers a linker error
in recent versions of `g++-powerpc64le`.

Changing `half` to take inputs by value fixes this.  Wrapping
`max_exponent` with `int(...)` to make an addressable integer also fixes this
and may help with other custom `Scalar` types down-the-road.

Also eliminated some compile warnings for powerpc.
This commit is contained in:
Antonio Sanchez 2021-02-26 15:25:00 -08:00 committed by David Tellenbach
parent 39a590dfb6
commit c65c2b31d4
4 changed files with 9 additions and 3 deletions

View File

@ -212,12 +212,18 @@ template<>
EIGEN_STRONG_INLINE void pgerMMA<Packet4f, __vector_pair, false>(__vector_quad *acc, const __vector_pair& a, const Packet4f& b) EIGEN_STRONG_INLINE void pgerMMA<Packet4f, __vector_pair, false>(__vector_quad *acc, const __vector_pair& a, const Packet4f& b)
{ {
// Just for compilation // Just for compilation
EIGEN_UNUSED_VARIABLE(acc)
EIGEN_UNUSED_VARIABLE(a)
EIGEN_UNUSED_VARIABLE(b)
} }
template<> template<>
EIGEN_STRONG_INLINE void pgerMMA<Packet4f, __vector_pair, true>(__vector_quad *acc, const __vector_pair& a, const Packet4f& b) EIGEN_STRONG_INLINE void pgerMMA<Packet4f, __vector_pair, true>(__vector_quad *acc, const __vector_pair& a, const Packet4f& b)
{ {
// Just for compilation // Just for compilation
EIGEN_UNUSED_VARIABLE(acc)
EIGEN_UNUSED_VARIABLE(a)
EIGEN_UNUSED_VARIABLE(b)
} }
// This is necessary because ploadRhs for double returns a pair of vectors when MMA is enabled. // This is necessary because ploadRhs for double returns a pair of vectors when MMA is enabled.

View File

@ -67,7 +67,7 @@ struct bfloat16 : public bfloat16_impl::bfloat16_base {
: bfloat16_impl::bfloat16_base(bfloat16_impl::raw_uint16_to_bfloat16(b ? 0x3f80 : 0)) {} : bfloat16_impl::bfloat16_base(bfloat16_impl::raw_uint16_to_bfloat16(b ? 0x3f80 : 0)) {}
template<class T> template<class T>
explicit EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bfloat16(const T& val) explicit EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bfloat16(T val)
: bfloat16_impl::bfloat16_base(bfloat16_impl::float_to_bfloat16_rtne<internal::is_integral<T>::value>(static_cast<float>(val))) {} : bfloat16_impl::bfloat16_base(bfloat16_impl::float_to_bfloat16_rtne<internal::is_integral<T>::value>(static_cast<float>(val))) {}
explicit EIGEN_DEVICE_FUNC bfloat16(float f) explicit EIGEN_DEVICE_FUNC bfloat16(float f)

View File

@ -147,7 +147,7 @@ struct half : public half_impl::half_base {
explicit EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR half(bool b) explicit EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR half(bool b)
: half_impl::half_base(half_impl::raw_uint16_to_half(b ? 0x3c00 : 0)) {} : half_impl::half_base(half_impl::raw_uint16_to_half(b ? 0x3c00 : 0)) {}
template<class T> template<class T>
explicit EIGEN_DEVICE_FUNC half(const T& val) explicit EIGEN_DEVICE_FUNC half(T val)
: half_impl::half_base(half_impl::float_to_half_rtne(static_cast<float>(val))) {} : half_impl::half_base(half_impl::float_to_half_rtne(static_cast<float>(val))) {}
explicit EIGEN_DEVICE_FUNC half(float f) explicit EIGEN_DEVICE_FUNC half(float f)
: half_impl::half_base(half_impl::float_to_half_rtne(f)) {} : half_impl::half_base(half_impl::float_to_half_rtne(f)) {}

View File

@ -25,7 +25,7 @@ void pow_test() {
const Scalar denorm_min = std::numeric_limits<Scalar>::denorm_min(); const Scalar denorm_min = std::numeric_limits<Scalar>::denorm_min();
const Scalar min = (std::numeric_limits<Scalar>::min)(); const Scalar min = (std::numeric_limits<Scalar>::min)();
const Scalar max = (std::numeric_limits<Scalar>::max)(); const Scalar max = (std::numeric_limits<Scalar>::max)();
const Scalar max_exp = (static_cast<Scalar>(std::numeric_limits<Scalar>::max_exponent) * Scalar(EIGEN_LN2)) / eps; const Scalar max_exp = (static_cast<Scalar>(int(std::numeric_limits<Scalar>::max_exponent)) * Scalar(EIGEN_LN2)) / eps;
const static Scalar abs_vals[] = {zero, const static Scalar abs_vals[] = {zero,
denorm_min, denorm_min,