Half.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 // This Source Code Form is subject to the terms of the Mozilla
5 // Public License v. 2.0. If a copy of the MPL was not distributed
6 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 //
8 // The conversion routines are Copyright (c) Fabian Giesen, 2016.
9 // The original license follows:
10 //
11 // Copyright (c) Fabian Giesen, 2016
12 // All rights reserved.
13 // Redistribution and use in source and binary forms, with or without
14 // modification, are permitted.
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 
27 // Standard 16-bit float type, mostly useful for GPUs. Defines a new
28 // type Eigen::half (inheriting either from CUDA's or HIP's __half struct) with
29 // operator overloads such that it behaves basically as an arithmetic
30 // type. It will be quite slow on CPUs (so it is recommended to stay
31 // in fp32 for CPUs, except for simple parameter conversions, I/O
32 // to disk and the likes), but fast on GPUs.
33 
34 #ifndef EIGEN_HALF_H
35 #define EIGEN_HALF_H
36 
37 // IWYU pragma: private
38 #include "../../InternalHeaderCheck.h"
39 
40 #if defined(EIGEN_HAS_GPU_FP16) || defined(EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC)
41 // When compiling with GPU support, the "__half_raw" base class as well as
42 // some other routines are defined in the GPU compiler header files
43 // (cuda_fp16.h, hip_fp16.h), and they are not tagged constexpr
44 // As a consequence, we get compile failures when compiling Eigen with
45 // GPU support. Hence the need to disable EIGEN_CONSTEXPR when building
46 // Eigen with GPU support
47 #pragma push_macro("EIGEN_CONSTEXPR")
48 #undef EIGEN_CONSTEXPR
49 #define EIGEN_CONSTEXPR
50 #endif
51 
52 #define F16_PACKET_FUNCTION(PACKET_F, PACKET_F16, METHOD) \
53  template <> \
54  EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC EIGEN_UNUSED PACKET_F16 METHOD<PACKET_F16>(const PACKET_F16& _x) { \
55  return float2half(METHOD<PACKET_F>(half2float(_x))); \
56  }
57 
58 namespace Eigen {
59 
60 struct half;
61 
62 namespace half_impl {
63 
64 // We want to use the __half_raw struct from the HIP header file only during the device compile phase.
65 // This is required because of a quirk in the way TensorFlow GPU builds are done.
66 // When compiling TensorFlow source code with GPU support, files that
67 // * contain GPU kernels (i.e. *.cu.cc files) are compiled via hipcc
68 // * do not contain GPU kernels ( i.e. *.cc files) are compiled via gcc (typically)
69 //
70 // Tensorflow uses the Eigen::half type as its FP16 type, and there are functions that
71 // * are defined in a file that gets compiled via hipcc AND
72 // * have Eigen::half as a pass-by-value argument AND
73 // * are called in a file that gets compiled via gcc
74 //
75 // In the scenario described above the caller and callee will see different versions
76 // of the Eigen::half base class __half_raw, and they will be compiled by different compilers
77 //
78 // There appears to be an ABI mismatch between gcc and clang (which is called by hipcc) that results in
79 // the callee getting corrupted values for the Eigen::half argument.
80 //
81 // Making the host side compile phase of hipcc use the same Eigen::half impl, as the gcc compile, resolves
82 // this error, and hence the following convoluted #if condition
83 #if !defined(EIGEN_HAS_GPU_FP16) || !defined(EIGEN_GPU_COMPILE_PHASE)
84 // Make our own __half_raw definition that is similar to CUDA's.
85 struct __half_raw {
86 #if (defined(EIGEN_HAS_GPU_FP16) && !defined(EIGEN_GPU_COMPILE_PHASE))
87  // Eigen::half can be used as the datatype for shared memory declarations (in Eigen and TF)
88  // The element type for shared memory cannot have non-trivial constructors
89  // and hence the following special casing (which skips the zero-initilization).
90  // Note that this check gets done even in the host compilation phase, and
91  // hence the need for this
93 #else
95 #endif
96 #if defined(EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC)
97  explicit EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR __half_raw(numext::uint16_t raw) : x(numext::bit_cast<__fp16>(raw)) {}
98  __fp16 x;
99 #else
102 #endif
103 };
104 
105 #elif defined(EIGEN_HAS_HIP_FP16)
106 // Nothing to do here
107 // HIP fp16 header file has a definition for __half_raw
108 #elif defined(EIGEN_HAS_CUDA_FP16)
109 #if EIGEN_CUDA_SDK_VER < 90000
110 // In CUDA < 9.0, __half is the equivalent of CUDA 9's __half_raw
111 typedef __half __half_raw;
112 #endif // defined(EIGEN_HAS_CUDA_FP16)
113 #elif defined(SYCL_DEVICE_ONLY)
114 typedef cl::sycl::half __half_raw;
115 #endif
116 
120 
121 struct half_base : public __half_raw {
124 
125 #if defined(EIGEN_HAS_GPU_FP16)
126 #if defined(EIGEN_HAS_HIP_FP16)
127  EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR half_base(const __half& h) { x = __half_as_ushort(h); }
128 #elif defined(EIGEN_HAS_CUDA_FP16)
129 #if EIGEN_CUDA_SDK_VER >= 90000
131 #endif
132 #endif
133 #endif
134 };
135 
136 } // namespace half_impl
137 
138 // Class definition.
139 struct half : public half_impl::half_base {
140  // Writing this out as separate #if-else blocks to make the code easier to follow
141  // The same applies to most #if-else blocks in this file
142 #if !defined(EIGEN_HAS_GPU_FP16) || !defined(EIGEN_GPU_COMPILE_PHASE)
143  // Use the same base class for the following two scenarios
144  // * when compiling without GPU support enabled
145  // * during host compile phase when compiling with GPU support enabled
147 #elif defined(EIGEN_HAS_HIP_FP16)
148  // Nothing to do here
149  // HIP fp16 header file has a definition for __half_raw
150 #elif defined(EIGEN_HAS_CUDA_FP16)
151 // Note that EIGEN_CUDA_SDK_VER is set to 0 even when compiling with HIP, so
152 // (EIGEN_CUDA_SDK_VER < 90000) is true even for HIP! So keeping this within
153 // #if defined(EIGEN_HAS_CUDA_FP16) is needed
154 #if defined(EIGEN_CUDA_SDK_VER) && EIGEN_CUDA_SDK_VER < 90000
156 #endif
157 #endif
158 
160 
162 
163 #if defined(EIGEN_HAS_GPU_FP16)
164 #if defined(EIGEN_HAS_HIP_FP16)
165  EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR half(const __half& h) : half_impl::half_base(h) {}
166 #elif defined(EIGEN_HAS_CUDA_FP16)
167 #if defined(EIGEN_CUDA_SDK_VER) && EIGEN_CUDA_SDK_VER >= 90000
168  EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR half(const __half& h) : half_impl::half_base(h) {}
169 #endif
170 #endif
171 #endif
172 
174  : half_impl::half_base(half_impl::raw_uint16_to_half(b ? 0x3c00 : 0)) {}
175  template <class T>
177  : half_impl::half_base(half_impl::float_to_half_rtne(static_cast<float>(val))) {}
178  explicit EIGEN_DEVICE_FUNC half(float f) : half_impl::half_base(half_impl::float_to_half_rtne(f)) {}
179 
180  // Following the convention of numpy, converting between complex and
181  // float will lead to loss of imag value.
182  template <typename RealScalar>
183  explicit EIGEN_DEVICE_FUNC half(std::complex<RealScalar> c)
184  : half_impl::half_base(half_impl::float_to_half_rtne(static_cast<float>(c.real()))) {}
185 
186  EIGEN_DEVICE_FUNC operator float() const { // NOLINT: Allow implicit conversion to float, because it is lossless.
187  return half_impl::half_to_float(*this);
188  }
189 
190 #if defined(EIGEN_HAS_GPU_FP16) && !defined(EIGEN_GPU_COMPILE_PHASE)
191  EIGEN_DEVICE_FUNC operator __half() const {
192  ::__half_raw hr;
193  hr.x = x;
194  return __half(hr);
195  }
196 #endif
197 };
198 
199 // TODO(majnemer): Get rid of this once we can rely on C++17 inline variables do
200 // solve the ODR issue.
201 namespace half_impl {
202 template <typename = void>
204  static EIGEN_CONSTEXPR const bool is_specialized = true;
205  static EIGEN_CONSTEXPR const bool is_signed = true;
206  static EIGEN_CONSTEXPR const bool is_integer = false;
207  static EIGEN_CONSTEXPR const bool is_exact = false;
208  static EIGEN_CONSTEXPR const bool has_infinity = true;
209  static EIGEN_CONSTEXPR const bool has_quiet_NaN = true;
210  static EIGEN_CONSTEXPR const bool has_signaling_NaN = true;
211  EIGEN_DIAGNOSTICS(push)
213  static EIGEN_CONSTEXPR const std::float_denorm_style has_denorm = std::denorm_present;
214  static EIGEN_CONSTEXPR const bool has_denorm_loss = false;
215  EIGEN_DIAGNOSTICS(pop)
216  static EIGEN_CONSTEXPR const std::float_round_style round_style = std::round_to_nearest;
217  static EIGEN_CONSTEXPR const bool is_iec559 = true;
218  // The C++ standard defines this as "true if the set of values representable
219  // by the type is finite." Half has finite precision.
220  static EIGEN_CONSTEXPR const bool is_bounded = true;
221  static EIGEN_CONSTEXPR const bool is_modulo = false;
222  static EIGEN_CONSTEXPR const int digits = 11;
223  static EIGEN_CONSTEXPR const int digits10 =
224  3; // according to http://half.sourceforge.net/structstd_1_1numeric__limits_3_01half__float_1_1half_01_4.html
225  static EIGEN_CONSTEXPR const int max_digits10 =
226  5; // according to http://half.sourceforge.net/structstd_1_1numeric__limits_3_01half__float_1_1half_01_4.html
227  static EIGEN_CONSTEXPR const int radix = std::numeric_limits<float>::radix;
228  static EIGEN_CONSTEXPR const int min_exponent = -13;
229  static EIGEN_CONSTEXPR const int min_exponent10 = -4;
230  static EIGEN_CONSTEXPR const int max_exponent = 16;
231  static EIGEN_CONSTEXPR const int max_exponent10 = 4;
232  static EIGEN_CONSTEXPR const bool traps = std::numeric_limits<float>::traps;
233  // IEEE754: "The implementer shall choose how tininess is detected, but shall
234  // detect tininess in the same way for all operations in radix two"
235  static EIGEN_CONSTEXPR const bool tinyness_before = std::numeric_limits<float>::tinyness_before;
236 
246 };
247 
248 template <typename T>
250 template <typename T>
252 template <typename T>
254 template <typename T>
256 template <typename T>
258 template <typename T>
260 template <typename T>
262 EIGEN_DIAGNOSTICS(push)
264 template <typename T>
265 EIGEN_CONSTEXPR const std::float_denorm_style numeric_limits_half_impl<T>::has_denorm;
266 template <typename T>
269 template <typename T>
270 EIGEN_CONSTEXPR const std::float_round_style numeric_limits_half_impl<T>::round_style;
271 template <typename T>
273 template <typename T>
275 template <typename T>
277 template <typename T>
279 template <typename T>
281 template <typename T>
283 template <typename T>
285 template <typename T>
287 template <typename T>
289 template <typename T>
291 template <typename T>
293 template <typename T>
295 template <typename T>
297 } // end namespace half_impl
298 } // end namespace Eigen
299 
300 namespace std {
301 // If std::numeric_limits<T> is specialized, should also specialize
302 // std::numeric_limits<const T>, std::numeric_limits<volatile T>, and
303 // std::numeric_limits<const volatile T>
304 // https://stackoverflow.com/a/16519653/
305 template <>
306 class numeric_limits<Eigen::half> : public Eigen::half_impl::numeric_limits_half_impl<> {};
307 template <>
308 class numeric_limits<const Eigen::half> : public numeric_limits<Eigen::half> {};
309 template <>
310 class numeric_limits<volatile Eigen::half> : public numeric_limits<Eigen::half> {};
311 template <>
312 class numeric_limits<const volatile Eigen::half> : public numeric_limits<Eigen::half> {};
313 } // end namespace std
314 
315 namespace Eigen {
316 
317 namespace half_impl {
318 
319 #if (defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 530) || \
320  (defined(EIGEN_HAS_HIP_FP16) && defined(HIP_DEVICE_COMPILE))
321 // Note: We deliberately do *not* define this to 1 even if we have Arm's native
322 // fp16 type since GPU half types are rather different from native CPU half types.
323 // TODO: Rename to something like EIGEN_HAS_NATIVE_GPU_FP16
324 #define EIGEN_HAS_NATIVE_FP16
325 #endif
326 
327 // Intrinsics for native fp16 support. Note that on current hardware,
328 // these are no faster than fp32 arithmetic (you need to use the half2
329 // versions to get the ALU speed increased), but you do save the
330 // conversion steps back and forth.
331 
332 #if defined(EIGEN_HAS_NATIVE_FP16)
333 EIGEN_STRONG_INLINE __device__ half operator+(const half& a, const half& b) {
334 #if defined(EIGEN_CUDA_SDK_VER) && EIGEN_CUDA_SDK_VER >= 90000
335  return __hadd(::__half(a), ::__half(b));
336 #else
337  return __hadd(a, b);
338 #endif
339 }
340 EIGEN_STRONG_INLINE __device__ half operator*(const half& a, const half& b) { return __hmul(a, b); }
341 EIGEN_STRONG_INLINE __device__ half operator-(const half& a, const half& b) { return __hsub(a, b); }
342 EIGEN_STRONG_INLINE __device__ half operator/(const half& a, const half& b) {
343 #if defined(EIGEN_CUDA_SDK_VER) && EIGEN_CUDA_SDK_VER >= 90000
344  return __hdiv(a, b);
345 #else
346  float num = __half2float(a);
347  float denom = __half2float(b);
348  return __float2half(num / denom);
349 #endif
350 }
351 EIGEN_STRONG_INLINE __device__ half operator-(const half& a) { return __hneg(a); }
352 EIGEN_STRONG_INLINE __device__ half& operator+=(half& a, const half& b) {
353  a = a + b;
354  return a;
355 }
356 EIGEN_STRONG_INLINE __device__ half& operator*=(half& a, const half& b) {
357  a = a * b;
358  return a;
359 }
360 EIGEN_STRONG_INLINE __device__ half& operator-=(half& a, const half& b) {
361  a = a - b;
362  return a;
363 }
364 EIGEN_STRONG_INLINE __device__ half& operator/=(half& a, const half& b) {
365  a = a / b;
366  return a;
367 }
368 EIGEN_STRONG_INLINE __device__ bool operator==(const half& a, const half& b) { return __heq(a, b); }
369 EIGEN_STRONG_INLINE __device__ bool operator!=(const half& a, const half& b) { return __hne(a, b); }
370 EIGEN_STRONG_INLINE __device__ bool operator<(const half& a, const half& b) { return __hlt(a, b); }
371 EIGEN_STRONG_INLINE __device__ bool operator<=(const half& a, const half& b) { return __hle(a, b); }
372 EIGEN_STRONG_INLINE __device__ bool operator>(const half& a, const half& b) { return __hgt(a, b); }
373 EIGEN_STRONG_INLINE __device__ bool operator>=(const half& a, const half& b) { return __hge(a, b); }
374 #endif
375 
376 #if defined(EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC) && !defined(EIGEN_GPU_COMPILE_PHASE)
377 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator+(const half& a, const half& b) { return half(vaddh_f16(a.x, b.x)); }
378 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator*(const half& a, const half& b) { return half(vmulh_f16(a.x, b.x)); }
379 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator-(const half& a, const half& b) { return half(vsubh_f16(a.x, b.x)); }
380 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator/(const half& a, const half& b) { return half(vdivh_f16(a.x, b.x)); }
381 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator-(const half& a) { return half(vnegh_f16(a.x)); }
382 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half& operator+=(half& a, const half& b) {
383  a = half(vaddh_f16(a.x, b.x));
384  return a;
385 }
386 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half& operator*=(half& a, const half& b) {
387  a = half(vmulh_f16(a.x, b.x));
388  return a;
389 }
390 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half& operator-=(half& a, const half& b) {
391  a = half(vsubh_f16(a.x, b.x));
392  return a;
393 }
394 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half& operator/=(half& a, const half& b) {
395  a = half(vdivh_f16(a.x, b.x));
396  return a;
397 }
398 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator==(const half& a, const half& b) { return vceqh_f16(a.x, b.x); }
399 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator!=(const half& a, const half& b) { return !vceqh_f16(a.x, b.x); }
400 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator<(const half& a, const half& b) { return vclth_f16(a.x, b.x); }
401 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator<=(const half& a, const half& b) { return vcleh_f16(a.x, b.x); }
402 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator>(const half& a, const half& b) { return vcgth_f16(a.x, b.x); }
403 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator>=(const half& a, const half& b) { return vcgeh_f16(a.x, b.x); }
404 // We need to distinguish ‘clang as the CUDA compiler’ from ‘clang as the host compiler,
405 // invoked by NVCC’ (e.g. on MacOS). The former needs to see both host and device implementation
406 // of the functions, while the latter can only deal with one of them.
407 #elif !defined(EIGEN_HAS_NATIVE_FP16) || (EIGEN_COMP_CLANG && !EIGEN_COMP_NVCC) // Emulate support for half floats
408 
409 #if EIGEN_COMP_CLANG && defined(EIGEN_GPUCC)
410 // We need to provide emulated *host-side* FP16 operators for clang.
411 #pragma push_macro("EIGEN_DEVICE_FUNC")
412 #undef EIGEN_DEVICE_FUNC
413 #if defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_HAS_NATIVE_FP16)
414 #define EIGEN_DEVICE_FUNC __host__
415 #else // both host and device need emulated ops.
416 #define EIGEN_DEVICE_FUNC __host__ __device__
417 #endif
418 #endif
419 
420 // Definitions for CPUs and older HIP+CUDA, mostly working through conversion
421 // to/from fp32.
422 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator+(const half& a, const half& b) { return half(float(a) + float(b)); }
423 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator*(const half& a, const half& b) { return half(float(a) * float(b)); }
424 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator-(const half& a, const half& b) { return half(float(a) - float(b)); }
425 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator/(const half& a, const half& b) { return half(float(a) / float(b)); }
427  half result;
428  result.x = a.x ^ 0x8000;
429  return result;
430 }
432  a = half(float(a) + float(b));
433  return a;
434 }
436  a = half(float(a) * float(b));
437  return a;
438 }
440  a = half(float(a) - float(b));
441  return a;
442 }
444  a = half(float(a) / float(b));
445  return a;
446 }
448  return numext::equal_strict(float(a), float(b));
449 }
451  return numext::not_equal_strict(float(a), float(b));
452 }
453 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator<(const half& a, const half& b) { return float(a) < float(b); }
454 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator<=(const half& a, const half& b) { return float(a) <= float(b); }
455 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator>(const half& a, const half& b) { return float(a) > float(b); }
456 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator>=(const half& a, const half& b) { return float(a) >= float(b); }
457 
458 #if EIGEN_COMP_CLANG && defined(EIGEN_GPUCC)
459 #pragma pop_macro("EIGEN_DEVICE_FUNC")
460 #endif
461 #endif // Emulate support for half floats
462 
463 // Division by an index. Do it in full float precision to avoid accuracy
464 // issues in converting the denominator to half.
466  return half(static_cast<float>(a) / static_cast<float>(b));
467 }
468 
470  a += half(1);
471  return a;
472 }
473 
475  a -= half(1);
476  return a;
477 }
478 
480  half original_value = a;
481  ++a;
482  return original_value;
483 }
484 
486  half original_value = a;
487  --a;
488  return original_value;
489 }
490 
491 // Conversion routines, including fallbacks for the host or older CUDA.
492 // Note that newer Intel CPUs (Haswell or newer) have vectorized versions of
493 // these in hardware. If we need more performance on older/other CPUs, they are
494 // also possible to vectorize directly.
495 
497  // We cannot simply do a "return __half_raw(x)" here, because __half_raw is union type
498  // in the hip_fp16 header file, and that will trigger a compile error
499  // On the other hand, having anything but a return statement also triggers a compile error
500  // because this is constexpr function.
501  // Fortunately, since we need to disable EIGEN_CONSTEXPR for GPU anyway, we can get out
502  // of this catch22 by having separate bodies for GPU / non GPU
503 #if defined(EIGEN_HAS_GPU_FP16)
504  __half_raw h;
505  h.x = x;
506  return h;
507 #else
508  return __half_raw(x);
509 #endif
510 }
511 
513  // HIP/CUDA/Default have a member 'x' of type uint16_t.
514  // For ARM64 native half, the member 'x' is of type __fp16, so we need to bit-cast.
515  // For SYCL, cl::sycl::half is _Float16, so cast directly.
516 #if defined(EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC)
517  return numext::bit_cast<numext::uint16_t>(h.x);
518 #elif defined(SYCL_DEVICE_ONLY)
519  return numext::bit_cast<numext::uint16_t>(h);
520 #else
521  return h.x;
522 #endif
523 }
524 
526  unsigned int u;
527  float f;
528 };
529 
531 #if (defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 300) || \
532  (defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIP_DEVICE_COMPILE))
533  __half tmp_ff = __float2half(ff);
534  return *(__half_raw*)&tmp_ff;
535 
536 #elif defined(EIGEN_HAS_FP16_C)
537  __half_raw h;
538 #if EIGEN_COMP_MSVC
539  // MSVC does not have scalar instructions.
540  h.x = _mm_extract_epi16(_mm_cvtps_ph(_mm_set_ss(ff), 0), 0);
541 #else
542  h.x = _cvtss_sh(ff, 0);
543 #endif
544  return h;
545 
546 #elif defined(EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC)
547  __half_raw h;
548  h.x = static_cast<__fp16>(ff);
549  return h;
550 
551 #else
552  float32_bits f;
553  f.f = ff;
554 
555  const float32_bits f32infty = {255 << 23};
556  const float32_bits f16max = {(127 + 16) << 23};
557  const float32_bits denorm_magic = {((127 - 15) + (23 - 10) + 1) << 23};
558  unsigned int sign_mask = 0x80000000u;
559  __half_raw o;
560  o.x = static_cast<numext::uint16_t>(0x0u);
561 
562  unsigned int sign = f.u & sign_mask;
563  f.u ^= sign;
564 
565  // NOTE all the integer compares in this function can be safely
566  // compiled into signed compares since all operands are below
567  // 0x80000000. Important if you want fast straight SSE2 code
568  // (since there's no unsigned PCMPGTD).
569 
570  if (f.u >= f16max.u) { // result is Inf or NaN (all exponent bits set)
571  o.x = (f.u > f32infty.u) ? 0x7e00 : 0x7c00; // NaN->qNaN and Inf->Inf
572  } else { // (De)normalized number or zero
573  if (f.u < (113 << 23)) { // resulting FP16 is subnormal or zero
574  // use a magic value to align our 10 mantissa bits at the bottom of
575  // the float. as long as FP addition is round-to-nearest-even this
576  // just works.
577  f.f += denorm_magic.f;
578 
579  // and one integer subtract of the bias later, we have our final float!
580  o.x = static_cast<numext::uint16_t>(f.u - denorm_magic.u);
581  } else {
582  unsigned int mant_odd = (f.u >> 13) & 1; // resulting mantissa is odd
583 
584  // update exponent, rounding bias part 1
585  // Equivalent to `f.u += ((unsigned int)(15 - 127) << 23) + 0xfff`, but
586  // without arithmetic overflow.
587  f.u += 0xc8000fffU;
588  // rounding bias part 2
589  f.u += mant_odd;
590  // take the bits!
591  o.x = static_cast<numext::uint16_t>(f.u >> 13);
592  }
593  }
594 
595  o.x |= static_cast<numext::uint16_t>(sign >> 16);
596  return o;
597 #endif
598 }
599 
601 #if (defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 300) || \
602  (defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIP_DEVICE_COMPILE))
603  return __half2float(h);
604 #elif defined(EIGEN_HAS_FP16_C)
605 #if EIGEN_COMP_MSVC
606  // MSVC does not have scalar instructions.
607  return _mm_cvtss_f32(_mm_cvtph_ps(_mm_set1_epi16(h.x)));
608 #else
609  return _cvtsh_ss(h.x);
610 #endif
611 #elif defined(EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC)
612  return static_cast<float>(h.x);
613 #else
614  const float32_bits magic = {113 << 23};
615  const unsigned int shifted_exp = 0x7c00 << 13; // exponent mask after shift
616  float32_bits o;
617 
618  o.u = (h.x & 0x7fff) << 13; // exponent/mantissa bits
619  unsigned int exp = shifted_exp & o.u; // just the exponent
620  o.u += (127 - 15) << 23; // exponent adjust
621 
622  // handle exponent special cases
623  if (exp == shifted_exp) { // Inf/NaN?
624  o.u += (128 - 16) << 23; // extra exp adjust
625  } else if (exp == 0) { // Zero/Denormal?
626  o.u += 1 << 23; // extra exp adjust
627  o.f -= magic.f; // renormalize
628  }
629 
630  o.u |= (h.x & 0x8000) << 16; // sign bit
631  return o.f;
632 #endif
633 }
634 
635 // --- standard functions ---
636 
638 #ifdef EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC
639  return (numext::bit_cast<numext::uint16_t>(a.x) & 0x7fff) == 0x7c00;
640 #else
641  return (a.x & 0x7fff) == 0x7c00;
642 #endif
643 }
645 #if (defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 530) || \
646  (defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIP_DEVICE_COMPILE))
647  return __hisnan(a);
648 #elif defined(EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC)
649  return (numext::bit_cast<numext::uint16_t>(a.x) & 0x7fff) > 0x7c00;
650 #else
651  return (a.x & 0x7fff) > 0x7c00;
652 #endif
653 }
655  return !(isinf EIGEN_NOT_A_MACRO(a)) && !(isnan EIGEN_NOT_A_MACRO(a));
656 }
657 
659 #if defined(EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC)
660  return half(vabsh_f16(a.x));
661 #else
662  half result;
663  result.x = a.x & 0x7FFF;
664  return result;
665 #endif
666 }
668 #if (EIGEN_CUDA_SDK_VER >= 80000 && defined EIGEN_CUDA_ARCH && EIGEN_CUDA_ARCH >= 530) || \
669  defined(EIGEN_HIP_DEVICE_COMPILE)
670  return half(hexp(a));
671 #else
672  return half(::expf(float(a)));
673 #endif
674 }
676 #if (EIGEN_CUDA_SDK_VER >= 80000 && defined EIGEN_CUDA_ARCH && EIGEN_CUDA_ARCH >= 530) || \
677  defined(EIGEN_HIP_DEVICE_COMPILE)
678  return half(hexp2(a));
679 #else
680  return half(::exp2f(float(a)));
681 #endif
682 }
685 #if (defined(EIGEN_HAS_CUDA_FP16) && EIGEN_CUDA_SDK_VER >= 80000 && defined(EIGEN_CUDA_ARCH) && \
686  EIGEN_CUDA_ARCH >= 530) || \
687  (defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIP_DEVICE_COMPILE))
688  return half(hlog(a));
689 #else
690  return half(::logf(float(a)));
691 #endif
692 }
694 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half log10(const half& a) { return half(::log10f(float(a))); }
696  return half(static_cast<float>(EIGEN_LOG2E) * ::logf(float(a)));
697 }
698 
700 #if (EIGEN_CUDA_SDK_VER >= 80000 && defined EIGEN_CUDA_ARCH && EIGEN_CUDA_ARCH >= 530) || \
701  defined(EIGEN_HIP_DEVICE_COMPILE)
702  return half(hsqrt(a));
703 #else
704  return half(::sqrtf(float(a)));
705 #endif
706 }
708  return half(::powf(float(a), float(b)));
709 }
711  return half(::atan2f(float(a), float(b)));
712 }
713 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half sin(const half& a) { return half(::sinf(float(a))); }
714 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half cos(const half& a) { return half(::cosf(float(a))); }
715 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half tan(const half& a) { return half(::tanf(float(a))); }
716 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half tanh(const half& a) { return half(::tanhf(float(a))); }
717 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half asin(const half& a) { return half(::asinf(float(a))); }
718 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half acos(const half& a) { return half(::acosf(float(a))); }
719 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half atan(const half& a) { return half(::atanf(float(a))); }
720 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half atanh(const half& a) { return half(::atanhf(float(a))); }
722 #if (EIGEN_CUDA_SDK_VER >= 80000 && defined EIGEN_CUDA_ARCH && EIGEN_CUDA_ARCH >= 300) || \
723  defined(EIGEN_HIP_DEVICE_COMPILE)
724  return half(hfloor(a));
725 #else
726  return half(::floorf(float(a)));
727 #endif
728 }
730 #if (EIGEN_CUDA_SDK_VER >= 80000 && defined EIGEN_CUDA_ARCH && EIGEN_CUDA_ARCH >= 300) || \
731  defined(EIGEN_HIP_DEVICE_COMPILE)
732  return half(hceil(a));
733 #else
734  return half(::ceilf(float(a)));
735 #endif
736 }
737 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half rint(const half& a) { return half(::rintf(float(a))); }
738 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half round(const half& a) { return half(::roundf(float(a))); }
739 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half trunc(const half& a) { return half(::truncf(float(a))); }
741  return half(::fmodf(float(a), float(b)));
742 }
743 
745 #if (defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 530) || \
746  (defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIP_DEVICE_COMPILE))
747  return __hlt(b, a) ? b : a;
748 #else
749  const float f1 = static_cast<float>(a);
750  const float f2 = static_cast<float>(b);
751  return f2 < f1 ? b : a;
752 #endif
753 }
755 #if (defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 530) || \
756  (defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIP_DEVICE_COMPILE))
757  return __hlt(a, b) ? b : a;
758 #else
759  const float f1 = static_cast<float>(a);
760  const float f2 = static_cast<float>(b);
761  return f1 < f2 ? b : a;
762 #endif
763 }
764 
765 #ifndef EIGEN_NO_IO
766 EIGEN_ALWAYS_INLINE std::ostream& operator<<(std::ostream& os, const half& v) {
767  os << static_cast<float>(v);
768  return os;
769 }
770 #endif
771 
772 } // end namespace half_impl
773 
774 // import Eigen::half_impl::half into Eigen namespace
775 // using half_impl::half;
776 
777 namespace internal {
778 
779 template <>
781  enum { value = true };
782 };
783 
784 template <>
785 struct random_impl<half> {
786  enum : int { MantissaBits = 10 };
788  static EIGEN_DEVICE_FUNC inline half run(const half& x, const half& y) {
789  float result = Impl::run(x, y, MantissaBits);
790  return half(result);
791  }
792  static EIGEN_DEVICE_FUNC inline half run() {
793  float result = Impl::run(MantissaBits);
794  return half(result);
795  }
796 };
797 
798 } // end namespace internal
799 
800 template <>
801 struct NumTraits<Eigen::half> : GenericNumTraits<Eigen::half> {
802  enum { IsSigned = true, IsInteger = false, IsComplex = false, RequireInitialization = false };
803 
805  return half_impl::raw_uint16_to_half(0x0800);
806  }
808  return half_impl::raw_uint16_to_half(0x211f); // Eigen::half(1e-2f);
809  }
811  return half_impl::raw_uint16_to_half(0x7bff);
812  }
814  return half_impl::raw_uint16_to_half(0xfbff);
815  }
817  return half_impl::raw_uint16_to_half(0x7c00);
818  }
820  return half_impl::raw_uint16_to_half(0x7e00);
821  }
822 };
823 
824 } // end namespace Eigen
825 
826 #if defined(EIGEN_HAS_GPU_FP16) || defined(EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC)
827 #pragma pop_macro("EIGEN_CONSTEXPR")
828 #endif
829 
830 namespace Eigen {
831 namespace numext {
832 
833 #if defined(EIGEN_GPU_COMPILE_PHASE)
834 
835 template <>
837  return (half_impl::isnan)(h);
838 }
839 
840 template <>
842  return (half_impl::isinf)(h);
843 }
844 
845 template <>
847  return (half_impl::isfinite)(h);
848 }
849 
850 #endif
851 
852 template <>
853 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half bit_cast<Eigen::half, uint16_t>(const uint16_t& src) {
855 }
856 
857 template <>
858 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC uint16_t bit_cast<uint16_t, Eigen::half>(const Eigen::half& src) {
860 }
861 
862 } // namespace numext
863 } // namespace Eigen
864 
865 // Add the missing shfl* intrinsics.
866 // The __shfl* functions are only valid on HIP or _CUDA_ARCH_ >= 300.
867 // CUDA defines them for (__CUDA_ARCH__ >= 300 || !defined(__CUDA_ARCH__))
868 //
869 // HIP and CUDA prior to SDK 9.0 define
870 // __shfl, __shfl_up, __shfl_down, __shfl_xor for int and float
871 // CUDA since 9.0 deprecates those and instead defines
872 // __shfl_sync, __shfl_up_sync, __shfl_down_sync, __shfl_xor_sync,
873 // with native support for __half and __nv_bfloat16
874 //
875 // Note that the following are __device__ - only functions.
876 #if (defined(EIGEN_CUDACC) && (!defined(EIGEN_CUDA_ARCH) || EIGEN_CUDA_ARCH >= 300)) || defined(EIGEN_HIPCC)
877 
878 #if defined(EIGEN_HAS_CUDA_FP16) && EIGEN_CUDA_SDK_VER >= 90000
879 
880 __device__ EIGEN_STRONG_INLINE Eigen::half __shfl_sync(unsigned mask, Eigen::half var, int srcLane,
881  int width = warpSize) {
882  const __half h = var;
883  return static_cast<Eigen::half>(__shfl_sync(mask, h, srcLane, width));
884 }
885 
886 __device__ EIGEN_STRONG_INLINE Eigen::half __shfl_up_sync(unsigned mask, Eigen::half var, unsigned int delta,
887  int width = warpSize) {
888  const __half h = var;
889  return static_cast<Eigen::half>(__shfl_up_sync(mask, h, delta, width));
890 }
891 
892 __device__ EIGEN_STRONG_INLINE Eigen::half __shfl_down_sync(unsigned mask, Eigen::half var, unsigned int delta,
893  int width = warpSize) {
894  const __half h = var;
895  return static_cast<Eigen::half>(__shfl_down_sync(mask, h, delta, width));
896 }
897 
898 __device__ EIGEN_STRONG_INLINE Eigen::half __shfl_xor_sync(unsigned mask, Eigen::half var, int laneMask,
899  int width = warpSize) {
900  const __half h = var;
901  return static_cast<Eigen::half>(__shfl_xor_sync(mask, h, laneMask, width));
902 }
903 
904 #else // HIP or CUDA SDK < 9.0
905 
906 __device__ EIGEN_STRONG_INLINE Eigen::half __shfl(Eigen::half var, int srcLane, int width = warpSize) {
907  const int ivar = static_cast<int>(Eigen::numext::bit_cast<Eigen::numext::uint16_t>(var));
908  return Eigen::numext::bit_cast<Eigen::half>(static_cast<Eigen::numext::uint16_t>(__shfl(ivar, srcLane, width)));
909 }
910 
911 __device__ EIGEN_STRONG_INLINE Eigen::half __shfl_up(Eigen::half var, unsigned int delta, int width = warpSize) {
912  const int ivar = static_cast<int>(Eigen::numext::bit_cast<Eigen::numext::uint16_t>(var));
913  return Eigen::numext::bit_cast<Eigen::half>(static_cast<Eigen::numext::uint16_t>(__shfl_up(ivar, delta, width)));
914 }
915 
916 __device__ EIGEN_STRONG_INLINE Eigen::half __shfl_down(Eigen::half var, unsigned int delta, int width = warpSize) {
917  const int ivar = static_cast<int>(Eigen::numext::bit_cast<Eigen::numext::uint16_t>(var));
918  return Eigen::numext::bit_cast<Eigen::half>(static_cast<Eigen::numext::uint16_t>(__shfl_down(ivar, delta, width)));
919 }
920 
921 __device__ EIGEN_STRONG_INLINE Eigen::half __shfl_xor(Eigen::half var, int laneMask, int width = warpSize) {
922  const int ivar = static_cast<int>(Eigen::numext::bit_cast<Eigen::numext::uint16_t>(var));
923  return Eigen::numext::bit_cast<Eigen::half>(static_cast<Eigen::numext::uint16_t>(__shfl_xor(ivar, laneMask, width)));
924 }
925 
926 #endif // HIP vs CUDA
927 #endif // __shfl*
928 
929 // ldg() has an overload for __half_raw, but we also need one for Eigen::half.
930 #if (defined(EIGEN_CUDACC) && (!defined(EIGEN_CUDA_ARCH) || EIGEN_CUDA_ARCH >= 350)) || defined(EIGEN_HIPCC)
931 EIGEN_STRONG_INLINE __device__ Eigen::half __ldg(const Eigen::half* ptr) {
932  return Eigen::half_impl::raw_uint16_to_half(__ldg(reinterpret_cast<const Eigen::numext::uint16_t*>(ptr)));
933 }
934 #endif // __ldg
935 
936 #if EIGEN_HAS_STD_HASH
937 namespace std {
938 template <>
939 struct hash<Eigen::half> {
940  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::size_t operator()(const Eigen::half& a) const {
941  return static_cast<std::size_t>(Eigen::numext::bit_cast<Eigen::numext::uint16_t>(a));
942  }
943 };
944 } // end namespace std
945 #endif
946 
947 namespace Eigen {
948 namespace internal {
949 
950 template <>
951 struct cast_impl<float, half> {
952  EIGEN_DEVICE_FUNC static inline half run(const float& a) {
953 #if (defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 300) || \
954  (defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIP_DEVICE_COMPILE))
955  return __float2half(a);
956 #else
957  return half(a);
958 #endif
959  }
960 };
961 
962 template <>
963 struct cast_impl<int, half> {
964  EIGEN_DEVICE_FUNC static inline half run(const int& a) {
965 #if (defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 300) || \
966  (defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIP_DEVICE_COMPILE))
967  return __float2half(static_cast<float>(a));
968 #else
969  return half(static_cast<float>(a));
970 #endif
971  }
972 };
973 
974 template <>
975 struct cast_impl<half, float> {
976  EIGEN_DEVICE_FUNC static inline float run(const half& a) {
977 #if (defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 300) || \
978  (defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIP_DEVICE_COMPILE))
979  return __half2float(a);
980 #else
981  return static_cast<float>(a);
982 #endif
983  }
984 };
985 
986 } // namespace internal
987 } // namespace Eigen
988 
989 #endif // EIGEN_HALF_H
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
#define EIGEN_ALWAYS_INLINE
Definition: Macros.h:845
#define EIGEN_DISABLE_DEPRECATED_WARNING
Definition: Macros.h:957
#define EIGEN_CONSTEXPR
Definition: Macros.h:758
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:892
#define EIGEN_NOT_A_MACRO
Definition: Macros.h:813
#define EIGEN_DIAGNOSTICS(tokens)
Definition: Macros.h:953
#define EIGEN_STRONG_INLINE
Definition: Macros.h:834
#define EIGEN_LOG2E
Definition: MathFunctions.h:17
Scalar * b
Definition: benchVecAdd.cpp:17
static int f(const TensorMap< Tensor< int, 3 > > &tensor)
Definition: cxx11_tensor_map.cpp:237
return int(ret)+1
const Scalar * a
Definition: level2_cplx_impl.h:32
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half abs(const half &a)
Definition: Half.h:658
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator--(half &a)
Definition: Half.h:474
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half log10(const half &a)
Definition: Half.h:694
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half rint(const half &a)
Definition: Half.h:737
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half atan(const half &a)
Definition: Half.h:719
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator==(const half &a, const half &b)
Definition: Half.h:447
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half tan(const half &a)
Definition: Half.h:715
EIGEN_ALWAYS_INLINE std::ostream & operator<<(std::ostream &os, const half &v)
Definition: Half.h:766
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half ceil(const half &a)
Definition: Half.h:729
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half & operator-=(half &a, const half &b)
Definition: Half.h:439
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half atanh(const half &a)
Definition: Half.h:720
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half log1p(const half &a)
Definition: Half.h:693
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool() isnan(const half &a)
Definition: Half.h:644
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half cos(const half &a)
Definition: Half.h:714
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator>=(const half &a, const half &b)
Definition: Half.h:456
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half exp2(const half &a)
Definition: Half.h:675
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half() min(const half &a, const half &b)
Definition: Half.h:744
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half asin(const half &a)
Definition: Half.h:717
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool() isfinite(const half &a)
Definition: Half.h:654
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC float half_to_float(__half_raw h)
Definition: Half.h:600
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half tanh(const half &a)
Definition: Half.h:716
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half & operator*=(half &a, const half &b)
Definition: Half.h:435
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator*(const half &a, const half &b)
Definition: Half.h:423
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half atan2(const half &a, const half &b)
Definition: Half.h:710
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half acos(const half &a)
Definition: Half.h:718
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half pow(const half &a, const half &b)
Definition: Half.h:707
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half trunc(const half &a)
Definition: Half.h:739
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half fmod(const half &a, const half &b)
Definition: Half.h:740
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half sqrt(const half &a)
Definition: Half.h:699
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half() max(const half &a, const half &b)
Definition: Half.h:754
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator+(const half &a, const half &b)
Definition: Half.h:422
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator/(const half &a, const half &b)
Definition: Half.h:425
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half round(const half &a)
Definition: Half.h:738
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR __half_raw raw_uint16_to_half(numext::uint16_t x)
Definition: Half.h:496
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator-(const half &a, const half &b)
Definition: Half.h:424
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator++(half &a)
Definition: Half.h:469
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half floor(const half &a)
Definition: Half.h:721
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator<=(const half &a, const half &b)
Definition: Half.h:454
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half sin(const half &a)
Definition: Half.h:713
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC numext::uint16_t raw_half_as_uint16(const __half_raw &h)
Definition: Half.h:512
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half & operator+=(half &a, const half &b)
Definition: Half.h:431
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half & operator/=(half &a, const half &b)
Definition: Half.h:443
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half log(const half &a)
Definition: Half.h:684
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator>(const half &a, const half &b)
Definition: Half.h:455
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half log2(const half &a)
Definition: Half.h:695
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator!=(const half &a, const half &b)
Definition: Half.h:450
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half exp(const half &a)
Definition: Half.h:667
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC __half_raw float_to_half_rtne(float ff)
Definition: Half.h:530
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half expm1(const half &a)
Definition: Half.h:683
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool() isinf(const half &a)
Definition: Half.h:637
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator<(const half &a, const half &b)
Definition: Half.h:453
const Scalar & y
Definition: RandomImpl.h:36
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool() isinf(const Eigen::bfloat16 &h)
Definition: BFloat16.h:747
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool equal_strict(const X &x, const Y &y)
Definition: Meta.h:571
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool() isfinite(const Eigen::bfloat16 &h)
Definition: BFloat16.h:752
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool() isnan(const Eigen::bfloat16 &h)
Definition: BFloat16.h:742
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool not_equal_strict(const X &x, const Y &y)
Definition: Meta.h:606
std::uint16_t uint16_t
Definition: Meta.h:38
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Tgt bit_cast(const Src &src)
Definition: NumTraits.h:102
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
double f2(const Vector< double > &coord)
f2 function, in front of the C2 unknown
Definition: poisson/poisson_with_singularity/two_d_poisson.cc:233
double f1(const Vector< double > &coord)
f1 function, in front of the C1 unknown
Definition: poisson/poisson_with_singularity/two_d_poisson.cc:147
int delta
Definition: MultiOpt.py:96
T sign(T x)
Definition: cxx11_tensor_builtins_sycl.cpp:172
int c
Definition: calibrate.py:100
val
Definition: calibrate.py:119
Definition: Eigen_Colamd.h:49
list x
Definition: plotDoE.py:28
Definition: NumTraits.h:172
@ RequireInitialization
Definition: NumTraits.h:177
@ IsSigned
Definition: NumTraits.h:175
@ IsInteger
Definition: NumTraits.h:174
@ IsComplex
Definition: NumTraits.h:176
EIGEN_DEVICE_FUNC static EIGEN_CONSTEXPR EIGEN_STRONG_INLINE Eigen::half epsilon()
Definition: Half.h:804
EIGEN_DEVICE_FUNC static EIGEN_CONSTEXPR EIGEN_STRONG_INLINE Eigen::half infinity()
Definition: Half.h:816
EIGEN_DEVICE_FUNC static EIGEN_CONSTEXPR EIGEN_STRONG_INLINE Eigen::half highest()
Definition: Half.h:810
EIGEN_DEVICE_FUNC static EIGEN_CONSTEXPR EIGEN_STRONG_INLINE Eigen::half quiet_NaN()
Definition: Half.h:819
EIGEN_DEVICE_FUNC static EIGEN_CONSTEXPR EIGEN_STRONG_INLINE Eigen::half lowest()
Definition: Half.h:813
EIGEN_DEVICE_FUNC static EIGEN_CONSTEXPR EIGEN_STRONG_INLINE Eigen::half dummy_precision()
Definition: Half.h:807
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:217
Definition: Half.h:85
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR __half_raw(numext::uint16_t raw)
Definition: Half.h:100
numext::uint16_t x
Definition: Half.h:101
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR __half_raw()
Definition: Half.h:94
Definition: Half.h:121
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR half_base(const __half_raw &h)
Definition: Half.h:123
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR half_base()
Definition: Half.h:122
static EIGEN_CONSTEXPR const bool has_infinity
Definition: Half.h:208
static EIGEN_DISABLE_DEPRECATED_WARNING EIGEN_CONSTEXPR const std::float_denorm_style has_denorm
Definition: Half.h:213
static EIGEN_CONSTEXPR Eigen::half round_error()
Definition: Half.h:241
static EIGEN_CONSTEXPR const int radix
Definition: Half.h:227
static EIGEN_CONSTEXPR const int digits10
Definition: Half.h:223
static EIGEN_CONSTEXPR Eigen::half() min()
Definition: Half.h:237
static EIGEN_CONSTEXPR Eigen::half infinity()
Definition: Half.h:242
static EIGEN_CONSTEXPR const int min_exponent
Definition: Half.h:228
static EIGEN_CONSTEXPR const int max_exponent10
Definition: Half.h:231
static EIGEN_CONSTEXPR Eigen::half epsilon()
Definition: Half.h:240
static EIGEN_CONSTEXPR Eigen::half() max()
Definition: Half.h:239
static EIGEN_CONSTEXPR const bool has_quiet_NaN
Definition: Half.h:209
static EIGEN_CONSTEXPR const bool is_signed
Definition: Half.h:205
static EIGEN_CONSTEXPR const int max_digits10
Definition: Half.h:225
static EIGEN_CONSTEXPR const bool is_iec559
Definition: Half.h:217
static EIGEN_CONSTEXPR const bool has_signaling_NaN
Definition: Half.h:210
static EIGEN_CONSTEXPR const bool has_denorm_loss
Definition: Half.h:214
static EIGEN_CONSTEXPR const bool is_integer
Definition: Half.h:206
static EIGEN_CONSTEXPR const int max_exponent
Definition: Half.h:230
static EIGEN_CONSTEXPR const bool is_specialized
Definition: Half.h:204
static EIGEN_CONSTEXPR const bool tinyness_before
Definition: Half.h:235
static EIGEN_CONSTEXPR Eigen::half quiet_NaN()
Definition: Half.h:243
static EIGEN_CONSTEXPR const bool traps
Definition: Half.h:232
static EIGEN_CONSTEXPR const std::float_round_style round_style
Definition: Half.h:216
static EIGEN_CONSTEXPR const bool is_modulo
Definition: Half.h:221
static EIGEN_CONSTEXPR const bool is_exact
Definition: Half.h:207
static EIGEN_CONSTEXPR const int min_exponent10
Definition: Half.h:229
static EIGEN_CONSTEXPR Eigen::half denorm_min()
Definition: Half.h:245
static EIGEN_CONSTEXPR Eigen::half lowest()
Definition: Half.h:238
static EIGEN_CONSTEXPR Eigen::half signaling_NaN()
Definition: Half.h:244
static EIGEN_CONSTEXPR const int digits
Definition: Half.h:222
static EIGEN_CONSTEXPR const bool is_bounded
Definition: Half.h:220
Definition: Half.h:139
half_impl::__half_raw __half_raw
Definition: Half.h:146
EIGEN_DEVICE_FUNC half(std::complex< RealScalar > c)
Definition: Half.h:183
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR half()
Definition: Half.h:159
EIGEN_DEVICE_FUNC half(T val)
Definition: Half.h:176
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR half(bool b)
Definition: Half.h:173
EIGEN_DEVICE_FUNC half(float f)
Definition: Half.h:178
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR half(const __half_raw &h)
Definition: Half.h:161
static EIGEN_DEVICE_FUNC half run(const float &a)
Definition: Half.h:952
static EIGEN_DEVICE_FUNC float run(const half &a)
Definition: Half.h:976
static EIGEN_DEVICE_FUNC half run(const int &a)
Definition: Half.h:964
Definition: MathFunctions.h:339
Definition: Meta.h:145
@ value
Definition: Meta.h:146
static EIGEN_DEVICE_FUNC half run(const half &x, const half &y)
Definition: Half.h:788
static EIGEN_DEVICE_FUNC half run()
Definition: Half.h:792
Definition: RandomImpl.h:28
Definition: main.h:115
void run(const string &dir_name, LinearSolver *linear_solver_pt, const unsigned nel_1d, bool mess_up_order)
Definition: two_d_poisson_compare_solvers.cc:317
Definition: Half.h:525
float f
Definition: Half.h:527
unsigned int u
Definition: Half.h:526