DPC++ Runtime
Runtime libraries for oneAPI DPC++
tfloat32_type_traits.hpp
Go to the documentation of this file.
1 //==-------------- tfloat32_type_traits.hpp - DPC++ Explicit SIMD API
2 //----------==//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9 // Implementation of SIMD element type traits for the tfloat32 type.
10 //===----------------------------------------------------------------------===//
11 
12 #pragma once
13 
17 
19 
20 namespace sycl {
21 inline namespace _V1 {
22 namespace ext::intel::esimd::detail {
23 
24 // Standalone definitions to use w/o instantiating element_type_traits.
26 
27 template <> struct element_type_traits<tfloat32> {
28  using RawT = unsigned int;
29  using EnclosingCppT = float;
30 
31  static constexpr bool use_native_cpp_ops = false;
32  static constexpr bool is_floating_point = true;
33 };
34 
35 // ------------------- Type conversion traits
36 
37 template <int N> struct vector_conversion_traits<tfloat32, N> {
38  using StdT = __cpp_t<tfloat32>;
39  using RawT = __raw_t<tfloat32>;
40 
41  static ESIMD_INLINE vector_type_t<RawT, N>
42  convert_to_raw(vector_type_t<StdT, N> Val) {
43 #ifdef __SYCL_DEVICE_ONLY__
44  vector_type_t<RawT, N> Result = __esimd_tf32_cvt<RawT, StdT, N>(Val);
45  return Result;
46 #else
47  vector_type_t<RawT, N> Output = 0;
48 
49  for (int i = 0; i < N; i++) {
50  Output[i] = sycl::bit_cast<RawT>(static_cast<tfloat32>(Val[i]));
51  }
52  return Output;
53 #endif
54  }
55 
56  static ESIMD_INLINE vector_type_t<StdT, N>
57  convert_to_cpp(vector_type_t<RawT, N> Val) {
58  vector_type_t<StdT, N> Result = sycl::bit_cast<vector_type_t<StdT, N>>(Val);
59  return Result;
60  }
61 };
62 
63 template <> struct scalar_conversion_traits<tfloat32> {
64  using RawT = __raw_t<tfloat32>;
65 
66  static ESIMD_INLINE RawT bitcast_to_raw(tfloat32 Val) {
67  return sycl::bit_cast<RawT>(Val);
68  }
69 
70  static ESIMD_INLINE tfloat32 bitcast_to_wrapper(RawT Val) {
71  return sycl::bit_cast<tfloat32>(Val);
72  }
73 };
74 
75 // Misc
76 inline std::ostream &operator<<(std::ostream &O, tfloat32 const &rhs) {
77  O << static_cast<float>(rhs);
78  return O;
79 }
80 
81 template <> struct is_esimd_arithmetic_type<tfloat32, void> : std::true_type {};
82 
83 } // namespace ext::intel::esimd::detail
84 } // namespace _V1
85 } // namespace sycl
86 
auto operator<<(const __ESIMD_DNS::simd_obj_impl< __raw_t< T1 >, N, SimdT< T1, N >> &LHS, const __ESIMD_DNS::simd_obj_impl< __raw_t< T2 >, N, SimdT< T2, N >> &RHS)
Definition: operators.hpp:178
Definition: access.hpp:18