Skip to content

Commit 2d11635

Browse files
author
Vijay Vasudevan
committed
TensorFlow: upstream changes from Eigen to make build work
with nvcc in debug mode.
1 parent 2c3738d commit 2d11635

File tree

16 files changed

+536
-27
lines changed

16 files changed

+536
-27
lines changed

third_party/eigen3/Eigen/Core

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ using std::ptrdiff_t;
333333

334334
#include "src/Core/NumTraits.h"
335335
#include "src/Core/MathFunctions.h"
336+
#include "src/Core/SpecialFunctions.h"
336337
#include "src/Core/GenericPacketMath.h"
337338

338339
#if defined EIGEN_VECTORIZE_AVX

third_party/eigen3/Eigen/src/Core/Functors.h

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,6 @@ struct functor_traits<scalar_sin_op<Scalar> >
769769
};
770770
};
771771

772-
773772
/** \internal
774773
* \brief Template functor to compute the tan of a scalar
775774
* \sa class CwiseUnaryOp, ArrayBase::tan()
@@ -827,6 +826,82 @@ struct functor_traits<scalar_asin_op<Scalar> >
827826
};
828827
};
829828

829+
/** \internal
830+
* \brief Template functor to compute the lgamma of a scalar
831+
* \sa class CwiseUnaryOp, ArrayBase::lgamma()
832+
*/
833+
template<typename Scalar> struct scalar_lgamma_op {
834+
EIGEN_EMPTY_STRUCT_CTOR(scalar_lgamma_op)
835+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const {
836+
using numext::lgamma; return lgamma(a);
837+
}
838+
typedef typename packet_traits<Scalar>::type Packet;
839+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& a) const {
840+
return internal::plgamma(a);
841+
}
842+
};
843+
844+
template<typename Scalar>
845+
struct functor_traits<scalar_lgamma_op<Scalar> >
846+
{
847+
enum {
848+
// Guesstimate
849+
Cost = 10 * NumTraits<Scalar>::MulCost + 5 * NumTraits<Scalar>::AddCost,
850+
PacketAccess = packet_traits<Scalar>::HasLGamma
851+
};
852+
};
853+
854+
/** \internal
855+
* \brief Template functor to compute the erf of a scalar
856+
* \sa class CwiseUnaryOp, ArrayBase::erf()
857+
*/
858+
template<typename Scalar> struct scalar_erf_op {
859+
EIGEN_EMPTY_STRUCT_CTOR(scalar_erf_op)
860+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const {
861+
using numext::erf; return erf(a);
862+
}
863+
typedef typename packet_traits<Scalar>::type Packet;
864+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& a) const {
865+
return internal::perf(a);
866+
}
867+
};
868+
869+
template<typename Scalar>
870+
struct functor_traits<scalar_erf_op<Scalar> >
871+
{
872+
enum {
873+
// Guesstimate
874+
Cost = 10 * NumTraits<Scalar>::MulCost + 5 * NumTraits<Scalar>::AddCost,
875+
PacketAccess = packet_traits<Scalar>::HasErf
876+
};
877+
};
878+
879+
/** \internal
880+
* \brief Template functor to compute the erfc of a scalar
881+
* \sa class CwiseUnaryOp, ArrayBase::erfc()
882+
*/
883+
template<typename Scalar> struct scalar_erfc_op {
884+
EIGEN_EMPTY_STRUCT_CTOR(scalar_erfc_op)
885+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const {
886+
using numext::erfc; return erfc(a);
887+
}
888+
typedef typename packet_traits<Scalar>::type Packet;
889+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& a) const {
890+
return internal::perfc(a);
891+
}
892+
};
893+
894+
template<typename Scalar>
895+
struct functor_traits<scalar_erfc_op<Scalar> >
896+
{
897+
enum {
898+
// Guesstimate
899+
Cost = 10 * NumTraits<Scalar>::MulCost + 5 * NumTraits<Scalar>::AddCost,
900+
PacketAccess = packet_traits<Scalar>::HasErfc
901+
};
902+
};
903+
904+
830905
/** \internal
831906
* \brief Template functor to raise a scalar to a power
832907
* \sa class CwiseUnaryOp, Cwise::pow

third_party/eigen3/Eigen/src/Core/GenericPacketMath.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ struct default_packet_traits
6969
HasASin = 0,
7070
HasACos = 0,
7171
HasATan = 0,
72-
HasTanH = 0
72+
HasTanH = 0,
73+
HasLGamma = 0,
74+
HasErf = 0,
75+
HasErfc = 0
7376
};
7477
};
7578

@@ -453,6 +456,18 @@ Packet ptanh(const Packet& x)
453456
return pselect(med_approx, small_approx, ple(pabs(x), thresh));
454457
}
455458

459+
/** \internal \returns the ln(|gamma(\a a)|) (coeff-wise) */
460+
template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
461+
Packet plgamma(const Packet& a) { return numext::lgamma(a); }
462+
463+
/** \internal \returns the erf(\a a) (coeff-wise) */
464+
template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
465+
Packet perf(const Packet& a) { return numext::erf(a); }
466+
467+
/** \internal \returns the erfc(\a a) (coeff-wise) */
468+
template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
469+
Packet perfc(const Packet& a) { return numext::erfc(a); }
470+
456471
/***************************************************************************
457472
* The following functions might not have to be overwritten for vectorized types
458473
***************************************************************************/

third_party/eigen3/Eigen/src/Core/GlobalFunctions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ namespace Eigen
4747
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(tan,scalar_tan_op)
4848
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(atan,scalar_atan_op)
4949
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(tanh,scalar_tanh_op)
50+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(lgamma,scalar_lgamma_op)
51+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(erf,scalar_erf_op)
52+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(erfc,scalar_erfc_op)
5053
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(exp,scalar_exp_op)
5154
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(log,scalar_log_op)
5255
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(abs,scalar_abs_op)
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
// This file is part of Eigen, a lightweight C++ template library
2+
// for linear algebra.
3+
//
4+
// Copyright (C) 2006-2010 Benoit Jacob <[email protected]>
5+
// Copyright (C) 2015 Eugene Brevdo <[email protected]>
6+
//
7+
// This Source Code Form is subject to the terms of the Mozilla
8+
// Public License v. 2.0. If a copy of the MPL was not distributed
9+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10+
11+
#ifndef EIGEN_SPECIALFUNCTIONS_H
12+
#define EIGEN_SPECIALFUNCTIONS_H
13+
14+
namespace Eigen {
15+
16+
namespace internal {
17+
18+
template <typename Scalar>
19+
EIGEN_STRONG_INLINE Scalar __lgamma(Scalar x) {
20+
EIGEN_STATIC_ASSERT((internal::is_same<Scalar, Scalar>::value == false),
21+
THIS_TYPE_IS_NOT_SUPPORTED);
22+
}
23+
24+
template <> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float __lgamma<float>(float x) { return lgammaf(x); }
25+
template <> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double __lgamma<double>(double x) { return lgamma(x); }
26+
27+
template <typename Scalar>
28+
EIGEN_STRONG_INLINE Scalar __erf(Scalar x) {
29+
EIGEN_STATIC_ASSERT((internal::is_same<Scalar, Scalar>::value == false),
30+
THIS_TYPE_IS_NOT_SUPPORTED);
31+
}
32+
33+
template <> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float __erf<float>(float x) { return erff(x); }
34+
template <> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double __erf<double>(double x) { return erf(x); }
35+
36+
template <typename Scalar>
37+
EIGEN_STRONG_INLINE Scalar __erfc(Scalar x) {
38+
EIGEN_STATIC_ASSERT((internal::is_same<Scalar, Scalar>::value == false),
39+
THIS_TYPE_IS_NOT_SUPPORTED);
40+
}
41+
42+
template <> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float __erfc<float>(float x) { return erfcf(x); }
43+
template <> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double __erfc<double>(double x) { return erfc(x); }
44+
45+
} // end namespace internal
46+
47+
/****************************************************************************
48+
* Implementations *
49+
****************************************************************************/
50+
51+
namespace internal {
52+
53+
/****************************************************************************
54+
* Implementation of lgamma *
55+
****************************************************************************/
56+
57+
template<typename Scalar>
58+
struct lgamma_impl
59+
{
60+
EIGEN_DEVICE_FUNC
61+
static EIGEN_STRONG_INLINE Scalar run(const Scalar& x)
62+
{
63+
return __lgamma<Scalar>(x);
64+
}
65+
};
66+
67+
template<typename Scalar>
68+
struct lgamma_retval
69+
{
70+
typedef Scalar type;
71+
};
72+
73+
/****************************************************************************
74+
* Implementation of erf *
75+
****************************************************************************/
76+
77+
template<typename Scalar>
78+
struct erf_impl
79+
{
80+
EIGEN_DEVICE_FUNC
81+
static EIGEN_STRONG_INLINE Scalar run(const Scalar& x)
82+
{
83+
return __erf<Scalar>(x);
84+
}
85+
};
86+
87+
template<typename Scalar>
88+
struct erf_retval
89+
{
90+
typedef Scalar type;
91+
};
92+
93+
/****************************************************************************
94+
* Implementation of erfc *
95+
****************************************************************************/
96+
97+
template<typename Scalar>
98+
struct erfc_impl
99+
{
100+
EIGEN_DEVICE_FUNC
101+
static EIGEN_STRONG_INLINE Scalar run(const Scalar& x)
102+
{
103+
return __erfc<Scalar>(x);
104+
}
105+
};
106+
107+
template<typename Scalar>
108+
struct erfc_retval
109+
{
110+
typedef Scalar type;
111+
};
112+
113+
} // end namespace internal
114+
115+
namespace numext {
116+
117+
template<typename Scalar>
118+
EIGEN_DEVICE_FUNC
119+
inline EIGEN_MATHFUNC_RETVAL(lgamma, Scalar) lgamma(const Scalar& x)
120+
{
121+
return EIGEN_MATHFUNC_IMPL(lgamma, Scalar)::run(x);
122+
}
123+
124+
template<typename Scalar>
125+
EIGEN_DEVICE_FUNC
126+
inline EIGEN_MATHFUNC_RETVAL(erf, Scalar) erf(const Scalar& x)
127+
{
128+
return EIGEN_MATHFUNC_IMPL(erf, Scalar)::run(x);
129+
}
130+
131+
template<typename Scalar>
132+
EIGEN_DEVICE_FUNC
133+
inline EIGEN_MATHFUNC_RETVAL(erfc, Scalar) erfc(const Scalar& x)
134+
{
135+
return EIGEN_MATHFUNC_IMPL(erfc, Scalar)::run(x);
136+
}
137+
138+
} // end namespace numext
139+
140+
} // end namespace Eigen
141+
142+
#endif // EIGEN_SPECIALFUNCTIONS_H

third_party/eigen3/Eigen/src/Core/arch/AVX/PacketMath.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ template<> struct packet_traits<float> : default_packet_traits
6969
HasSqrt = 1,
7070
HasRsqrt = 1,
7171
HasSelect = 1,
72-
HasEq = 1,
72+
HasEq = 1
7373
};
7474
};
7575
template<> struct packet_traits<double> : default_packet_traits
@@ -155,11 +155,11 @@ template<> EIGEN_STRONG_INLINE Packet4d pmul<Packet4d>(const Packet4d& a, const
155155

156156
#ifdef __FMA__
157157
template<> EIGEN_STRONG_INLINE Packet8f pmadd(const Packet8f& a, const Packet8f& b, const Packet8f& c) {
158-
#if EIGEN_COMP_GNUC || EIGEN_COMP_CLANG
158+
#if EIGEN_GNUC_AT_MOST(4, 8) || EIGEN_COMP_CLANG
159159
// clang stupidly generates a vfmadd213ps instruction plus some vmovaps on registers,
160160
// and gcc stupidly generates a vfmadd132ps instruction,
161161
// so let's enforce it to generate a vfmadd231ps instruction since the most common use case is to accumulate
162-
// the result of the product.
162+
// the result of the product. the issue has been fixed in gcc 4.9
163163
Packet8f res = c;
164164
asm("vfmadd231ps %[a], %[b], %[c]" : [c] "+x" (res) : [a] "x" (a), [b] "x" (b));
165165
return res;
@@ -168,7 +168,7 @@ template<> EIGEN_STRONG_INLINE Packet8f pmadd(const Packet8f& a, const Packet8f&
168168
#endif
169169
}
170170
template<> EIGEN_STRONG_INLINE Packet4d pmadd(const Packet4d& a, const Packet4d& b, const Packet4d& c) {
171-
#if EIGEN_COMP_GNUC || EIGEN_COMP_CLANG
171+
#if EIGEN_GNUC_AT_MOST(4, 8) || EIGEN_COMP_CLANG
172172
// see above
173173
Packet4d res = c;
174174
asm("vfmadd231pd %[a], %[b], %[c]" : [c] "+x" (res) : [a] "x" (a), [b] "x" (b));

third_party/eigen3/Eigen/src/Core/arch/CUDA/MathFunctions.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,43 @@ double2 prsqrt<double2>(const double2& a)
6666
return make_double2(rsqrt(a.x), rsqrt(a.y));
6767
}
6868

69+
template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
70+
float4 plgamma<float4>(const float4& a)
71+
{
72+
return make_float4(lgammaf(a.x), lgammaf(a.y), lgammaf(a.z), lgammaf(a.w));
73+
}
74+
75+
template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
76+
double2 plgamma<double2>(const double2& a)
77+
{
78+
return make_double2(lgamma(a.x), lgamma(a.y));
79+
}
80+
81+
template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
82+
float4 perf<float4>(const float4& a)
83+
{
84+
return make_float4(erf(a.x), erf(a.y), erf(a.z), erf(a.w));
85+
}
86+
87+
template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
88+
double2 perf<double2>(const double2& a)
89+
{
90+
return make_double2(erf(a.x), erf(a.y));
91+
}
92+
93+
template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
94+
float4 perfc<float4>(const float4& a)
95+
{
96+
return make_float4(erfc(a.x), erfc(a.y), erfc(a.z), erfc(a.w));
97+
}
98+
99+
template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
100+
double2 perfc<double2>(const double2& a)
101+
{
102+
return make_double2(erfc(a.x), erfc(a.y));
103+
}
104+
105+
69106
#endif
70107

71108
} // end namespace internal

third_party/eigen3/Eigen/src/Core/arch/CUDA/PacketMath.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ template<> struct packet_traits<float> : default_packet_traits
3838
HasExp = 1,
3939
HasSqrt = 1,
4040
HasRsqrt = 1,
41+
HasLGamma = 1,
42+
HasErf = 1,
43+
HasErfc = 1,
4144

4245
HasBlend = 0,
4346
HasSelect = 1,
@@ -60,6 +63,9 @@ template<> struct packet_traits<double> : default_packet_traits
6063
HasExp = 1,
6164
HasSqrt = 1,
6265
HasRsqrt = 1,
66+
HasLGamma = 1,
67+
HasErf = 1,
68+
HasErfc = 1,
6369

6470
HasBlend = 0,
6571
HasSelect = 1,

0 commit comments

Comments
 (0)