Special function implementations for half/bfloat16 packets.

Current implementations fail to consider half-float packets, only
half-float scalars.  Added specializations for packets on AVX, AVX512 and
NEON.  Added tests to `special_packetmath`.

The current `special_functions` tests would fail for half and bfloat16 due to
lack of precision. The NEON tests also fail with precision issues and
due to different handling of `sqrt(inf)`, so special functions bessel, ndtri
have been disabled.

Tested with AVX, AVX512.
This commit is contained in:
Antonio Sanchez
2020-12-02 14:00:57 -08:00
parent 305b8bd277
commit e2f21465fe
17 changed files with 418 additions and 159 deletions

View File

@@ -147,7 +147,9 @@ struct packet_traits<Eigen::half> : default_packet_traits {
HasRound = 1,
HasFloor = 1,
HasCeil = 1,
HasRint = 1
HasRint = 1,
HasBessel = 1,
HasNdtri = 1,
};
};
@@ -189,7 +191,9 @@ struct packet_traits<bfloat16> : default_packet_traits {
HasRound = 1,
HasFloor = 1,
HasCeil = 1,
HasRint = 1
HasRint = 1,
HasBessel = 1,
HasNdtri = 1,
};
};
#endif

View File

@@ -86,7 +86,9 @@ struct packet_traits<half> : default_packet_traits {
HasRound = 1,
HasFloor = 1,
HasCeil = 1,
HasRint = 1
HasRint = 1,
HasBessel = 1,
HasNdtri = 1,
};
};

View File

@@ -58,7 +58,7 @@
#define F16_PACKET_FUNCTION(PACKET_F, PACKET_F16, METHOD) \
template <> \
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED \
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC EIGEN_UNUSED \
PACKET_F16 METHOD<PACKET_F16>(const PACKET_F16& _x) { \
return float2half(METHOD<PACKET_F>(half2float(_x))); \
}

View File

@@ -192,7 +192,9 @@ struct packet_traits<float> : default_packet_traits
HasExp = 1,
HasSqrt = 1,
HasTanh = EIGEN_FAST_MATH,
HasErf = EIGEN_FAST_MATH
HasErf = EIGEN_FAST_MATH,
HasBessel = 0, // Issues with accuracy.
HasNdtri = 0
};
};
@@ -3321,7 +3323,9 @@ template<> struct packet_traits<bfloat16> : default_packet_traits
HasExp = 1,
HasSqrt = 0,
HasTanh = EIGEN_FAST_MATH,
HasErf = EIGEN_FAST_MATH
HasErf = EIGEN_FAST_MATH,
HasBessel = 0, // Issues with accuracy.
HasNdtri = 0,
};
};
@@ -3887,7 +3891,10 @@ struct packet_traits<Eigen::half> : default_packet_traits {
HasCos = 0,
HasLog = 0,
HasExp = 0,
HasSqrt = 1
HasSqrt = 1,
HasErf = EIGEN_FAST_MATH,
HasBessel = 0, // Issues with accuracy.
HasNdtri = 0,
};
};