DPC++ Runtime
Runtime libraries for oneAPI DPC++
fp_control_kernel_properties.hpp
Go to the documentation of this file.
1 //=- fp_control_kernel_properties.hpp - SYCL kernel property for fp control -=//
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 
13 
14 #include <cstdint>
15 #include <type_traits>
16 
17 namespace sycl {
18 inline namespace _V1 {
19 namespace ext::intel::experimental {
20 
21 template <typename T, typename PropertyListT> class kernel_attribute;
22 
23 // Masks defined here must be in sync with the LLVM pass for handling compile
24 // time properties (CompileTimePropertiesPass).
25 enum class fp_mode : std::uint32_t {
26  round_to_nearest = 1, // Round to nearest or even
27  round_upward = 1 << 1, // Round towards +ve inf
28  round_downward = 1 << 2, // Round towards -ve inf
29  round_toward_zero = 1 << 3, // Round towards zero
30 
31  denorm_ftz = 1 << 4, // Denorm mode flush to zero
32  denorm_d_allow = 1 << 5, // Denorm mode double allow
33  denorm_f_allow = 1 << 6, // Denorm mode float allow
34  denorm_hf_allow = 1 << 7, // Denorm mode half allow
36  denorm_hf_allow // Denorm mode double/float/half allow
37 };
38 
39 constexpr fp_mode operator|(const fp_mode &a, const fp_mode &b) {
40  return static_cast<fp_mode>(static_cast<std::underlying_type_t<fp_mode>>(a) |
41  static_cast<std::underlying_type_t<fp_mode>>(b));
42 }
43 
44 namespace detail {
45 constexpr fp_mode operator&(const fp_mode &a, const fp_mode &b) {
46  return static_cast<fp_mode>(static_cast<std::underlying_type_t<fp_mode>>(a) &
47  static_cast<std::underlying_type_t<fp_mode>>(b));
48 }
49 constexpr fp_mode operator^(const fp_mode &a, const fp_mode &b) {
50  return static_cast<fp_mode>(static_cast<std::underlying_type_t<fp_mode>>(a) ^
51  static_cast<std::underlying_type_t<fp_mode>>(b));
52 }
53 constexpr bool isSet(const fp_mode &mode, const fp_mode &flag) {
54  return (mode & flag) == flag;
55 }
56 constexpr bool checkMutuallyExclusive(const fp_mode &mode) {
57  // Check that either none of the flags is set or only one flag is set.
60  bool isCorrectRoundingMode = ((mode & roundMask) == fp_mode(0)) ||
65  // Check that if denorm_ftz is set then other denorm flags are not set.
68  bool isCorrectDenormMode = !isSet(mode, fp_mode::denorm_ftz) ||
69  ((mode & denormAllowMask) == fp_mode(0));
70  return isCorrectRoundingMode && isCorrectDenormMode;
71 }
72 
76  if ((mode & roundMask) == fp_mode(0))
78 
79  auto denormMask = fp_mode::denorm_ftz | fp_mode::denorm_hf_allow |
81  if ((mode & denormMask) == fp_mode(0))
83 
84  return mode;
85 }
86 } // namespace detail
87 
89  template <fp_mode option>
91  fp_control_key, std::integral_constant<fp_mode, option>>;
92 };
93 
94 template <fp_mode option>
96 
97 } // namespace ext::intel::experimental
98 
99 namespace ext::oneapi::experimental {
100 template <>
101 struct is_property_key<intel::experimental::fp_control_key> : std::true_type {};
102 
103 template <typename T, typename PropertyListT>
105  intel::experimental::fp_control_key,
106  intel::experimental::kernel_attribute<T, PropertyListT>> : std::true_type {
107 };
108 
109 namespace detail {
110 template <> struct PropertyToKind<intel::experimental::fp_control_key> {
111  static constexpr PropKind Kind = FloatingPointControls;
112 };
113 
114 template <>
115 struct IsCompileTimeProperty<intel::experimental::fp_control_key>
116  : std::true_type {};
117 
118 template <intel::experimental::fp_mode FPMode>
119 struct PropertyMetaInfo<intel::experimental::fp_control_key::value_t<FPMode>> {
121  "Mutually exclusive fp modes are specified for the kernel.");
122  static constexpr const char *name = "sycl-floating-point-control";
125 };
126 
127 } // namespace detail
128 } // namespace ext::oneapi::experimental
129 } // namespace _V1
130 } // namespace sycl
constexpr fp_mode operator^(const fp_mode &a, const fp_mode &b)
constexpr bool isSet(const fp_mode &mode, const fp_mode &flag)
constexpr bool checkMutuallyExclusive(const fp_mode &mode)
constexpr fp_mode operator&(const fp_mode &a, const fp_mode &b)
constexpr fp_control_key::value_t< option > fp_control
constexpr fp_mode operator|(const fp_mode &a, const fp_mode &b)
T detail::marray_element_t< T > y T T T maxval[i] T T T a
y y maxval[j] maxval b
Definition: access.hpp:18