10#ifndef EIGEN_PACKET_MATH_GPU_H
11#define EIGEN_PACKET_MATH_GPU_H
14#include "../../InternalHeaderCheck.h"
21#if defined(EIGEN_HIP_DEVICE_COMPILE) || (defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 350)
22#define EIGEN_GPU_HAS_LDG 1
26#if (defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 530)
27#define EIGEN_CUDA_HAS_FP16_ARITHMETIC 1
30#if defined(EIGEN_HIP_DEVICE_COMPILE) || defined(EIGEN_CUDA_HAS_FP16_ARITHMETIC)
31#define EIGEN_GPU_HAS_FP16_ARITHMETIC 1
37#if defined(EIGEN_GPUCC) && defined(EIGEN_USE_GPU)
40struct is_arithmetic<float4> {
41 enum { value =
true };
44struct is_arithmetic<double2> {
45 enum { value =
true };
49struct packet_traits<float> : default_packet_traits {
74 HasGammaSampleDerAlpha = 1,
82struct packet_traits<double> : default_packet_traits {
105 HasGammaSampleDerAlpha = 1,
113struct unpacket_traits<float4> {
119 masked_load_available =
false,
120 masked_store_available =
false
125struct unpacket_traits<double2> {
131 masked_load_available =
false,
132 masked_store_available =
false
134 typedef double2 half;
138EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pset1<float4>(
const float& from) {
139 return make_float4(from, from, from, from);
142EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 pset1<double2>(
const double& from) {
143 return make_double2(from, from);
149#if defined(EIGEN_CUDA_ARCH) || defined(EIGEN_HIPCC) || (defined(EIGEN_CUDACC) && EIGEN_COMP_CLANG && !EIGEN_COMP_NVCC)
151EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
float bitwise_and(
const float& a,
const float& b) {
152 return __int_as_float(__float_as_int(a) & __float_as_int(b));
154EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
double bitwise_and(
const double& a,
const double& b) {
155 return __longlong_as_double(__double_as_longlong(a) & __double_as_longlong(b));
158EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
float bitwise_or(
const float& a,
const float& b) {
159 return __int_as_float(__float_as_int(a) | __float_as_int(b));
161EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
double bitwise_or(
const double& a,
const double& b) {
162 return __longlong_as_double(__double_as_longlong(a) | __double_as_longlong(b));
165EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
float bitwise_xor(
const float& a,
const float& b) {
166 return __int_as_float(__float_as_int(a) ^ __float_as_int(b));
168EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
double bitwise_xor(
const double& a,
const double& b) {
169 return __longlong_as_double(__double_as_longlong(a) ^ __double_as_longlong(b));
172EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
float bitwise_andnot(
const float& a,
const float& b) {
173 return __int_as_float(__float_as_int(a) & ~__float_as_int(b));
175EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
double bitwise_andnot(
const double& a,
const double& b) {
176 return __longlong_as_double(__double_as_longlong(a) & ~__double_as_longlong(b));
178EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
float eq_mask(
const float& a,
const float& b) {
179 return __int_as_float(a == b ? 0xffffffffu : 0u);
181EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
double eq_mask(
const double& a,
const double& b) {
182 return __longlong_as_double(a == b ? 0xffffffffffffffffull : 0ull);
185EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
float lt_mask(
const float& a,
const float& b) {
186 return __int_as_float(a < b ? 0xffffffffu : 0u);
189EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
double lt_mask(
const double& a,
const double& b) {
190 return __longlong_as_double(a < b ? 0xffffffffffffffffull : 0ull);
193EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
float le_mask(
const float& a,
const float& b) {
194 return __int_as_float(a <= b ? 0xffffffffu : 0u);
197EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
double le_mask(
const double& a,
const double& b) {
198 return __longlong_as_double(a <= b ? 0xffffffffffffffffull : 0ull);
202EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pand<float4>(
const float4& a,
const float4& b) {
203 return make_float4(bitwise_and(a.x, b.x), bitwise_and(a.y, b.y), bitwise_and(a.z, b.z), bitwise_and(a.w, b.w));
206EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 pand<double2>(
const double2& a,
const double2& b) {
207 return make_double2(bitwise_and(a.x, b.x), bitwise_and(a.y, b.y));
211EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 por<float4>(
const float4& a,
const float4& b) {
212 return make_float4(bitwise_or(a.x, b.x), bitwise_or(a.y, b.y), bitwise_or(a.z, b.z), bitwise_or(a.w, b.w));
215EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 por<double2>(
const double2& a,
const double2& b) {
216 return make_double2(bitwise_or(a.x, b.x), bitwise_or(a.y, b.y));
220EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pxor<float4>(
const float4& a,
const float4& b) {
221 return make_float4(bitwise_xor(a.x, b.x), bitwise_xor(a.y, b.y), bitwise_xor(a.z, b.z), bitwise_xor(a.w, b.w));
224EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 pxor<double2>(
const double2& a,
const double2& b) {
225 return make_double2(bitwise_xor(a.x, b.x), bitwise_xor(a.y, b.y));
229EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pandnot<float4>(
const float4& a,
const float4& b) {
230 return make_float4(bitwise_andnot(a.x, b.x), bitwise_andnot(a.y, b.y), bitwise_andnot(a.z, b.z),
231 bitwise_andnot(a.w, b.w));
234EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 pandnot<double2>(
const double2& a,
const double2& b) {
235 return make_double2(bitwise_andnot(a.x, b.x), bitwise_andnot(a.y, b.y));
239EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pcmp_eq<float4>(
const float4& a,
const float4& b) {
240 return make_float4(eq_mask(a.x, b.x), eq_mask(a.y, b.y), eq_mask(a.z, b.z), eq_mask(a.w, b.w));
243EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pcmp_lt<float4>(
const float4& a,
const float4& b) {
244 return make_float4(lt_mask(a.x, b.x), lt_mask(a.y, b.y), lt_mask(a.z, b.z), lt_mask(a.w, b.w));
247EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pcmp_le<float4>(
const float4& a,
const float4& b) {
248 return make_float4(le_mask(a.x, b.x), le_mask(a.y, b.y), le_mask(a.z, b.z), le_mask(a.w, b.w));
251EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 pcmp_eq<double2>(
const double2& a,
const double2& b) {
252 return make_double2(eq_mask(a.x, b.x), eq_mask(a.y, b.y));
255EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 pcmp_lt<double2>(
const double2& a,
const double2& b) {
256 return make_double2(lt_mask(a.x, b.x), lt_mask(a.y, b.y));
259EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 pcmp_le<double2>(
const double2& a,
const double2& b) {
260 return make_double2(le_mask(a.x, b.x), le_mask(a.y, b.y));
266EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 plset<float4>(
const float& a) {
267 return make_float4(a, a + 1, a + 2, a + 3);
270EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 plset<double2>(
const double& a) {
271 return make_double2(a, a + 1);
275EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 padd<float4>(
const float4& a,
const float4& b) {
276 return make_float4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w);
279EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 padd<double2>(
const double2& a,
const double2& b) {
280 return make_double2(a.x + b.x, a.y + b.y);
284EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 psub<float4>(
const float4& a,
const float4& b) {
285 return make_float4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w);
288EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 psub<double2>(
const double2& a,
const double2& b) {
289 return make_double2(a.x - b.x, a.y - b.y);
293EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pnegate(
const float4& a) {
294 return make_float4(-a.x, -a.y, -a.z, -a.w);
297EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 pnegate(
const double2& a) {
298 return make_double2(-a.x, -a.y);
302EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pconj(
const float4& a) {
306EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 pconj(
const double2& a) {
311EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pmul<float4>(
const float4& a,
const float4& b) {
312 return make_float4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w);
315EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 pmul<double2>(
const double2& a,
const double2& b) {
316 return make_double2(a.x * b.x, a.y * b.y);
320EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pdiv<float4>(
const float4& a,
const float4& b) {
321 return make_float4(a.x / b.x, a.y / b.y, a.z / b.z, a.w / b.w);
324EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 pdiv<double2>(
const double2& a,
const double2& b) {
325 return make_double2(a.x / b.x, a.y / b.y);
329EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pmin<float4>(
const float4& a,
const float4& b) {
330 return make_float4(fminf(a.x, b.x), fminf(a.y, b.y), fminf(a.z, b.z), fminf(a.w, b.w));
333EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 pmin<double2>(
const double2& a,
const double2& b) {
334 return make_double2(fmin(a.x, b.x), fmin(a.y, b.y));
338EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pmax<float4>(
const float4& a,
const float4& b) {
339 return make_float4(fmaxf(a.x, b.x), fmaxf(a.y, b.y), fmaxf(a.z, b.z), fmaxf(a.w, b.w));
342EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 pmax<double2>(
const double2& a,
const double2& b) {
343 return make_double2(fmax(a.x, b.x), fmax(a.y, b.y));
347EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pload<float4>(
const float* from) {
348 return *
reinterpret_cast<const float4*
>(from);
352EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 pload<double2>(
const double* from) {
353 return *
reinterpret_cast<const double2*
>(from);
357EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 ploadu<float4>(
const float* from) {
358 return make_float4(from[0], from[1], from[2], from[3]);
361EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 ploadu<double2>(
const double* from) {
362 return make_double2(from[0], from[1]);
366EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 ploaddup<float4>(
const float* from) {
367 return make_float4(from[0], from[0], from[1], from[1]);
370EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 ploaddup<double2>(
const double* from) {
371 return make_double2(from[0], from[0]);
375EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void pstore<float>(
float* to,
const float4& from) {
376 *
reinterpret_cast<float4*
>(to) = from;
380EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void pstore<double>(
double* to,
const double2& from) {
381 *
reinterpret_cast<double2*
>(to) = from;
385EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void pstoreu<float>(
float* to,
const float4& from) {
393EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void pstoreu<double>(
double* to,
const double2& from) {
399EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE float4 ploadt_ro<float4, Aligned>(
const float* from) {
400#if defined(EIGEN_GPU_HAS_LDG)
401 return __ldg(
reinterpret_cast<const float4*
>(from));
403 return make_float4(from[0], from[1], from[2], from[3]);
407EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE double2 ploadt_ro<double2, Aligned>(
const double* from) {
408#if defined(EIGEN_GPU_HAS_LDG)
409 return __ldg(
reinterpret_cast<const double2*
>(from));
411 return make_double2(from[0], from[1]);
416EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE float4 ploadt_ro<float4, Unaligned>(
const float* from) {
417#if defined(EIGEN_GPU_HAS_LDG)
418 return make_float4(__ldg(from + 0), __ldg(from + 1), __ldg(from + 2), __ldg(from + 3));
420 return make_float4(from[0], from[1], from[2], from[3]);
424EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE double2 ploadt_ro<double2, Unaligned>(
const double* from) {
425#if defined(EIGEN_GPU_HAS_LDG)
426 return make_double2(__ldg(from + 0), __ldg(from + 1));
428 return make_double2(from[0], from[1]);
433EIGEN_DEVICE_FUNC
inline float4 pgather<float, float4>(
const float* from, Index stride) {
434 return make_float4(from[0 * stride], from[1 * stride], from[2 * stride], from[3 * stride]);
438EIGEN_DEVICE_FUNC
inline double2 pgather<double, double2>(
const double* from, Index stride) {
439 return make_double2(from[0 * stride], from[1 * stride]);
443EIGEN_DEVICE_FUNC
inline void pscatter<float, float4>(
float* to,
const float4& from, Index stride) {
444 to[stride * 0] = from.x;
445 to[stride * 1] = from.y;
446 to[stride * 2] = from.z;
447 to[stride * 3] = from.w;
450EIGEN_DEVICE_FUNC
inline void pscatter<double, double2>(
double* to,
const double2& from, Index stride) {
451 to[stride * 0] = from.x;
452 to[stride * 1] = from.y;
456EIGEN_DEVICE_FUNC
inline float pfirst<float4>(
const float4& a) {
460EIGEN_DEVICE_FUNC
inline double pfirst<double2>(
const double2& a) {
465EIGEN_DEVICE_FUNC
inline float predux<float4>(
const float4& a) {
466 return a.x + a.y + a.z + a.w;
469EIGEN_DEVICE_FUNC
inline double predux<double2>(
const double2& a) {
474EIGEN_DEVICE_FUNC
inline float predux_max<float4>(
const float4& a) {
475 return fmaxf(fmaxf(a.x, a.y), fmaxf(a.z, a.w));
478EIGEN_DEVICE_FUNC
inline double predux_max<double2>(
const double2& a) {
479 return fmax(a.x, a.y);
483EIGEN_DEVICE_FUNC
inline float predux_min<float4>(
const float4& a) {
484 return fminf(fminf(a.x, a.y), fminf(a.z, a.w));
487EIGEN_DEVICE_FUNC
inline double predux_min<double2>(
const double2& a) {
488 return fmin(a.x, a.y);
492EIGEN_DEVICE_FUNC
inline float predux_mul<float4>(
const float4& a) {
493 return a.x * a.y * a.z * a.w;
496EIGEN_DEVICE_FUNC
inline double predux_mul<double2>(
const double2& a) {
501EIGEN_DEVICE_FUNC
inline float4 pabs<float4>(
const float4& a) {
502 return make_float4(fabsf(a.x), fabsf(a.y), fabsf(a.z), fabsf(a.w));
505EIGEN_DEVICE_FUNC
inline double2 pabs<double2>(
const double2& a) {
506 return make_double2(fabs(a.x), fabs(a.y));
510EIGEN_DEVICE_FUNC
inline float4 pfloor<float4>(
const float4& a) {
511 return make_float4(floorf(a.x), floorf(a.y), floorf(a.z), floorf(a.w));
514EIGEN_DEVICE_FUNC
inline double2 pfloor<double2>(
const double2& a) {
519EIGEN_DEVICE_FUNC
inline float4 pceil<float4>(
const float4& a) {
520 return make_float4(ceilf(a.x), ceilf(a.y), ceilf(a.z), ceilf(a.w));
523EIGEN_DEVICE_FUNC
inline double2 pceil<double2>(
const double2& a) {
524 return make_double2(
ceil(a.x),
ceil(a.y));
528EIGEN_DEVICE_FUNC
inline float4 print<float4>(
const float4& a) {
529 return make_float4(rintf(a.x), rintf(a.y), rintf(a.z), rintf(a.w));
532EIGEN_DEVICE_FUNC
inline double2 print<double2>(
const double2& a) {
533 return make_double2(
rint(a.x),
rint(a.y));
537EIGEN_DEVICE_FUNC
inline float4 ptrunc<float4>(
const float4& a) {
538 return make_float4(truncf(a.x), truncf(a.y), truncf(a.z), truncf(a.w));
541EIGEN_DEVICE_FUNC
inline double2 ptrunc<double2>(
const double2& a) {
545EIGEN_DEVICE_FUNC
inline void ptranspose(PacketBlock<float4, 4>& kernel) {
546 float tmp = kernel.packet[0].y;
547 kernel.packet[0].y = kernel.packet[1].x;
548 kernel.packet[1].x = tmp;
550 tmp = kernel.packet[0].z;
551 kernel.packet[0].z = kernel.packet[2].x;
552 kernel.packet[2].x = tmp;
554 tmp = kernel.packet[0].w;
555 kernel.packet[0].w = kernel.packet[3].x;
556 kernel.packet[3].x = tmp;
558 tmp = kernel.packet[1].z;
559 kernel.packet[1].z = kernel.packet[2].y;
560 kernel.packet[2].y = tmp;
562 tmp = kernel.packet[1].w;
563 kernel.packet[1].w = kernel.packet[3].y;
564 kernel.packet[3].y = tmp;
566 tmp = kernel.packet[2].w;
567 kernel.packet[2].w = kernel.packet[3].z;
568 kernel.packet[3].z = tmp;
571EIGEN_DEVICE_FUNC
inline void ptranspose(PacketBlock<double2, 2>& kernel) {
572 double tmp = kernel.packet[0].y;
573 kernel.packet[0].y = kernel.packet[1].x;
574 kernel.packet[1].x = tmp;
582#if (defined(EIGEN_HAS_CUDA_FP16) || defined(EIGEN_HAS_HIP_FP16)) && defined(EIGEN_GPU_COMPILE_PHASE)
584typedef ulonglong2 Packet4h2;
586struct unpacket_traits<Packet4h2> {
587 typedef Eigen::half type;
592 masked_load_available =
false,
593 masked_store_available =
false
595 typedef Packet4h2 half;
598struct is_arithmetic<Packet4h2> {
599 enum { value =
true };
603struct unpacket_traits<half2> {
604 typedef Eigen::half type;
609 masked_load_available =
false,
610 masked_store_available =
false
615struct is_arithmetic<half2> {
616 enum { value =
true };
620struct packet_traits<
Eigen::half> : default_packet_traits {
621 typedef Packet4h2 type;
622 typedef Packet4h2 half;
641EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pset1<half2>(
const Eigen::half& from) {
642 return __half2half2(from);
646EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 pset1<Packet4h2>(
const Eigen::half& from) {
648 half2* p_alias =
reinterpret_cast<half2*
>(&r);
649 p_alias[0] = pset1<half2>(from);
650 p_alias[1] = pset1<half2>(from);
651 p_alias[2] = pset1<half2>(from);
652 p_alias[3] = pset1<half2>(from);
658EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pload(
const Eigen::half* from) {
659 return *
reinterpret_cast<const half2*
>(from);
662EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 ploadu(
const Eigen::half* from) {
return __halves2half2(from[0], from[1]); }
664EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 ploaddup(
const Eigen::half* from) {
665 return __halves2half2(from[0], from[0]);
668EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void pstore(Eigen::half* to,
const half2& from) {
669 *
reinterpret_cast<half2*
>(to) = from;
672EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void pstoreu(Eigen::half* to,
const half2& from) {
673 to[0] = __low2half(from);
674 to[1] = __high2half(from);
677EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE half2 ploadt_ro_aligned(
const Eigen::half* from) {
678#if defined(EIGEN_GPU_HAS_LDG)
680 return __ldg(
reinterpret_cast<const half2*
>(from));
682 return __halves2half2(*(from + 0), *(from + 1));
686EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE half2 ploadt_ro_unaligned(
const Eigen::half* from) {
687#if defined(EIGEN_GPU_HAS_LDG)
688 return __halves2half2(__ldg(from + 0), __ldg(from + 1));
690 return __halves2half2(*(from + 0), *(from + 1));
694EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pgather(
const Eigen::half* from, Index stride) {
695 return __halves2half2(from[0 * stride], from[1 * stride]);
698EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void pscatter(Eigen::half* to,
const half2& from, Index stride) {
699 to[stride * 0] = __low2half(from);
700 to[stride * 1] = __high2half(from);
703EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Eigen::half pfirst(
const half2& a) {
return __low2half(a); }
705EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pabs(
const half2& a) {
706 half a1 = __low2half(a);
707 half a2 = __high2half(a);
708 half result1 = half_impl::raw_uint16_to_half(a1.x & 0x7FFF);
709 half result2 = half_impl::raw_uint16_to_half(a2.x & 0x7FFF);
710 return __halves2half2(result1, result2);
713EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 ptrue(
const half2& ) {
714 half true_half = half_impl::raw_uint16_to_half(0xffffu);
715 return pset1<half2>(true_half);
718EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pzero(
const half2& ) {
719 half false_half = half_impl::raw_uint16_to_half(0x0000u);
720 return pset1<half2>(false_half);
723EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void ptranspose(PacketBlock<half2, 2>& kernel) {
724 __half a1 = __low2half(kernel.packet[0]);
725 __half a2 = __high2half(kernel.packet[0]);
726 __half b1 = __low2half(kernel.packet[1]);
727 __half b2 = __high2half(kernel.packet[1]);
728 kernel.packet[0] = __halves2half2(a1, b1);
729 kernel.packet[1] = __halves2half2(a2, b2);
732EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 plset(
const Eigen::half& a) {
733#if defined(EIGEN_GPU_HAS_FP16_ARITHMETIC)
734 return __halves2half2(a, __hadd(a, __float2half(1.0f)));
736 float f = __half2float(a) + 1.0f;
737 return __halves2half2(a, __float2half(f));
741EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pselect(
const half2& mask,
const half2& a,
const half2& b) {
742 half mask_low = __low2half(mask);
743 half mask_high = __high2half(mask);
744 half result_low = mask_low == half(0) ? __low2half(b) : __low2half(a);
745 half result_high = mask_high == half(0) ? __high2half(b) : __high2half(a);
746 return __halves2half2(result_low, result_high);
749EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pcmp_eq(
const half2& a,
const half2& b) {
750 half true_half = half_impl::raw_uint16_to_half(0xffffu);
751 half false_half = half_impl::raw_uint16_to_half(0x0000u);
752 half a1 = __low2half(a);
753 half a2 = __high2half(a);
754 half b1 = __low2half(b);
755 half b2 = __high2half(b);
756 half eq1 = __half2float(a1) == __half2float(b1) ? true_half : false_half;
757 half eq2 = __half2float(a2) == __half2float(b2) ? true_half : false_half;
758 return __halves2half2(eq1, eq2);
761EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pcmp_lt(
const half2& a,
const half2& b) {
762 half true_half = half_impl::raw_uint16_to_half(0xffffu);
763 half false_half = half_impl::raw_uint16_to_half(0x0000u);
764 half a1 = __low2half(a);
765 half a2 = __high2half(a);
766 half b1 = __low2half(b);
767 half b2 = __high2half(b);
768 half eq1 = __half2float(a1) < __half2float(b1) ? true_half : false_half;
769 half eq2 = __half2float(a2) < __half2float(b2) ? true_half : false_half;
770 return __halves2half2(eq1, eq2);
773EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pcmp_le(
const half2& a,
const half2& b) {
774 half true_half = half_impl::raw_uint16_to_half(0xffffu);
775 half false_half = half_impl::raw_uint16_to_half(0x0000u);
776 half a1 = __low2half(a);
777 half a2 = __high2half(a);
778 half b1 = __low2half(b);
779 half b2 = __high2half(b);
780 half eq1 = __half2float(a1) <= __half2float(b1) ? true_half : false_half;
781 half eq2 = __half2float(a2) <= __half2float(b2) ? true_half : false_half;
782 return __halves2half2(eq1, eq2);
785EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pand(
const half2& a,
const half2& b) {
786 half a1 = __low2half(a);
787 half a2 = __high2half(a);
788 half b1 = __low2half(b);
789 half b2 = __high2half(b);
790 half result1 = half_impl::raw_uint16_to_half(a1.x & b1.x);
791 half result2 = half_impl::raw_uint16_to_half(a2.x & b2.x);
792 return __halves2half2(result1, result2);
795EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 por(
const half2& a,
const half2& b) {
796 half a1 = __low2half(a);
797 half a2 = __high2half(a);
798 half b1 = __low2half(b);
799 half b2 = __high2half(b);
800 half result1 = half_impl::raw_uint16_to_half(a1.x | b1.x);
801 half result2 = half_impl::raw_uint16_to_half(a2.x | b2.x);
802 return __halves2half2(result1, result2);
805EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pxor(
const half2& a,
const half2& b) {
806 half a1 = __low2half(a);
807 half a2 = __high2half(a);
808 half b1 = __low2half(b);
809 half b2 = __high2half(b);
810 half result1 = half_impl::raw_uint16_to_half(a1.x ^ b1.x);
811 half result2 = half_impl::raw_uint16_to_half(a2.x ^ b2.x);
812 return __halves2half2(result1, result2);
815EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pandnot(
const half2& a,
const half2& b) {
816 half a1 = __low2half(a);
817 half a2 = __high2half(a);
818 half b1 = __low2half(b);
819 half b2 = __high2half(b);
820 half result1 = half_impl::raw_uint16_to_half(a1.x & ~b1.x);
821 half result2 = half_impl::raw_uint16_to_half(a2.x & ~b2.x);
822 return __halves2half2(result1, result2);
825EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 padd(
const half2& a,
const half2& b) {
826#if defined(EIGEN_GPU_HAS_FP16_ARITHMETIC)
827 return __hadd2(a, b);
829 float a1 = __low2float(a);
830 float a2 = __high2float(a);
831 float b1 = __low2float(b);
832 float b2 = __high2float(b);
835 return __floats2half2_rn(r1, r2);
839EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 psub(
const half2& a,
const half2& b) {
840#if defined(EIGEN_GPU_HAS_FP16_ARITHMETIC)
841 return __hsub2(a, b);
843 float a1 = __low2float(a);
844 float a2 = __high2float(a);
845 float b1 = __low2float(b);
846 float b2 = __high2float(b);
849 return __floats2half2_rn(r1, r2);
853EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pnegate(
const half2& a) {
854#if defined(EIGEN_GPU_HAS_FP16_ARITHMETIC)
857 float a1 = __low2float(a);
858 float a2 = __high2float(a);
859 return __floats2half2_rn(-a1, -a2);
863EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pconj(
const half2& a) {
return a; }
865EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pmul(
const half2& a,
const half2& b) {
866#if defined(EIGEN_GPU_HAS_FP16_ARITHMETIC)
867 return __hmul2(a, b);
869 float a1 = __low2float(a);
870 float a2 = __high2float(a);
871 float b1 = __low2float(b);
872 float b2 = __high2float(b);
875 return __floats2half2_rn(r1, r2);
879EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pmadd(
const half2& a,
const half2& b,
const half2& c) {
880#if defined(EIGEN_GPU_HAS_FP16_ARITHMETIC)
881 return __hfma2(a, b, c);
883 float a1 = __low2float(a);
884 float a2 = __high2float(a);
885 float b1 = __low2float(b);
886 float b2 = __high2float(b);
887 float c1 = __low2float(c);
888 float c2 = __high2float(c);
889 float r1 = a1 * b1 + c1;
890 float r2 = a2 * b2 + c2;
891 return __floats2half2_rn(r1, r2);
895EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pdiv(
const half2& a,
const half2& b) {
896#if defined(EIGEN_GPU_HAS_FP16_ARITHMETIC)
897 return __h2div(a, b);
899 float a1 = __low2float(a);
900 float a2 = __high2float(a);
901 float b1 = __low2float(b);
902 float b2 = __high2float(b);
905 return __floats2half2_rn(r1, r2);
909EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pmin(
const half2& a,
const half2& b) {
910 float a1 = __low2float(a);
911 float a2 = __high2float(a);
912 float b1 = __low2float(b);
913 float b2 = __high2float(b);
914 __half r1 = a1 < b1 ? __low2half(a) : __low2half(b);
915 __half r2 = a2 < b2 ? __high2half(a) : __high2half(b);
916 return __halves2half2(r1, r2);
919EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pmax(
const half2& a,
const half2& b) {
920 float a1 = __low2float(a);
921 float a2 = __high2float(a);
922 float b1 = __low2float(b);
923 float b2 = __high2float(b);
924 __half r1 = a1 > b1 ? __low2half(a) : __low2half(b);
925 __half r2 = a2 > b2 ? __high2half(a) : __high2half(b);
926 return __halves2half2(r1, r2);
929EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Eigen::half predux(
const half2& a) {
930#if defined(EIGEN_GPU_HAS_FP16_ARITHMETIC)
931 return __hadd(__low2half(a), __high2half(a));
933 float a1 = __low2float(a);
934 float a2 = __high2float(a);
935 return Eigen::half(__float2half(a1 + a2));
939EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Eigen::half predux_max(
const half2& a) {
940#if defined(EIGEN_GPU_HAS_FP16_ARITHMETIC)
941 __half first = __low2half(a);
942 __half second = __high2half(a);
943 return __hgt(first, second) ? first : second;
945 float a1 = __low2float(a);
946 float a2 = __high2float(a);
947 return a1 > a2 ? __low2half(a) : __high2half(a);
951EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Eigen::half predux_min(
const half2& a) {
952#if defined(EIGEN_GPU_HAS_FP16_ARITHMETIC)
953 __half first = __low2half(a);
954 __half second = __high2half(a);
955 return __hlt(first, second) ? first : second;
957 float a1 = __low2float(a);
958 float a2 = __high2float(a);
959 return a1 < a2 ? __low2half(a) : __high2half(a);
963EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Eigen::half predux_mul(
const half2& a) {
964#if defined(EIGEN_GPU_HAS_FP16_ARITHMETIC)
965 return __hmul(__low2half(a), __high2half(a));
967 float a1 = __low2float(a);
968 float a2 = __high2float(a);
969 return Eigen::half(__float2half(a1 * a2));
973EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 plog1p(
const half2& a) {
974 float a1 = __low2float(a);
975 float a2 = __high2float(a);
976 float r1 = log1pf(a1);
977 float r2 = log1pf(a2);
978 return __floats2half2_rn(r1, r2);
981EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pexpm1(
const half2& a) {
982 float a1 = __low2float(a);
983 float a2 = __high2float(a);
984 float r1 = expm1f(a1);
985 float r2 = expm1f(a2);
986 return __floats2half2_rn(r1, r2);
989#if (EIGEN_CUDA_SDK_VER >= 80000 && defined(EIGEN_CUDA_HAS_FP16_ARITHMETIC)) || defined(EIGEN_HIP_DEVICE_COMPILE)
991EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 plog(
const half2& a) {
return h2log(a); }
993EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pexp(
const half2& a) {
return h2exp(a); }
995EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 psqrt(
const half2& a) {
return h2sqrt(a); }
997EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 prsqrt(
const half2& a) {
return h2rsqrt(a); }
1001EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 plog(
const half2& a) {
1002 float a1 = __low2float(a);
1003 float a2 = __high2float(a);
1004 float r1 = logf(a1);
1005 float r2 = logf(a2);
1006 return __floats2half2_rn(r1, r2);
1009EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pexp(
const half2& a) {
1010 float a1 = __low2float(a);
1011 float a2 = __high2float(a);
1012 float r1 = expf(a1);
1013 float r2 = expf(a2);
1014 return __floats2half2_rn(r1, r2);
1017EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 psqrt(
const half2& a) {
1018 float a1 = __low2float(a);
1019 float a2 = __high2float(a);
1020 float r1 = sqrtf(a1);
1021 float r2 = sqrtf(a2);
1022 return __floats2half2_rn(r1, r2);
1025EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 prsqrt(
const half2& a) {
1026 float a1 = __low2float(a);
1027 float a2 = __high2float(a);
1028 float r1 = rsqrtf(a1);
1029 float r2 = rsqrtf(a2);
1030 return __floats2half2_rn(r1, r2);
1036EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 pload<Packet4h2>(
const Eigen::half* from) {
1037 return *
reinterpret_cast<const Packet4h2*
>(from);
1042EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 ploadu<Packet4h2>(
const Eigen::half* from) {
1044 half2* p_alias =
reinterpret_cast<half2*
>(&r);
1045 p_alias[0] = ploadu(from + 0);
1046 p_alias[1] = ploadu(from + 2);
1047 p_alias[2] = ploadu(from + 4);
1048 p_alias[3] = ploadu(from + 6);
1053EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 ploaddup<Packet4h2>(
const Eigen::half* from) {
1055 half2* p_alias =
reinterpret_cast<half2*
>(&r);
1056 p_alias[0] = ploaddup(from + 0);
1057 p_alias[1] = ploaddup(from + 1);
1058 p_alias[2] = ploaddup(from + 2);
1059 p_alias[3] = ploaddup(from + 3);
1064EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void pstore<Eigen::half>(Eigen::half* to,
const Packet4h2& from) {
1065 *
reinterpret_cast<Packet4h2*
>(to) = from;
1069EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void pstoreu<Eigen::half>(Eigen::half* to,
const Packet4h2& from) {
1070 const half2* from_alias =
reinterpret_cast<const half2*
>(&from);
1071 pstoreu(to + 0, from_alias[0]);
1072 pstoreu(to + 2, from_alias[1]);
1073 pstoreu(to + 4, from_alias[2]);
1074 pstoreu(to + 6, from_alias[3]);
1078EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Packet4h2 ploadt_ro<Packet4h2, Aligned>(
const Eigen::half* from) {
1079#if defined(EIGEN_GPU_HAS_LDG)
1081 r = __ldg(
reinterpret_cast<const Packet4h2*
>(from));
1085 half2* r_alias =
reinterpret_cast<half2*
>(&r);
1086 r_alias[0] = ploadt_ro_aligned(from + 0);
1087 r_alias[1] = ploadt_ro_aligned(from + 2);
1088 r_alias[2] = ploadt_ro_aligned(from + 4);
1089 r_alias[3] = ploadt_ro_aligned(from + 6);
1095EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Packet4h2 ploadt_ro<Packet4h2, Unaligned>(
const Eigen::half* from) {
1097 half2* r_alias =
reinterpret_cast<half2*
>(&r);
1098 r_alias[0] = ploadt_ro_unaligned(from + 0);
1099 r_alias[1] = ploadt_ro_unaligned(from + 2);
1100 r_alias[2] = ploadt_ro_unaligned(from + 4);
1101 r_alias[3] = ploadt_ro_unaligned(from + 6);
1106EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 pgather<Eigen::half, Packet4h2>(
const Eigen::half* from, Index stride) {
1108 half2* p_alias =
reinterpret_cast<half2*
>(&r);
1109 p_alias[0] = __halves2half2(from[0 * stride], from[1 * stride]);
1110 p_alias[1] = __halves2half2(from[2 * stride], from[3 * stride]);
1111 p_alias[2] = __halves2half2(from[4 * stride], from[5 * stride]);
1112 p_alias[3] = __halves2half2(from[6 * stride], from[7 * stride]);
1117EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void pscatter<Eigen::half, Packet4h2>(Eigen::half* to,
const Packet4h2& from,
1119 const half2* from_alias =
reinterpret_cast<const half2*
>(&from);
1120 pscatter(to + stride * 0, from_alias[0], stride);
1121 pscatter(to + stride * 2, from_alias[1], stride);
1122 pscatter(to + stride * 4, from_alias[2], stride);
1123 pscatter(to + stride * 6, from_alias[3], stride);
1127EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Eigen::half pfirst<Packet4h2>(
const Packet4h2& a) {
1128 return pfirst(*(
reinterpret_cast<const half2*
>(&a)));
1132EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 pabs<Packet4h2>(
const Packet4h2& a) {
1134 half2* p_alias =
reinterpret_cast<half2*
>(&r);
1135 const half2* a_alias =
reinterpret_cast<const half2*
>(&a);
1136 p_alias[0] = pabs(a_alias[0]);
1137 p_alias[1] = pabs(a_alias[1]);
1138 p_alias[2] = pabs(a_alias[2]);
1139 p_alias[3] = pabs(a_alias[3]);
1144EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 ptrue<Packet4h2>(
const Packet4h2& ) {
1145 half true_half = half_impl::raw_uint16_to_half(0xffffu);
1146 return pset1<Packet4h2>(true_half);
1150EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 pzero<Packet4h2>(
const Packet4h2& ) {
1151 half false_half = half_impl::raw_uint16_to_half(0x0000u);
1152 return pset1<Packet4h2>(false_half);
1155EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void ptranspose_double(
double* d_row0,
double* d_row1,
double* d_row2,
1156 double* d_row3,
double* d_row4,
double* d_row5,
1157 double* d_row6,
double* d_row7) {
1160 d_row0[1] = d_row4[0];
1164 d_row1[1] = d_row5[0];
1168 d_row2[1] = d_row6[0];
1172 d_row3[1] = d_row7[0];
1176EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void ptranspose_half2(half2* f_row0, half2* f_row1, half2* f_row2,
1180 f_row0[1] = f_row2[0];
1184 f_row1[1] = f_row3[0];
1188EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void ptranspose_half(half2& f0, half2& f1) {
1189 __half a1 = __low2half(f0);
1190 __half a2 = __high2half(f0);
1191 __half b1 = __low2half(f1);
1192 __half b2 = __high2half(f1);
1193 f0 = __halves2half2(a1, b1);
1194 f1 = __halves2half2(a2, b2);
1197EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void ptranspose(PacketBlock<Packet4h2, 8>& kernel) {
1198 double* d_row0 =
reinterpret_cast<double*
>(&kernel.packet[0]);
1199 double* d_row1 =
reinterpret_cast<double*
>(&kernel.packet[1]);
1200 double* d_row2 =
reinterpret_cast<double*
>(&kernel.packet[2]);
1201 double* d_row3 =
reinterpret_cast<double*
>(&kernel.packet[3]);
1202 double* d_row4 =
reinterpret_cast<double*
>(&kernel.packet[4]);
1203 double* d_row5 =
reinterpret_cast<double*
>(&kernel.packet[5]);
1204 double* d_row6 =
reinterpret_cast<double*
>(&kernel.packet[6]);
1205 double* d_row7 =
reinterpret_cast<double*
>(&kernel.packet[7]);
1206 ptranspose_double(d_row0, d_row1, d_row2, d_row3, d_row4, d_row5, d_row6, d_row7);
1208 half2* f_row0 =
reinterpret_cast<half2*
>(d_row0);
1209 half2* f_row1 =
reinterpret_cast<half2*
>(d_row1);
1210 half2* f_row2 =
reinterpret_cast<half2*
>(d_row2);
1211 half2* f_row3 =
reinterpret_cast<half2*
>(d_row3);
1212 ptranspose_half2(f_row0, f_row1, f_row2, f_row3);
1213 ptranspose_half(f_row0[0], f_row1[0]);
1214 ptranspose_half(f_row0[1], f_row1[1]);
1215 ptranspose_half(f_row2[0], f_row3[0]);
1216 ptranspose_half(f_row2[1], f_row3[1]);
1218 f_row0 =
reinterpret_cast<half2*
>(d_row0 + 1);
1219 f_row1 =
reinterpret_cast<half2*
>(d_row1 + 1);
1220 f_row2 =
reinterpret_cast<half2*
>(d_row2 + 1);
1221 f_row3 =
reinterpret_cast<half2*
>(d_row3 + 1);
1222 ptranspose_half2(f_row0, f_row1, f_row2, f_row3);
1223 ptranspose_half(f_row0[0], f_row1[0]);
1224 ptranspose_half(f_row0[1], f_row1[1]);
1225 ptranspose_half(f_row2[0], f_row3[0]);
1226 ptranspose_half(f_row2[1], f_row3[1]);
1228 f_row0 =
reinterpret_cast<half2*
>(d_row4);
1229 f_row1 =
reinterpret_cast<half2*
>(d_row5);
1230 f_row2 =
reinterpret_cast<half2*
>(d_row6);
1231 f_row3 =
reinterpret_cast<half2*
>(d_row7);
1232 ptranspose_half2(f_row0, f_row1, f_row2, f_row3);
1233 ptranspose_half(f_row0[0], f_row1[0]);
1234 ptranspose_half(f_row0[1], f_row1[1]);
1235 ptranspose_half(f_row2[0], f_row3[0]);
1236 ptranspose_half(f_row2[1], f_row3[1]);
1238 f_row0 =
reinterpret_cast<half2*
>(d_row4 + 1);
1239 f_row1 =
reinterpret_cast<half2*
>(d_row5 + 1);
1240 f_row2 =
reinterpret_cast<half2*
>(d_row6 + 1);
1241 f_row3 =
reinterpret_cast<half2*
>(d_row7 + 1);
1242 ptranspose_half2(f_row0, f_row1, f_row2, f_row3);
1243 ptranspose_half(f_row0[0], f_row1[0]);
1244 ptranspose_half(f_row0[1], f_row1[1]);
1245 ptranspose_half(f_row2[0], f_row3[0]);
1246 ptranspose_half(f_row2[1], f_row3[1]);
1250EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 plset<Packet4h2>(
const Eigen::half& a) {
1251#if defined(EIGEN_HIP_DEVICE_COMPILE)
1254 half2* p_alias =
reinterpret_cast<half2*
>(&r);
1255 p_alias[0] = __halves2half2(a, __hadd(a, __float2half(1.0f)));
1256 p_alias[1] = __halves2half2(__hadd(a, __float2half(2.0f)), __hadd(a, __float2half(3.0f)));
1257 p_alias[2] = __halves2half2(__hadd(a, __float2half(4.0f)), __hadd(a, __float2half(5.0f)));
1258 p_alias[3] = __halves2half2(__hadd(a, __float2half(6.0f)), __hadd(a, __float2half(7.0f)));
1260#elif defined(EIGEN_CUDA_HAS_FP16_ARITHMETIC)
1262 half2* r_alias =
reinterpret_cast<half2*
>(&r);
1264 half2 b = pset1<half2>(a);
1266 half2 half_offset0 = __halves2half2(__float2half(0.0f), __float2half(2.0f));
1267 half2 half_offset1 = __halves2half2(__float2half(4.0f), __float2half(6.0f));
1269 c = __hadd2(b, half_offset0);
1270 r_alias[0] = plset(__low2half(c));
1271 r_alias[1] = plset(__high2half(c));
1273 c = __hadd2(b, half_offset1);
1274 r_alias[2] = plset(__low2half(c));
1275 r_alias[3] = plset(__high2half(c));
1280 float f = __half2float(a);
1282 half2* p_alias =
reinterpret_cast<half2*
>(&r);
1283 p_alias[0] = __halves2half2(a, __float2half(f + 1.0f));
1284 p_alias[1] = __halves2half2(__float2half(f + 2.0f), __float2half(f + 3.0f));
1285 p_alias[2] = __halves2half2(__float2half(f + 4.0f), __float2half(f + 5.0f));
1286 p_alias[3] = __halves2half2(__float2half(f + 6.0f), __float2half(f + 7.0f));
1292EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 pselect<Packet4h2>(
const Packet4h2& mask,
const Packet4h2& a,
1293 const Packet4h2& b) {
1295 half2* r_alias =
reinterpret_cast<half2*
>(&r);
1296 const half2* mask_alias =
reinterpret_cast<const half2*
>(&mask);
1297 const half2* a_alias =
reinterpret_cast<const half2*
>(&a);
1298 const half2* b_alias =
reinterpret_cast<const half2*
>(&b);
1299 r_alias[0] = pselect(mask_alias[0], a_alias[0], b_alias[0]);
1300 r_alias[1] = pselect(mask_alias[1], a_alias[1], b_alias[1]);
1301 r_alias[2] = pselect(mask_alias[2], a_alias[2], b_alias[2]);
1302 r_alias[3] = pselect(mask_alias[3], a_alias[3], b_alias[3]);
1307EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 pcmp_eq<Packet4h2>(
const Packet4h2& a,
const Packet4h2& b) {
1309 half2* r_alias =
reinterpret_cast<half2*
>(&r);
1310 const half2* a_alias =
reinterpret_cast<const half2*
>(&a);
1311 const half2* b_alias =
reinterpret_cast<const half2*
>(&b);
1312 r_alias[0] = pcmp_eq(a_alias[0], b_alias[0]);
1313 r_alias[1] = pcmp_eq(a_alias[1], b_alias[1]);
1314 r_alias[2] = pcmp_eq(a_alias[2], b_alias[2]);
1315 r_alias[3] = pcmp_eq(a_alias[3], b_alias[3]);
1320EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 pcmp_lt<Packet4h2>(
const Packet4h2& a,
const Packet4h2& b) {
1322 half2* r_alias =
reinterpret_cast<half2*
>(&r);
1323 const half2* a_alias =
reinterpret_cast<const half2*
>(&a);
1324 const half2* b_alias =
reinterpret_cast<const half2*
>(&b);
1325 r_alias[0] = pcmp_lt(a_alias[0], b_alias[0]);
1326 r_alias[1] = pcmp_lt(a_alias[1], b_alias[1]);
1327 r_alias[2] = pcmp_lt(a_alias[2], b_alias[2]);
1328 r_alias[3] = pcmp_lt(a_alias[3], b_alias[3]);
1333EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 pcmp_le<Packet4h2>(
const Packet4h2& a,
const Packet4h2& b) {
1335 half2* r_alias =
reinterpret_cast<half2*
>(&r);
1336 const half2* a_alias =
reinterpret_cast<const half2*
>(&a);
1337 const half2* b_alias =
reinterpret_cast<const half2*
>(&b);
1338 r_alias[0] = pcmp_le(a_alias[0], b_alias[0]);
1339 r_alias[1] = pcmp_le(a_alias[1], b_alias[1]);
1340 r_alias[2] = pcmp_le(a_alias[2], b_alias[2]);
1341 r_alias[3] = pcmp_le(a_alias[3], b_alias[3]);
1346EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 pand<Packet4h2>(
const Packet4h2& a,
const Packet4h2& b) {
1348 half2* r_alias =
reinterpret_cast<half2*
>(&r);
1349 const half2* a_alias =
reinterpret_cast<const half2*
>(&a);
1350 const half2* b_alias =
reinterpret_cast<const half2*
>(&b);
1351 r_alias[0] = pand(a_alias[0], b_alias[0]);
1352 r_alias[1] = pand(a_alias[1], b_alias[1]);
1353 r_alias[2] = pand(a_alias[2], b_alias[2]);
1354 r_alias[3] = pand(a_alias[3], b_alias[3]);
1359EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 por<Packet4h2>(
const Packet4h2& a,
const Packet4h2& b) {
1361 half2* r_alias =
reinterpret_cast<half2*
>(&r);
1362 const half2* a_alias =
reinterpret_cast<const half2*
>(&a);
1363 const half2* b_alias =
reinterpret_cast<const half2*
>(&b);
1364 r_alias[0] = por(a_alias[0], b_alias[0]);
1365 r_alias[1] = por(a_alias[1], b_alias[1]);
1366 r_alias[2] = por(a_alias[2], b_alias[2]);
1367 r_alias[3] = por(a_alias[3], b_alias[3]);
1372EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 pxor<Packet4h2>(
const Packet4h2& a,
const Packet4h2& b) {
1374 half2* r_alias =
reinterpret_cast<half2*
>(&r);
1375 const half2* a_alias =
reinterpret_cast<const half2*
>(&a);
1376 const half2* b_alias =
reinterpret_cast<const half2*
>(&b);
1377 r_alias[0] = pxor(a_alias[0], b_alias[0]);
1378 r_alias[1] = pxor(a_alias[1], b_alias[1]);
1379 r_alias[2] = pxor(a_alias[2], b_alias[2]);
1380 r_alias[3] = pxor(a_alias[3], b_alias[3]);
1385EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 pandnot<Packet4h2>(
const Packet4h2& a,
const Packet4h2& b) {
1387 half2* r_alias =
reinterpret_cast<half2*
>(&r);
1388 const half2* a_alias =
reinterpret_cast<const half2*
>(&a);
1389 const half2* b_alias =
reinterpret_cast<const half2*
>(&b);
1390 r_alias[0] = pandnot(a_alias[0], b_alias[0]);
1391 r_alias[1] = pandnot(a_alias[1], b_alias[1]);
1392 r_alias[2] = pandnot(a_alias[2], b_alias[2]);
1393 r_alias[3] = pandnot(a_alias[3], b_alias[3]);
1398EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 padd<Packet4h2>(
const Packet4h2& a,
const Packet4h2& b) {
1400 half2* r_alias =
reinterpret_cast<half2*
>(&r);
1401 const half2* a_alias =
reinterpret_cast<const half2*
>(&a);
1402 const half2* b_alias =
reinterpret_cast<const half2*
>(&b);
1403 r_alias[0] = padd(a_alias[0], b_alias[0]);
1404 r_alias[1] = padd(a_alias[1], b_alias[1]);
1405 r_alias[2] = padd(a_alias[2], b_alias[2]);
1406 r_alias[3] = padd(a_alias[3], b_alias[3]);
1411EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 psub<Packet4h2>(
const Packet4h2& a,
const Packet4h2& b) {
1413 half2* r_alias =
reinterpret_cast<half2*
>(&r);
1414 const half2* a_alias =
reinterpret_cast<const half2*
>(&a);
1415 const half2* b_alias =
reinterpret_cast<const half2*
>(&b);
1416 r_alias[0] = psub(a_alias[0], b_alias[0]);
1417 r_alias[1] = psub(a_alias[1], b_alias[1]);
1418 r_alias[2] = psub(a_alias[2], b_alias[2]);
1419 r_alias[3] = psub(a_alias[3], b_alias[3]);
1424EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 pnegate(
const Packet4h2& a) {
1426 half2* r_alias =
reinterpret_cast<half2*
>(&r);
1427 const half2* a_alias =
reinterpret_cast<const half2*
>(&a);
1428 r_alias[0] = pnegate(a_alias[0]);
1429 r_alias[1] = pnegate(a_alias[1]);
1430 r_alias[2] = pnegate(a_alias[2]);
1431 r_alias[3] = pnegate(a_alias[3]);
1436EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 pconj(
const Packet4h2& a) {
1441EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 pmul<Packet4h2>(
const Packet4h2& a,
const Packet4h2& b) {
1443 half2* r_alias =
reinterpret_cast<half2*
>(&r);
1444 const half2* a_alias =
reinterpret_cast<const half2*
>(&a);
1445 const half2* b_alias =
reinterpret_cast<const half2*
>(&b);
1446 r_alias[0] = pmul(a_alias[0], b_alias[0]);
1447 r_alias[1] = pmul(a_alias[1], b_alias[1]);
1448 r_alias[2] = pmul(a_alias[2], b_alias[2]);
1449 r_alias[3] = pmul(a_alias[3], b_alias[3]);
1454EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 pmadd<Packet4h2>(
const Packet4h2& a,
const Packet4h2& b,
1455 const Packet4h2& c) {
1457 half2* r_alias =
reinterpret_cast<half2*
>(&r);
1458 const half2* a_alias =
reinterpret_cast<const half2*
>(&a);
1459 const half2* b_alias =
reinterpret_cast<const half2*
>(&b);
1460 const half2* c_alias =
reinterpret_cast<const half2*
>(&c);
1461 r_alias[0] = pmadd(a_alias[0], b_alias[0], c_alias[0]);
1462 r_alias[1] = pmadd(a_alias[1], b_alias[1], c_alias[1]);
1463 r_alias[2] = pmadd(a_alias[2], b_alias[2], c_alias[2]);
1464 r_alias[3] = pmadd(a_alias[3], b_alias[3], c_alias[3]);
1469EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 pdiv<Packet4h2>(
const Packet4h2& a,
const Packet4h2& b) {
1471 half2* r_alias =
reinterpret_cast<half2*
>(&r);
1472 const half2* a_alias =
reinterpret_cast<const half2*
>(&a);
1473 const half2* b_alias =
reinterpret_cast<const half2*
>(&b);
1474 r_alias[0] = pdiv(a_alias[0], b_alias[0]);
1475 r_alias[1] = pdiv(a_alias[1], b_alias[1]);
1476 r_alias[2] = pdiv(a_alias[2], b_alias[2]);
1477 r_alias[3] = pdiv(a_alias[3], b_alias[3]);
1482EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 pmin<Packet4h2>(
const Packet4h2& a,
const Packet4h2& b) {
1484 half2* r_alias =
reinterpret_cast<half2*
>(&r);
1485 const half2* a_alias =
reinterpret_cast<const half2*
>(&a);
1486 const half2* b_alias =
reinterpret_cast<const half2*
>(&b);
1487 r_alias[0] = pmin(a_alias[0], b_alias[0]);
1488 r_alias[1] = pmin(a_alias[1], b_alias[1]);
1489 r_alias[2] = pmin(a_alias[2], b_alias[2]);
1490 r_alias[3] = pmin(a_alias[3], b_alias[3]);
1495EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 pmax<Packet4h2>(
const Packet4h2& a,
const Packet4h2& b) {
1497 half2* r_alias =
reinterpret_cast<half2*
>(&r);
1498 const half2* a_alias =
reinterpret_cast<const half2*
>(&a);
1499 const half2* b_alias =
reinterpret_cast<const half2*
>(&b);
1500 r_alias[0] = pmax(a_alias[0], b_alias[0]);
1501 r_alias[1] = pmax(a_alias[1], b_alias[1]);
1502 r_alias[2] = pmax(a_alias[2], b_alias[2]);
1503 r_alias[3] = pmax(a_alias[3], b_alias[3]);
1508EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Eigen::half predux<Packet4h2>(
const Packet4h2& a) {
1509 const half2* a_alias =
reinterpret_cast<const half2*
>(&a);
1511 return predux(a_alias[0]) + predux(a_alias[1]) + predux(a_alias[2]) + predux(a_alias[3]);
1515EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Eigen::half predux_max<Packet4h2>(
const Packet4h2& a) {
1516 const half2* a_alias =
reinterpret_cast<const half2*
>(&a);
1517 half2 m0 = __halves2half2(predux_max(a_alias[0]), predux_max(a_alias[1]));
1518 half2 m1 = __halves2half2(predux_max(a_alias[2]), predux_max(a_alias[3]));
1519 __half first = predux_max(m0);
1520 __half second = predux_max(m1);
1521#if defined(EIGEN_CUDA_HAS_FP16_ARITHMETIC)
1522 return (__hgt(first, second) ? first : second);
1524 float ffirst = __half2float(first);
1525 float fsecond = __half2float(second);
1526 return (ffirst > fsecond) ? first : second;
1531EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Eigen::half predux_min<Packet4h2>(
const Packet4h2& a) {
1532 const half2* a_alias =
reinterpret_cast<const half2*
>(&a);
1533 half2 m0 = __halves2half2(predux_min(a_alias[0]), predux_min(a_alias[1]));
1534 half2 m1 = __halves2half2(predux_min(a_alias[2]), predux_min(a_alias[3]));
1535 __half first = predux_min(m0);
1536 __half second = predux_min(m1);
1537#if defined(EIGEN_CUDA_HAS_FP16_ARITHMETIC)
1538 return (__hlt(first, second) ? first : second);
1540 float ffirst = __half2float(first);
1541 float fsecond = __half2float(second);
1542 return (ffirst < fsecond) ? first : second;
1548EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Eigen::half predux_mul<Packet4h2>(
const Packet4h2& a) {
1549 const half2* a_alias =
reinterpret_cast<const half2*
>(&a);
1550 return predux_mul(pmul(pmul(a_alias[0], a_alias[1]), pmul(a_alias[2], a_alias[3])));
1554EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 plog1p<Packet4h2>(
const Packet4h2& a) {
1556 half2* r_alias =
reinterpret_cast<half2*
>(&r);
1557 const half2* a_alias =
reinterpret_cast<const half2*
>(&a);
1558 r_alias[0] = plog1p(a_alias[0]);
1559 r_alias[1] = plog1p(a_alias[1]);
1560 r_alias[2] = plog1p(a_alias[2]);
1561 r_alias[3] = plog1p(a_alias[3]);
1566EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 pexpm1<Packet4h2>(
const Packet4h2& a) {
1568 half2* r_alias =
reinterpret_cast<half2*
>(&r);
1569 const half2* a_alias =
reinterpret_cast<const half2*
>(&a);
1570 r_alias[0] = pexpm1(a_alias[0]);
1571 r_alias[1] = pexpm1(a_alias[1]);
1572 r_alias[2] = pexpm1(a_alias[2]);
1573 r_alias[3] = pexpm1(a_alias[3]);
1578EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 plog<Packet4h2>(
const Packet4h2& a) {
1580 half2* r_alias =
reinterpret_cast<half2*
>(&r);
1581 const half2* a_alias =
reinterpret_cast<const half2*
>(&a);
1582 r_alias[0] = plog(a_alias[0]);
1583 r_alias[1] = plog(a_alias[1]);
1584 r_alias[2] = plog(a_alias[2]);
1585 r_alias[3] = plog(a_alias[3]);
1590EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 pexp<Packet4h2>(
const Packet4h2& a) {
1592 half2* r_alias =
reinterpret_cast<half2*
>(&r);
1593 const half2* a_alias =
reinterpret_cast<const half2*
>(&a);
1594 r_alias[0] = pexp(a_alias[0]);
1595 r_alias[1] = pexp(a_alias[1]);
1596 r_alias[2] = pexp(a_alias[2]);
1597 r_alias[3] = pexp(a_alias[3]);
1602EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 psqrt<Packet4h2>(
const Packet4h2& a) {
1604 half2* r_alias =
reinterpret_cast<half2*
>(&r);
1605 const half2* a_alias =
reinterpret_cast<const half2*
>(&a);
1606 r_alias[0] = psqrt(a_alias[0]);
1607 r_alias[1] = psqrt(a_alias[1]);
1608 r_alias[2] = psqrt(a_alias[2]);
1609 r_alias[3] = psqrt(a_alias[3]);
1614EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 prsqrt<Packet4h2>(
const Packet4h2& a) {
1616 half2* r_alias =
reinterpret_cast<half2*
>(&r);
1617 const half2* a_alias =
reinterpret_cast<const half2*
>(&a);
1618 r_alias[0] = prsqrt(a_alias[0]);
1619 r_alias[1] = prsqrt(a_alias[1]);
1620 r_alias[2] = prsqrt(a_alias[2]);
1621 r_alias[3] = prsqrt(a_alias[3]);
1628EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 padd<half2>(
const half2& a,
const half2& b) {
1629#if defined(EIGEN_GPU_HAS_FP16_ARITHMETIC)
1630 return __hadd2(a, b);
1632 float a1 = __low2float(a);
1633 float a2 = __high2float(a);
1634 float b1 = __low2float(b);
1635 float b2 = __high2float(b);
1638 return __floats2half2_rn(r1, r2);
1643EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pmul<half2>(
const half2& a,
const half2& b) {
1644#if defined(EIGEN_GPU_HAS_FP16_ARITHMETIC)
1645 return __hmul2(a, b);
1647 float a1 = __low2float(a);
1648 float a2 = __high2float(a);
1649 float b1 = __low2float(b);
1650 float b2 = __high2float(b);
1653 return __floats2half2_rn(r1, r2);
1658EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pdiv<half2>(
const half2& a,
const half2& b) {
1659#if defined(EIGEN_GPU_HAS_FP16_ARITHMETIC)
1660 return __h2div(a, b);
1662 float a1 = __low2float(a);
1663 float a2 = __high2float(a);
1664 float b1 = __low2float(b);
1665 float b2 = __high2float(b);
1668 return __floats2half2_rn(r1, r2);
1673EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pmin<half2>(
const half2& a,
const half2& b) {
1674 float a1 = __low2float(a);
1675 float a2 = __high2float(a);
1676 float b1 = __low2float(b);
1677 float b2 = __high2float(b);
1678 __half r1 = a1 < b1 ? __low2half(a) : __low2half(b);
1679 __half r2 = a2 < b2 ? __high2half(a) : __high2half(b);
1680 return __halves2half2(r1, r2);
1684EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pmax<half2>(
const half2& a,
const half2& b) {
1685 float a1 = __low2float(a);
1686 float a2 = __high2float(a);
1687 float b1 = __low2float(b);
1688 float b2 = __high2float(b);
1689 __half r1 = a1 > b1 ? __low2half(a) : __low2half(b);
1690 __half r2 = a2 > b2 ? __high2half(a) : __high2half(b);
1691 return __halves2half2(r1, r2);
1696#undef EIGEN_GPU_HAS_LDG
1697#undef EIGEN_CUDA_HAS_FP16_ARITHMETIC
1698#undef EIGEN_GPU_HAS_FP16_ARITHMETIC
@ Aligned16
Definition Constants.h:237
Namespace containing all symbols from the Eigen library.
Definition Core:137
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_rint_op< typename Derived::Scalar >, const Derived > rint(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_trunc_op< typename Derived::Scalar >, const Derived > trunc(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_floor_op< typename Derived::Scalar >, const Derived > floor(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_ceil_op< typename Derived::Scalar >, const Derived > ceil(const Eigen::ArrayBase< Derived > &x)