Eigen-unsupported  5.0.1-dev+284dcc12
 
Loading...
Searching...
No Matches
TensorMeta.h
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
16namespace Eigen {
17
18template <bool cond>
19struct Cond {};
20
21template <typename T1, typename T2>
22EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE const T1& choose(Cond<true>, const T1& first, const T2&) {
23 return first;
24}
25
26template <typename T1, typename T2>
27EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE const T2& choose(Cond<false>, const T1&, const T2& second) {
28 return second;
29}
30
31template <size_t n>
32struct max_n_1 {
33 static const size_t size = n;
34};
35template <>
36struct max_n_1<0> {
37 static const size_t size = 1;
38};
39
40template <typename T>
41EIGEN_DEPRECATED EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE constexpr T divup(const T x, const T y) {
42 return Eigen::numext::div_ceil(x, y);
43}
44
45// Default packet types
46template <typename Scalar, typename Device>
47struct PacketType : internal::packet_traits<Scalar> {
48 typedef typename internal::packet_traits<Scalar>::type type;
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
54typedef ulonglong2 Packet4h2;
55template <>
56struct 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
88namespace TensorSycl {
89namespace internal {
90
91template <typename Index, Index A, Index B>
92struct PlusOp {
93 static constexpr Index Value = A + B;
94};
95
96template <typename Index, Index A, Index B>
97struct DivOp {
98 static constexpr Index Value = A / B;
99};
100
101template <typename Index, Index start, Index end, Index step, template <class Indx, Indx...> class StepOp>
102struct static_for {
103 template <typename UnaryOperator>
104 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void loop(UnaryOperator op) {
105 op(start);
106 static_for<Index, StepOp<Index, start, step>::Value, end, step, StepOp>::loop(op);
107 }
108};
109template <typename Index, Index end, Index step, template <class Indx, Indx...> class StepOp>
110struct static_for<Index, end, end, step, StepOp> {
111 template <typename UnaryOperator>
112 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void loop(UnaryOperator) {}
113};
114
115template <typename OutScalar, typename Device, bool Vectorizable>
116struct Vectorise {
117 static constexpr int PacketSize = 1;
118 typedef OutScalar PacketReturnType;
119};
120
121template <typename OutScalar, typename Device>
122struct 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
127static 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
132template <>
133struct 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};
151template <typename Scalar>
152struct 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
174template <typename Scalar>
175struct 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
185PACKET_TYPE(const, float, 1, 4, SyclDevice)
186PACKET_TYPE(, float, 1, 4, SyclDevice)
187PACKET_TYPE(const, float, 1, 4, const SyclDevice)
188PACKET_TYPE(, float, 1, 4, const SyclDevice)
189
190PACKET_TYPE(const, double, 0, 2, SyclDevice)
191PACKET_TYPE(, double, 0, 2, SyclDevice)
192PACKET_TYPE(const, double, 0, 2, const SyclDevice)
193PACKET_TYPE(, double, 0, 2, const SyclDevice)
194#undef PACKET_TYPE
195
196template <>
197struct PacketType<half, const SyclDevice> : PacketType<half, SyclDevice> {};
198template <>
199struct PacketType<const half, const SyclDevice> : PacketType<half, SyclDevice> {};
200#endif
201#endif
202
203// Pair mimics std::pair but works on e.g. nvcc.
204template <typename U, typename V>
205struct Pair {
206 public:
207 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
208
209 U first;
210 V second;
211
212 typedef U first_type;
213 typedef V second_type;
214
215 constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Pair() : first(), second() {}
216
217 constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Pair(const U& f, const V& s) : first(f), second(s) {}
218
219 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void swap(Pair& rhs) {
220 using numext::swap;
221 swap(first, rhs.first);
222 swap(second, rhs.second);
223 }
224};
225
226template <typename U, typename V>
227constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator==(const Pair<U, V>& x, const Pair<U, V>& y) {
228 return (x.first == y.first && x.second == y.second);
229}
230
231template <typename U, typename V>
232constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator!=(const Pair<U, V>& x, const Pair<U, V>& y) {
233 return !(x == y);
234}
235
236// Can't use std::pairs on cuda devices
237template <typename Idx>
238struct IndexPair {
239 constexpr EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE IndexPair() : first(0), second(0) {}
240 constexpr EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE IndexPair(Idx f, Idx s) : first(f), second(s) {}
241
242 EIGEN_DEVICE_FUNC void set(IndexPair<Idx> val) {
243 first = val.first;
244 second = val.second;
245 }
246
247 Idx first;
248 Idx second;
249};
250
251namespace internal {
252
253template <typename IndexType, typename Index, Index First, Index... Is>
254constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE array<Index, 1 + sizeof...(Is)> customIndices2Array(
255 IndexType& idx, numeric_list<Index, First, Is...>) {
256 return {static_cast<Index>(idx[First]), static_cast<Index>(idx[Is])...};
257}
258template <typename IndexType, typename Index>
259constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE array<Index, 0> customIndices2Array(IndexType&, numeric_list<Index>) {
260 return array<Index, 0>();
261}
262
264template <typename Index, std::size_t NumIndices, typename IndexType>
265constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE array<Index, NumIndices> customIndices2Array(IndexType& idx) {
266 return customIndices2Array(idx, typename gen_numeric_list<Index, NumIndices>::type{});
267}
268
269template <typename B, typename D>
270struct is_base_of {
271 typedef char (&yes)[1];
272 typedef char (&no)[2];
273
274 template <typename BB, typename DD>
275 struct Host {
276 operator BB*() const;
277 operator DD*();
278 };
279
280 template <typename T>
281 static yes check(D*, T);
282 static no check(B*, int);
283
284 static const bool value = sizeof(check(Host<B, D>(), int())) == sizeof(yes);
285};
286
287} // namespace internal
288
289} // namespace Eigen
290
291#endif // EIGEN_CXX11_TENSOR_TENSOR_META_H
Namespace containing all symbols from the Eigen library.
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index