DPC++ Runtime
Runtime libraries for oneAPI DPC++
bf16_storage_builtins.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 #include <sycl/builtins.hpp>
9 
10 namespace sycl {
12 namespace ext::oneapi {
13 
14 namespace detail {
15 
16 template <typename T> struct is_bf16_storage_type {
17  static constexpr int value = false;
18 };
19 
20 template <> struct is_bf16_storage_type<uint16_t> {
21  static constexpr int value = true;
22 };
23 
24 template <> struct is_bf16_storage_type<uint32_t> {
25  static constexpr int value = true;
26 };
27 
28 template <int N> struct is_bf16_storage_type<vec<uint16_t, N>> {
29  static constexpr int value = true;
30 };
31 
32 template <int N> struct is_bf16_storage_type<vec<uint32_t, N>> {
33  static constexpr int value = true;
34 };
35 
36 } // namespace detail
37 
38 template <typename T>
39 std::enable_if_t<detail::is_bf16_storage_type<T>::value, T> fabs(T x) {
40 #ifdef __SYCL_DEVICE_ONLY__
41  return __clc_fabs(x);
42 #else
43  (void)x;
44  throw runtime_error("bf16 is not supported on host device.",
45  PI_ERROR_INVALID_DEVICE);
46 #endif
47 }
48 template <typename T>
49 std::enable_if_t<detail::is_bf16_storage_type<T>::value, T> fmin(T x, T y) {
50 #ifdef __SYCL_DEVICE_ONLY__
51  return __clc_fmin(x, y);
52 #else
53  (void)x;
54  (void)y;
55  throw runtime_error("bf16 is not supported on host device.",
56  PI_ERROR_INVALID_DEVICE);
57 #endif
58 }
59 template <typename T>
60 std::enable_if_t<detail::is_bf16_storage_type<T>::value, T> fmax(T x, T y) {
61 #ifdef __SYCL_DEVICE_ONLY__
62  return __clc_fmax(x, y);
63 #else
64  (void)x;
65  (void)y;
66  throw runtime_error("bf16 is not supported on host device.",
67  PI_ERROR_INVALID_DEVICE);
68 #endif
69 }
70 template <typename T>
71 std::enable_if_t<detail::is_bf16_storage_type<T>::value, T> fma(T x, T y, T z) {
72 #ifdef __SYCL_DEVICE_ONLY__
73  return __clc_fma(x, y, z);
74 #else
75  (void)x;
76  (void)y;
77  (void)z;
78  throw runtime_error("bf16 is not supported on host device.",
79  PI_ERROR_INVALID_DEVICE);
80 #endif
81 }
82 
83 } // namespace ext::oneapi
84 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
85 } // namespace sycl
Provides a cross-patform vector class template that works efficiently on SYCL devices as well as in h...
Definition: types.hpp:558
#define __SYCL_INLINE_VER_NAMESPACE(X)
std::enable_if_t< detail::is_bf16_storage_type< T >::value, T > fma(T x, T y, T z)
std::enable_if_t< detail::is_bf16_storage_type< T >::value, T > fmax(T x, T y)
std::enable_if_t< detail::is_bf16_storage_type< T >::value, T > fmin(T x, T y)
std::enable_if_t< detail::is_bf16_storage_type< T >::value, T > fabs(T x)
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14