arch/AVX512/MathFunctions.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2016 Pedro Gonnet (pedro.gonnet@gmail.com)
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #ifndef THIRD_PARTY_EIGEN3_EIGEN_SRC_CORE_ARCH_AVX512_MATHFUNCTIONS_H_
11 #define THIRD_PARTY_EIGEN3_EIGEN_SRC_CORE_ARCH_AVX512_MATHFUNCTIONS_H_
12 
13 // IWYU pragma: private
14 #include "../../InternalHeaderCheck.h"
15 
16 namespace Eigen {
17 
18 namespace internal {
21 
22 template <>
24  Packet16f fexponent;
25  const Packet16h out = float2half(pfrexp<Packet16f>(half2float(a), fexponent));
26  exponent = float2half(fexponent);
27  return out;
28 }
29 
30 template <>
32  return float2half(pldexp<Packet16f>(half2float(a), half2float(exponent)));
33 }
34 
35 template <>
37  Packet16f fexponent;
38  const Packet16bf out = F32ToBf16(pfrexp<Packet16f>(Bf16ToF32(a), fexponent));
39  exponent = F32ToBf16(fexponent);
40  return out;
41 }
42 
43 template <>
45  return F32ToBf16(pldexp<Packet16f>(Bf16ToF32(a), Bf16ToF32(exponent)));
46 }
47 
48 #if EIGEN_FAST_MATH
49 template <>
51  return generic_sqrt_newton_step<Packet16f>::run(_x, _mm512_rsqrt14_ps(_x));
52 }
53 
54 template <>
56 #ifdef EIGEN_VECTORIZE_AVX512ER
57  return generic_sqrt_newton_step<Packet8d, /*Steps=*/1>::run(_x, _mm512_rsqrt28_pd(_x));
58 #else
59  return generic_sqrt_newton_step<Packet8d, /*Steps=*/2>::run(_x, _mm512_rsqrt14_pd(_x));
60 #endif
61 }
62 #else
63 template <>
65  return _mm512_sqrt_ps(x);
66 }
67 
68 template <>
70  return _mm512_sqrt_pd(x);
71 }
72 #endif
73 
74 // prsqrt for float.
75 #if defined(EIGEN_VECTORIZE_AVX512ER)
76 template <>
77 EIGEN_STRONG_INLINE Packet16f prsqrt<Packet16f>(const Packet16f& x) {
78  return _mm512_rsqrt28_ps(x);
79 }
80 #elif EIGEN_FAST_MATH
81 
82 template <>
84  return generic_rsqrt_newton_step<Packet16f, /*Steps=*/1>::run(_x, _mm512_rsqrt14_ps(_x));
85 }
86 #endif
87 
88 // prsqrt for double.
89 #if EIGEN_FAST_MATH
90 template <>
92 #ifdef EIGEN_VECTORIZE_AVX512ER
93  return generic_rsqrt_newton_step<Packet8d, /*Steps=*/1>::run(_x, _mm512_rsqrt28_pd(_x));
94 #else
95  return generic_rsqrt_newton_step<Packet8d, /*Steps=*/2>::run(_x, _mm512_rsqrt14_pd(_x));
96 #endif
97 }
98 
99 template <>
100 EIGEN_STRONG_INLINE Packet16f preciprocal<Packet16f>(const Packet16f& a) {
101 #ifdef EIGEN_VECTORIZE_AVX512ER
102  return _mm512_rcp28_ps(a);
103 #else
104  return generic_reciprocal_newton_step<Packet16f, /*Steps=*/1>::run(a, _mm512_rcp14_ps(a));
105 #endif
106 }
107 #endif
108 
133 
134 } // end namespace internal
135 
136 } // end namespace Eigen
137 
138 #endif // THIRD_PARTY_EIGEN3_EIGEN_SRC_CORE_ARCH_AVX512_MATHFUNCTIONS_H_
#define BF16_PACKET_FUNCTION(PACKET_F, PACKET_BF16, METHOD)
Definition: BFloat16.h:34
#define EIGEN_INSTANTIATE_GENERIC_MATH_FUNCS_DOUBLE(PACKET)
Definition: GenericPacketMathFunctionsFwd.h:203
#define EIGEN_INSTANTIATE_GENERIC_MATH_FUNCS_FLOAT(PACKET)
Definition: GenericPacketMathFunctionsFwd.h:188
#define F16_PACKET_FUNCTION(PACKET_F, PACKET_F16, METHOD)
Definition: Half.h:52
#define EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
Definition: Macros.h:900
#define EIGEN_STRONG_INLINE
Definition: Macros.h:834
const Scalar * a
Definition: level2_cplx_impl.h:32
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pexpm1(const Packet &a)
Definition: GenericPacketMath.h:1097
EIGEN_STRONG_INLINE Packet8h float2half(const Packet8f &a)
Definition: AVX/PacketMath.h:2283
EIGEN_STRONG_INLINE Packet8f Bf16ToF32(const Packet8bf &a)
Definition: AVX/PacketMath.h:2558
EIGEN_STRONG_INLINE Packet16f pfrexp< Packet16f >(const Packet16f &a, Packet16f &exponent)
Definition: AVX512/PacketMath.h:1356
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet plog2(const Packet &a)
Definition: GenericPacketMath.h:1123
__m512d Packet8d
Definition: AVX512/PacketMath.h:36
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet plog(const Packet &a)
Definition: GenericPacketMath.h:1103
EIGEN_STRONG_INLINE Packet16f psqrt< Packet16f >(const Packet16f &x)
Definition: arch/AVX512/MathFunctions.h:64
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pcos(const Packet &a)
Definition: GenericPacketMath.h:1022
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin(const Packet &a)
Definition: GenericPacketMath.h:1015
eigen_packet_wrapper< __m256i, 2 > Packet16bf
Definition: AVX512/PacketMath.h:41
EIGEN_STRONG_INLINE Packet8f half2float(const Packet8h &a)
Definition: AVX/PacketMath.h:2273
EIGEN_DEVICE_FUNC Packet preciprocal(const Packet &a)
Definition: GenericPacketMath.h:1433
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet ptanh(const Packet &a)
Definition: GenericPacketMath.h:1071
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pexp2(const Packet &a)
Definition: GenericPacketMath.h:1091
EIGEN_STRONG_INLINE Packet16f pldexp< Packet16f >(const Packet16f &a, const Packet16f &exponent)
Definition: AVX512/PacketMath.h:1377
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet plog1p(const Packet &a)
Definition: GenericPacketMath.h:1110
EIGEN_STRONG_INLINE Packet8d psqrt< Packet8d >(const Packet8d &x)
Definition: arch/AVX512/MathFunctions.h:69
EIGEN_STRONG_INLINE Packet4f psqrt(const Packet4f &a)
Definition: LSX/PacketMath.h:2176
EIGEN_STRONG_INLINE Packet8h pldexp(const Packet8h &a, const Packet8h &exponent)
Definition: arch/AVX/MathFunctions.h:80
EIGEN_STRONG_INLINE Packet8h pfrexp(const Packet8h &a, Packet8h &exponent)
Definition: arch/AVX/MathFunctions.h:72
EIGEN_STRONG_INLINE Packet4f prsqrt(const Packet4f &a)
Definition: LSX/PacketMath.h:2528
eigen_packet_wrapper< __m256i, 1 > Packet16h
Definition: AVX512/PacketMath.h:39
EIGEN_STRONG_INLINE Packet8bf F32ToBf16(Packet4f p4f)
Definition: AltiVec/PacketMath.h:2059
__m512 Packet16f
Definition: AVX512/PacketMath.h:34
EIGEN_STRONG_INLINE Packet4f pexp(const Packet4f &_x)
Definition: LSX/PacketMath.h:2663
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
auto run(Kernel kernel, Args &&... args) -> decltype(kernel(args...))
Definition: gpu_test_helper.h:414
Definition: Eigen_Colamd.h:49
list x
Definition: plotDoE.py:28
Definition: GenericPacketMath.h:225
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet run(const Packet &a, const Packet &approx_rsqrt)
Definition: MathFunctionsImpl.h:128
std::ofstream out("Result.txt")