10 #ifndef EIGEN_TYPE_CASTING_CUDA_H 11 #define EIGEN_TYPE_CASTING_CUDA_H 18 struct scalar_cast_op<float,
Eigen::half> {
19 EIGEN_EMPTY_STRUCT_CTOR(scalar_cast_op)
20 typedef
Eigen::half result_type;
21 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
Eigen::half operator() (const
float& a)
const {
22 #if defined(EIGEN_HAS_CUDA_FP16) && defined(__CUDA_ARCH__) && __CUDA_ARCH__ >= 300 23 return __float2half(a);
25 return Eigen::half(a);
31 struct functor_traits<scalar_cast_op<float,
Eigen::half> >
32 {
enum { Cost = NumTraits<float>::AddCost, PacketAccess =
false }; };
36 struct scalar_cast_op<int,
Eigen::half> {
37 EIGEN_EMPTY_STRUCT_CTOR(scalar_cast_op)
38 typedef
Eigen::half result_type;
39 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
Eigen::half operator() (const
int& a)
const {
40 #if defined(EIGEN_HAS_CUDA_FP16) && defined(__CUDA_ARCH__) && __CUDA_ARCH__ >= 300 41 return __float2half(static_cast<float>(a));
43 return Eigen::half(static_cast<float>(a));
49 struct functor_traits<scalar_cast_op<int,
Eigen::half> >
50 {
enum { Cost = NumTraits<float>::AddCost, PacketAccess =
false }; };
54 struct scalar_cast_op<
Eigen::half, float> {
55 EIGEN_EMPTY_STRUCT_CTOR(scalar_cast_op)
56 typedef
float result_type;
57 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
float operator() (const
Eigen::half& a)
const {
58 #if defined(EIGEN_HAS_CUDA_FP16) && defined(__CUDA_ARCH__) && __CUDA_ARCH__ >= 300 59 return __half2float(a);
61 return static_cast<float>(a);
67 struct functor_traits<scalar_cast_op<
Eigen::half, float> >
68 {
enum { Cost = NumTraits<float>::AddCost, PacketAccess =
false }; };
72 #if defined(EIGEN_HAS_CUDA_FP16) && defined(__CUDA_ARCH__) && __CUDA_ARCH__ >= 300 75 struct type_casting_traits<
Eigen::half, float> {
83 template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pcast<half2, float4>(
const half2& a,
const half2& b) {
84 float2 r1 = __half22float2(a);
85 float2 r2 = __half22float2(b);
86 return make_float4(r1.x, r1.y, r2.x, r2.y);
90 struct type_casting_traits<float,
Eigen::half> {
98 template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pcast<float4, half2>(
const float4& a) {
100 return __floats2half2_rn(a.x, a.y);
103 #elif defined EIGEN_VECTORIZE_AVX 106 struct type_casting_traits<
Eigen::half, float> {
114 template<> EIGEN_STRONG_INLINE Packet8f pcast<Packet8h, Packet8f>(
const Packet8h& a) {
115 return half2float(a);
119 struct type_casting_traits<float,
Eigen::half> {
127 template<> EIGEN_STRONG_INLINE Packet8h pcast<Packet8f, Packet8h>(
const Packet8f& a) {
128 return float2half(a);
136 struct type_casting_traits<
Eigen::half, float> {
144 template<> EIGEN_STRONG_INLINE Packet4f pcast<Packet4h, Packet4f>(
const Packet4h& a) {
145 __int64_t a64 = _mm_cvtm64_si64(a.x);
146 Eigen::half h = raw_uint16_to_half(static_cast<unsigned short>(a64));
147 float f1 =
static_cast<float>(h);
148 h = raw_uint16_to_half(static_cast<unsigned short>(a64 >> 16));
149 float f2 =
static_cast<float>(h);
150 h = raw_uint16_to_half(static_cast<unsigned short>(a64 >> 32));
151 float f3 =
static_cast<float>(h);
152 h = raw_uint16_to_half(static_cast<unsigned short>(a64 >> 48));
153 float f4 =
static_cast<float>(h);
154 return _mm_set_ps(f4, f3, f2, f1);
158 struct type_casting_traits<float,
Eigen::half> {
166 template<> EIGEN_STRONG_INLINE Packet4h pcast<Packet4f, Packet4h>(
const Packet4f& a) {
167 EIGEN_ALIGN16
float aux[4];
169 Eigen::half h0(aux[0]);
170 Eigen::half h1(aux[1]);
171 Eigen::half h2(aux[2]);
172 Eigen::half h3(aux[3]);
175 result.x = _mm_set_pi16(h3.x, h2.x, h1.x, h0.x);
185 #endif // EIGEN_TYPE_CASTING_CUDA_H Namespace containing all symbols from the Eigen library.
Definition: Core:271
Definition: Eigen_Colamd.h:50