TensorMeta.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) 2015 Benoit Steiner <benoit.steiner.goog@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 EIGEN_CXX11_TENSOR_TENSOR_META_H
11 #define EIGEN_CXX11_TENSOR_TENSOR_META_H
12 
13 // IWYU pragma: private
14 #include "./InternalHeaderCheck.h"
15 
16 namespace Eigen {
17 
18 template <bool cond>
19 struct Cond {};
20 
21 template <typename T1, typename T2>
22 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE const T1& choose(Cond<true>, const T1& first, const T2&) {
23  return first;
24 }
25 
26 template <typename T1, typename T2>
27 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE const T2& choose(Cond<false>, const T1&, const T2& second) {
28  return second;
29 }
30 
31 template <size_t n>
32 struct max_n_1 {
33  static const size_t size = n;
34 };
35 template <>
36 struct max_n_1<0> {
37  static const size_t size = 1;
38 };
39 
40 template <typename T>
42  return Eigen::numext::div_ceil(x, y);
43 }
44 
45 // Default packet types
46 template <typename Scalar, typename Device>
49 };
50 
51 // For CUDA packet types when using a GpuDevice
52 #if defined(EIGEN_USE_GPU) && defined(EIGEN_HAS_GPU_FP16) && defined(EIGEN_GPU_COMPILE_PHASE)
53 
54 typedef ulonglong2 Packet4h2;
55 template <>
56 struct PacketType<half, GpuDevice> {
57  typedef Packet4h2 type;
58  static const int size = 8;
59  enum {
60  HasAdd = 1,
61  HasSub = 1,
62  HasMul = 1,
63  HasNegate = 1,
64  HasAbs = 1,
65  HasArg = 0,
66  HasAbs2 = 0,
67  HasMin = 1,
68  HasMax = 1,
69  HasConj = 0,
70  HasSetLinear = 0,
71  HasBlend = 0,
72 
73  HasDiv = 1,
74  HasSqrt = 1,
75  HasRsqrt = 1,
76  HasExp = 1,
77  HasExpm1 = 0,
78  HasLog = 1,
79  HasLog1p = 0,
80  HasLog10 = 0,
81  HasPow = 1,
82  };
83 };
84 #endif
85 
86 #if defined(EIGEN_USE_SYCL)
87 
88 namespace TensorSycl {
89 namespace internal {
90 
91 template <typename Index, Index A, Index B>
92 struct PlusOp {
93  static constexpr Index Value = A + B;
94 };
95 
96 template <typename Index, Index A, Index B>
97 struct DivOp {
98  static constexpr Index Value = A / B;
99 };
100 
101 template <typename Index, Index start, Index end, Index step, template <class Indx, Indx...> class StepOp>
102 struct static_for {
103  template <typename UnaryOperator>
104  static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void loop(UnaryOperator op) {
105  op(start);
107  }
108 };
109 template <typename Index, Index end, Index step, template <class Indx, Indx...> class StepOp>
110 struct static_for<Index, end, end, step, StepOp> {
111  template <typename UnaryOperator>
112  static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void loop(UnaryOperator) {}
113 };
114 
115 template <typename OutScalar, typename Device, bool Vectorizable>
116 struct Vectorise {
117  static constexpr int PacketSize = 1;
118  typedef OutScalar PacketReturnType;
119 };
120 
121 template <typename OutScalar, typename Device>
122 struct Vectorise<OutScalar, Device, true> {
123  static constexpr int PacketSize = Eigen::PacketType<OutScalar, Device>::size;
124  typedef typename Eigen::PacketType<OutScalar, Device>::type PacketReturnType;
125 };
126 
127 static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Index roundUp(Index x, Index y) { return ((((x) + (y)-1) / (y)) * (y)); }
128 
129 } // namespace internal
130 } // namespace TensorSycl
131 
132 template <>
133 struct PacketType<half, SyclDevice> {
134  typedef half type;
135  static const int size = 1;
136  enum {
137  HasAdd = 0,
138  HasSub = 0,
139  HasMul = 0,
140  HasNegate = 0,
141  HasAbs = 0,
142  HasArg = 0,
143  HasAbs2 = 0,
144  HasMin = 0,
145  HasMax = 0,
146  HasConj = 0,
147  HasSetLinear = 0,
148  HasBlend = 0
149  };
150 };
151 template <typename Scalar>
152 struct PacketType<Scalar, SyclDevice> : internal::default_packet_traits {
153  typedef Scalar type;
154  typedef Scalar half;
155  enum {
156  Vectorizable = 0,
157  size = 1,
158  AlignedOnScalar = 0,
159  };
160  enum {
161  HasAdd = 0,
162  HasSub = 0,
163  HasMul = 0,
164  HasNegate = 0,
165  HasAbs = 0,
166  HasAbs2 = 0,
167  HasMin = 0,
168  HasMax = 0,
169  HasConj = 0,
170  HasSetLinear = 0
171  };
172 };
173 
174 template <typename Scalar>
175 struct PacketType<Scalar, const SyclDevice> : PacketType<Scalar, SyclDevice> {};
176 
177 #ifndef EIGEN_DONT_VECTORIZE_SYCL
178 #define PACKET_TYPE(CVQual, Type, val, lengths, DEV) \
179  template <> \
180  struct PacketType<CVQual Type, DEV> : internal::sycl_packet_traits<val, lengths> { \
181  typedef typename internal::packet_traits<Type>::type type; \
182  typedef typename internal::packet_traits<Type>::half half; \
183  };
184 
185 PACKET_TYPE(const, float, 1, 4, SyclDevice)
186 PACKET_TYPE(, float, 1, 4, SyclDevice)
187 PACKET_TYPE(const, float, 1, 4, const SyclDevice)
188 PACKET_TYPE(, float, 1, 4, const SyclDevice)
189 
190 PACKET_TYPE(const, double, 0, 2, SyclDevice)
191 PACKET_TYPE(, double, 0, 2, SyclDevice)
192 PACKET_TYPE(const, double, 0, 2, const SyclDevice)
193 PACKET_TYPE(, double, 0, 2, const SyclDevice)
194 #undef PACKET_TYPE
195 
196 template <>
197 struct PacketType<half, const SyclDevice> : PacketType<half, SyclDevice> {};
198 template <>
199 struct PacketType<const half, const SyclDevice> : PacketType<half, SyclDevice> {};
200 #endif
201 #endif
202 
203 // Pair mimics std::pair but works on e.g. nvcc.
204 template <typename U, typename V>
205 struct Pair {
206  public:
208 
211 
212  typedef U first_type;
213  typedef V second_type;
214 
216 
218 
220  using numext::swap;
221  swap(first, rhs.first);
222  swap(second, rhs.second);
223  }
224 };
225 
226 template <typename U, typename V>
228  return (x.first == y.first && x.second == y.second);
229 }
230 
231 template <typename U, typename V>
233  return !(x == y);
234 }
235 
236 // Can't use std::pairs on cuda devices
237 template <typename Idx>
238 struct IndexPair {
241 
243  first = val.first;
244  second = val.second;
245  }
246 
247  Idx first;
248  Idx second;
249 };
250 
251 namespace internal {
252 
253 template <typename IndexType, typename Index, Index First, Index... Is>
255  IndexType& idx, numeric_list<Index, First, Is...>) {
256  return {static_cast<Index>(idx[First]), static_cast<Index>(idx[Is])...};
257 }
258 template <typename IndexType, typename Index>
261  return array<Index, 0>();
262 }
263 
265 template <typename Index, std::size_t NumIndices, typename IndexType>
268 }
269 
270 template <typename B, typename D>
271 struct is_base_of {
272  typedef char (&yes)[1];
273  typedef char (&no)[2];
274 
275  template <typename BB, typename DD>
276  struct Host {
277  operator BB*() const;
278  operator DD*();
279  };
280 
281  template <typename T>
282  static yes check(D*, T);
283  static no check(B*, int);
284 
285  static const bool value = sizeof(check(Host<B, D>(), int())) == sizeof(yes);
286 };
287 
288 } // namespace internal
289 
290 } // namespace Eigen
291 
292 #endif // EIGEN_CXX11_TENSOR_TENSOR_META_H
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
dominoes D
Definition: Domino.cpp:55
MatrixXcd V
Definition: EigenSolver_EigenSolver_MatrixType.cpp:15
#define EIGEN_ALWAYS_INLINE
Definition: Macros.h:845
#define EIGEN_DEPRECATED
Definition: Macros.h:931
#define EIGEN_CONSTEXPR
Definition: Macros.h:758
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:892
#define EIGEN_STRONG_INLINE
Definition: Macros.h:834
#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW
Definition: Memory.h:879
SCALAR Scalar
Definition: bench_gemm.cpp:45
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition: bench_gemm.cpp:47
Matrix< SCALARB, Dynamic, Dynamic, opt_B > B
Definition: bench_gemm.cpp:48
Definition: matrices.h:74
static int f(const TensorMap< Tensor< int, 3 > > &tensor)
Definition: cxx11_tensor_map.cpp:237
static constexpr lastp1_t end
Definition: IndexedViewHelper.h:79
Scalar * y
Definition: level1_cplx_impl.h:128
RealScalar s
Definition: level1_cplx_impl.h:130
char char * op
Definition: level2_impl.h:374
EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE array< Index, 1+sizeof...(Is)> customIndices2Array(IndexType &idx, numeric_list< Index, First, Is... >)
Definition: TensorMeta.h:254
EIGEN_STRONG_INLINE void swap(T &a, T &b)
Definition: Meta.h:536
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE EIGEN_CONSTEXPR T div_ceil(T a, T b)
Definition: MathFunctions.h:1251
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
EIGEN_DEPRECATED EIGEN_DEVICE_FUNC constexpr EIGEN_ALWAYS_INLINE T divup(const T x, const T y)
Definition: TensorMeta.h:41
std::array< T, N > array
Definition: EmulateArray.h:231
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE const T1 & choose(Cond< true >, const T1 &first, const T2 &)
Definition: TensorMeta.h:22
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator!=(const Pair< U, V > &x, const Pair< U, V > &y)
Definition: TensorMeta.h:232
EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator==(const Pair< U, V > &x, const Pair< U, V > &y)
Definition: TensorMeta.h:227
double U
Swimming speed.
Definition: two_d_variable_diff_adapt.cc:53
val
Definition: calibrate.py:119
Definition: Eigen_Colamd.h:49
void start(const unsigned &i)
(Re-)start i-th timer
Definition: oomph_utilities.cc:243
list x
Definition: plotDoE.py:28
GenericValue< UTF8<> > Value
Value with UTF8 encoding.
Definition: document.h:679
Definition: TensorMeta.h:19
Definition: TensorMeta.h:238
EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE IndexPair()
Definition: TensorMeta.h:239
EIGEN_DEVICE_FUNC void set(IndexPair< Idx > val)
Definition: TensorMeta.h:242
Idx first
Definition: TensorMeta.h:247
Idx second
Definition: TensorMeta.h:248
EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE IndexPair(Idx f, Idx s)
Definition: TensorMeta.h:240
Definition: TensorMeta.h:47
internal::packet_traits< Scalar >::type type
Definition: TensorMeta.h:48
Definition: TensorMeta.h:205
U first_type
Definition: TensorMeta.h:212
EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Pair(const U &f, const V &s)
Definition: TensorMeta.h:217
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void swap(Pair &rhs)
Definition: TensorMeta.h:219
EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Pair()
Definition: TensorMeta.h:215
V second
Definition: TensorMeta.h:210
V second_type
Definition: TensorMeta.h:213
EIGEN_MAKE_ALIGNED_OPERATOR_NEW U first
Definition: TensorMeta.h:209
Definition: Half.h:139
@ HasRsqrt
Definition: GenericPacketMath.h:74
@ HasBlend
Definition: GenericPacketMath.h:66
@ HasLog10
Definition: GenericPacketMath.h:79
@ HasArg
Definition: GenericPacketMath.h:64
@ HasLog1p
Definition: GenericPacketMath.h:78
@ HasPow
Definition: GenericPacketMath.h:80
@ HasExp
Definition: GenericPacketMath.h:75
@ HasSqrt
Definition: GenericPacketMath.h:73
@ HasExpm1
Definition: GenericPacketMath.h:76
@ HasLog
Definition: GenericPacketMath.h:77
@ HasDiv
Definition: GenericPacketMath.h:71
Definition: MoreMeta.h:55
Definition: TensorMeta.h:276
Definition: TensorMeta.h:271
static const bool value
Definition: TensorMeta.h:285
static no check(B *, int)
char(& yes)[1]
Definition: TensorMeta.h:272
char(& no)[2]
Definition: TensorMeta.h:273
static yes check(D *, T)
Definition: MoreMeta.h:33
Definition: GenericPacketMath.h:108
@ size
Definition: GenericPacketMath.h:113
@ AlignedOnScalar
Definition: GenericPacketMath.h:114
@ Vectorizable
Definition: GenericPacketMath.h:112
Scalar half
Definition: GenericPacketMath.h:110
@ HasSub
Definition: GenericPacketMath.h:118
@ HasMax
Definition: GenericPacketMath.h:124
@ HasNegate
Definition: GenericPacketMath.h:120
@ HasMul
Definition: GenericPacketMath.h:119
@ HasAdd
Definition: GenericPacketMath.h:117
@ HasSetLinear
Definition: GenericPacketMath.h:126
@ HasMin
Definition: GenericPacketMath.h:123
@ HasConj
Definition: GenericPacketMath.h:125
@ HasAbs2
Definition: GenericPacketMath.h:122
@ HasAbs
Definition: GenericPacketMath.h:121
Definition: TensorMeta.h:32
static const size_t size
Definition: TensorMeta.h:33