DPC++ Runtime
Runtime libraries for oneAPI DPC++
bf16_storage_builtins.hpp
Go to the documentation of this file.
1 //===- bf16_storage_builtins.hpp ------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #pragma once
10 
11 #include <CL/__spirv/spirv_ops.hpp>
12 #include <sycl/builtins.hpp>
13 #include <sycl/detail/builtins.hpp>
17 
18 namespace sycl {
19 inline namespace _V1 {
20 namespace ext::oneapi {
21 
22 namespace detail {
23 
24 template <typename T> struct is_bf16_storage_type {
25  static constexpr int value = false;
26 };
27 
28 template <> struct is_bf16_storage_type<uint16_t> {
29  static constexpr int value = true;
30 };
31 
32 template <> struct is_bf16_storage_type<uint32_t> {
33  static constexpr int value = true;
34 };
35 
36 template <int N> struct is_bf16_storage_type<vec<uint16_t, N>> {
37  static constexpr int value = true;
38 };
39 
40 template <int N> struct is_bf16_storage_type<vec<uint32_t, N>> {
41  static constexpr int value = true;
42 };
43 
44 } // namespace detail
45 
46 template <typename T>
47 std::enable_if_t<detail::is_bf16_storage_type<T>::value, T> fabs(T x) {
48 #ifdef __SYCL_DEVICE_ONLY__
49  return __clc_fabs(x);
50 #else
51  (void)x;
52  throw runtime_error("bf16 is not supported on host device.",
53  PI_ERROR_INVALID_DEVICE);
54 #endif
55 }
56 template <typename T>
57 std::enable_if_t<detail::is_bf16_storage_type<T>::value, T> fmin(T x, T y) {
58 #ifdef __SYCL_DEVICE_ONLY__
59  return __clc_fmin(x, y);
60 #else
61  (void)x;
62  (void)y;
63  throw runtime_error("bf16 is not supported on host device.",
64  PI_ERROR_INVALID_DEVICE);
65 #endif
66 }
67 template <typename T>
68 std::enable_if_t<detail::is_bf16_storage_type<T>::value, T> fmax(T x, T y) {
69 #ifdef __SYCL_DEVICE_ONLY__
70  return __clc_fmax(x, y);
71 #else
72  (void)x;
73  (void)y;
74  throw runtime_error("bf16 is not supported on host device.",
75  PI_ERROR_INVALID_DEVICE);
76 #endif
77 }
78 template <typename T>
79 std::enable_if_t<detail::is_bf16_storage_type<T>::value, T> fma(T x, T y, T z) {
80 #ifdef __SYCL_DEVICE_ONLY__
81  return __clc_fma(x, y, z);
82 #else
83  (void)x;
84  (void)y;
85  (void)z;
86  throw runtime_error("bf16 is not supported on host device.",
87  PI_ERROR_INVALID_DEVICE);
88 #endif
89 }
90 
91 } // namespace ext::oneapi
92 } // namespace _V1
93 } // namespace sycl
spirv_ops.hpp
builtins.hpp
sycl::_V1::ext::oneapi::fabs
std::enable_if_t< detail::is_bf16_storage_type< T >::value, T > fabs(T x)
Definition: bf16_storage_builtins.hpp:47
type_traits.hpp
sycl::_V1::ext::oneapi::fma
std::enable_if_t< detail::is_bf16_storage_type< T >::value, T > fma(T x, T y, T z)
Definition: bf16_storage_builtins.hpp:79
detail
---— Error handling, matching OpenCL plugin semantics.
Definition: common.hpp:44
sycl
Definition: access.hpp:18
generic_type_lists.hpp
sycl::_V1::ext::oneapi::fmax
std::enable_if_t< detail::is_bf16_storage_type< T >::value, T > fmax(T x, T y)
Definition: bf16_storage_builtins.hpp:68
sycl::_V1::ext::oneapi::detail::is_bf16_storage_type
Definition: bf16_storage_builtins.hpp:24
generic_type_traits.hpp
sycl::_V1::ext::oneapi::fmin
std::enable_if_t< detail::is_bf16_storage_type< T >::value, T > fmin(T x, T y)
Definition: bf16_storage_builtins.hpp:57
sycl::_V1::ext::oneapi::detail::is_bf16_storage_type::value
static constexpr int value
Definition: bf16_storage_builtins.hpp:25
builtins.hpp
sycl::_V1::vec
Provides a cross-patform vector class template that works efficiently on SYCL devices as well as in h...
Definition: aliases.hpp:18