InteropHeaders.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 // Mehdi Goli Codeplay Software Ltd.
5 // Ralph Potter Codeplay Software Ltd.
6 // Luke Iwanski Codeplay Software Ltd.
7 // Contact: <eigen@codeplay.com>
8 //
9 // This Source Code Form is subject to the terms of the Mozilla
10 // Public License v. 2.0. If a copy of the MPL was not distributed
11 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
12 
13 /*****************************************************************
14  * InteropHeaders.h
15  *
16  * \brief:
17  * InteropHeaders
18  *
19  *****************************************************************/
20 
21 #ifndef EIGEN_INTEROP_HEADERS_SYCL_H
22 #define EIGEN_INTEROP_HEADERS_SYCL_H
23 
24 // IWYU pragma: private
25 #include "../../InternalHeaderCheck.h"
26 
27 namespace Eigen {
28 
29 #if !defined(EIGEN_DONT_VECTORIZE_SYCL)
30 
31 namespace internal {
32 
33 template <int has_blend, int lengths>
35  enum {
38  size = lengths,
39  HasDiv = 1,
40  HasLog = 1,
41  HasExp = 1,
42  HasSqrt = 1,
43  HasRsqrt = 1,
44  HasSin = 1,
45  HasCos = 1,
46  HasTan = 1,
47  HasASin = 1,
48  HasACos = 1,
49  HasATan = 1,
50  HasSinh = 1,
51  HasCosh = 1,
52  HasTanh = 1,
53  HasLGamma = 0,
55  HasZeta = 0,
57  HasErf = 0,
58  HasErfc = 0,
59  HasNdtri = 0,
60  HasIGamma = 0,
63  HasBlend = has_blend,
64  // This flag is used to indicate whether packet comparison is supported.
65  // pcmp_eq, pcmp_lt and pcmp_le should be defined for it to be true.
66  HasCmp = 1,
67  HasMax = 1,
68  HasMin = 1,
69  HasMul = 1,
70  HasAdd = 1,
71  HasFloor = 1,
72  HasRound = 1,
73  HasRint = 1,
74  HasLog1p = 1,
75  HasExpm1 = 1,
76  HasCeil = 1,
77  };
78 };
79 
80 #ifdef SYCL_DEVICE_ONLY
81 #define SYCL_PACKET_TRAITS(packet_type, has_blend, unpacket_type, lengths) \
82  template <> \
83  struct packet_traits<unpacket_type> : sycl_packet_traits<has_blend, lengths> { \
84  typedef packet_type type; \
85  typedef packet_type half; \
86  };
87 
88 SYCL_PACKET_TRAITS(cl::sycl::cl_half8, 1, Eigen::half, 8)
89 SYCL_PACKET_TRAITS(cl::sycl::cl_half8, 1, const Eigen::half, 8)
90 SYCL_PACKET_TRAITS(cl::sycl::cl_float4, 1, float, 4)
91 SYCL_PACKET_TRAITS(cl::sycl::cl_float4, 1, const float, 4)
92 SYCL_PACKET_TRAITS(cl::sycl::cl_double2, 0, double, 2)
93 SYCL_PACKET_TRAITS(cl::sycl::cl_double2, 0, const double, 2)
94 #undef SYCL_PACKET_TRAITS
95 
96 // Make sure this is only available when targeting a GPU: we don't want to
97 // introduce conflicts between these packet_traits definitions and the ones
98 // we'll use on the host side (SSE, AVX, ...)
99 #define SYCL_ARITHMETIC(packet_type) \
100  template <> \
101  struct is_arithmetic<packet_type> { \
102  enum { value = true }; \
103  };
104 SYCL_ARITHMETIC(cl::sycl::cl_half8)
105 SYCL_ARITHMETIC(cl::sycl::cl_float4)
106 SYCL_ARITHMETIC(cl::sycl::cl_double2)
107 #undef SYCL_ARITHMETIC
108 
109 #define SYCL_UNPACKET_TRAITS(packet_type, unpacket_type, lengths) \
110  template <> \
111  struct unpacket_traits<packet_type> { \
112  typedef unpacket_type type; \
113  enum { size = lengths, vectorizable = true, alignment = Aligned16 }; \
114  typedef packet_type half; \
115  };
116 SYCL_UNPACKET_TRAITS(cl::sycl::cl_half8, Eigen::half, 8)
117 SYCL_UNPACKET_TRAITS(cl::sycl::cl_float4, float, 4)
118 SYCL_UNPACKET_TRAITS(cl::sycl::cl_double2, double, 2)
119 
120 #undef SYCL_UNPACKET_TRAITS
121 #endif
122 
123 } // end namespace internal
124 
125 #endif
126 
127 namespace TensorSycl {
128 namespace internal {
129 
130 template <typename PacketReturnType, int PacketSize>
131 struct PacketWrapper;
132 // This function should never get called on the device
133 #ifndef SYCL_DEVICE_ONLY
134 template <typename PacketReturnType, int PacketSize>
137  template <typename Index>
138  EIGEN_DEVICE_FUNC static Scalar scalarize(Index, PacketReturnType &) {
139  eigen_assert(false && "THERE IS NO PACKETIZE VERSION FOR THE CHOSEN TYPE");
140  abort();
141  }
142  EIGEN_DEVICE_FUNC static PacketReturnType convert_to_packet_type(Scalar in, Scalar) {
143  return ::Eigen::internal::template plset<PacketReturnType>(in);
144  }
145  EIGEN_DEVICE_FUNC static void set_packet(PacketReturnType, Scalar *) {
146  eigen_assert(false && "THERE IS NO PACKETIZE VERSION FOR THE CHOSEN TYPE");
147  abort();
148  }
149 };
150 
151 #elif defined(SYCL_DEVICE_ONLY)
152 template <typename PacketReturnType>
153 struct PacketWrapper<PacketReturnType, 4> {
155  template <typename Index>
156  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE static Scalar scalarize(Index index, PacketReturnType &in) {
157  switch (index) {
158  case 0:
159  return in.x();
160  case 1:
161  return in.y();
162  case 2:
163  return in.z();
164  case 3:
165  return in.w();
166  default:
167  // INDEX MUST BE BETWEEN 0 and 3.There is no abort function in SYCL kernel. so we cannot use abort here.
168  // The code will never reach here
169  __builtin_unreachable();
170  }
171  __builtin_unreachable();
172  }
173 
174  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE static PacketReturnType convert_to_packet_type(Scalar in, Scalar other) {
175  return PacketReturnType(in, other, other, other);
176  }
177  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE static void set_packet(PacketReturnType &lhs, Scalar *rhs) {
178  lhs = PacketReturnType(rhs[0], rhs[1], rhs[2], rhs[3]);
179  }
180 };
181 
182 template <typename PacketReturnType>
183 struct PacketWrapper<PacketReturnType, 1> {
185  template <typename Index>
186  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE static Scalar scalarize(Index, PacketReturnType &in) {
187  return in;
188  }
190  return PacketReturnType(in);
191  }
192  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE static void set_packet(PacketReturnType &lhs, Scalar *rhs) { lhs = rhs[0]; }
193 };
194 
195 template <typename PacketReturnType>
196 struct PacketWrapper<PacketReturnType, 2> {
198  template <typename Index>
199  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE static Scalar scalarize(Index index, PacketReturnType &in) {
200  switch (index) {
201  case 0:
202  return in.x();
203  case 1:
204  return in.y();
205  default:
206  // INDEX MUST BE BETWEEN 0 and 1.There is no abort function in SYCL kernel. so we cannot use abort here.
207  // The code will never reach here
208  __builtin_unreachable();
209  }
210  __builtin_unreachable();
211  }
212 
213  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE static PacketReturnType convert_to_packet_type(Scalar in, Scalar other) {
214  return PacketReturnType(in, other);
215  }
216  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE static void set_packet(PacketReturnType &lhs, Scalar *rhs) {
217  lhs = PacketReturnType(rhs[0], rhs[1]);
218  }
219 };
220 
221 #endif
222 
223 } // end namespace internal
224 } // end namespace TensorSycl
225 } // end namespace Eigen
226 
227 #endif // EIGEN_INTEROP_HEADERS_SYCL_H
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:892
#define eigen_assert(x)
Definition: Macros.h:910
#define EIGEN_STRONG_INLINE
Definition: Macros.h:834
SCALAR Scalar
Definition: bench_gemm.cpp:45
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
type
Definition: compute_granudrum_aor.py:141
Definition: Eigen_Colamd.h:49
Definition: InteropHeaders.h:135
::Eigen::internal::unpacket_traits< PacketReturnType >::type Scalar
Definition: InteropHeaders.h:136
static EIGEN_DEVICE_FUNC void set_packet(PacketReturnType, Scalar *)
Definition: InteropHeaders.h:145
static EIGEN_DEVICE_FUNC PacketReturnType convert_to_packet_type(Scalar in, Scalar)
Definition: InteropHeaders.h:142
static EIGEN_DEVICE_FUNC Scalar scalarize(Index, PacketReturnType &)
Definition: InteropHeaders.h:138
Definition: Half.h:139
Definition: GenericPacketMath.h:45
Definition: InteropHeaders.h:34
@ HasCmp
Definition: InteropHeaders.h:66
@ HasIGammac
Definition: InteropHeaders.h:61
@ HasExp
Definition: InteropHeaders.h:41
@ HasSin
Definition: InteropHeaders.h:44
@ HasErfc
Definition: InteropHeaders.h:58
@ HasFloor
Definition: InteropHeaders.h:71
@ HasLGamma
Definition: InteropHeaders.h:53
@ HasMul
Definition: InteropHeaders.h:69
@ HasDiGamma
Definition: InteropHeaders.h:54
@ HasSqrt
Definition: InteropHeaders.h:42
@ HasLog1p
Definition: InteropHeaders.h:74
@ HasRsqrt
Definition: InteropHeaders.h:43
@ HasErf
Definition: InteropHeaders.h:57
@ HasZeta
Definition: InteropHeaders.h:55
@ HasIGamma
Definition: InteropHeaders.h:60
@ HasACos
Definition: InteropHeaders.h:48
@ HasAdd
Definition: InteropHeaders.h:70
@ HasTan
Definition: InteropHeaders.h:46
@ Vectorizable
Definition: InteropHeaders.h:36
@ HasATan
Definition: InteropHeaders.h:49
@ HasBlend
Definition: InteropHeaders.h:63
@ HasCosh
Definition: InteropHeaders.h:51
@ HasMin
Definition: InteropHeaders.h:68
@ AlignedOnScalar
Definition: InteropHeaders.h:37
@ HasBetaInc
Definition: InteropHeaders.h:62
@ HasRound
Definition: InteropHeaders.h:72
@ HasSinh
Definition: InteropHeaders.h:50
@ HasPolygamma
Definition: InteropHeaders.h:56
@ HasExpm1
Definition: InteropHeaders.h:75
@ HasTanh
Definition: InteropHeaders.h:52
@ HasLog
Definition: InteropHeaders.h:40
@ size
Definition: InteropHeaders.h:38
@ HasMax
Definition: InteropHeaders.h:67
@ HasNdtri
Definition: InteropHeaders.h:59
@ HasDiv
Definition: InteropHeaders.h:39
@ HasCeil
Definition: InteropHeaders.h:76
@ HasASin
Definition: InteropHeaders.h:47
@ HasCos
Definition: InteropHeaders.h:45
@ HasRint
Definition: InteropHeaders.h:73
Definition: ZVector/PacketMath.h:50