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_AVX512 105 struct type_casting_traits<half, float> {
113 template<> EIGEN_STRONG_INLINE Packet16f pcast<Packet16h, Packet16f>(
const Packet16h& a) {
114 return half2float(a);
118 struct type_casting_traits<float, half> {
126 template<> EIGEN_STRONG_INLINE Packet16h pcast<Packet16f, Packet16h>(
const Packet16f& a) {
127 return float2half(a);
130 #elif defined EIGEN_VECTORIZE_AVX 133 struct type_casting_traits<
Eigen::half, float> {
141 template<> EIGEN_STRONG_INLINE Packet8f pcast<Packet8h, Packet8f>(
const Packet8h& a) {
142 return half2float(a);
146 struct type_casting_traits<float,
Eigen::half> {
154 template<> EIGEN_STRONG_INLINE Packet8h pcast<Packet8f, Packet8h>(
const Packet8f& a) {
155 return float2half(a);
163 struct type_casting_traits<
Eigen::half, float> {
171 template<> EIGEN_STRONG_INLINE Packet4f pcast<Packet4h, Packet4f>(
const Packet4h& a) {
172 __int64_t a64 = _mm_cvtm64_si64(a.x);
173 Eigen::half h = raw_uint16_to_half(static_cast<unsigned short>(a64));
174 float f1 =
static_cast<float>(h);
175 h = raw_uint16_to_half(static_cast<unsigned short>(a64 >> 16));
176 float f2 =
static_cast<float>(h);
177 h = raw_uint16_to_half(static_cast<unsigned short>(a64 >> 32));
178 float f3 =
static_cast<float>(h);
179 h = raw_uint16_to_half(static_cast<unsigned short>(a64 >> 48));
180 float f4 =
static_cast<float>(h);
181 return _mm_set_ps(f4, f3, f2, f1);
185 struct type_casting_traits<float,
Eigen::half> {
193 template<> EIGEN_STRONG_INLINE Packet4h pcast<Packet4f, Packet4h>(
const Packet4f& a) {
194 EIGEN_ALIGN16
float aux[4];
196 Eigen::half h0(aux[0]);
197 Eigen::half h1(aux[1]);
198 Eigen::half h2(aux[2]);
199 Eigen::half h3(aux[3]);
202 result.x = _mm_set_pi16(h3.x, h2.x, h1.x, h0.x);
212 #endif // EIGEN_TYPE_CASTING_CUDA_H Namespace containing all symbols from the Eigen library.
Definition: Core:287
Definition: Eigen_Colamd.h:50