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 
90  oneapi::experimental::detail::PropKind::FloatingPointControls> {
91  template <fp_mode option>
93  fp_control_key, std::integral_constant<fp_mode, option>>;
94 };
95 
96 template <fp_mode option>
98 
99 } // namespace ext::intel::experimental
100 
101 namespace ext::oneapi::experimental {
102 template <typename T, typename PropertyListT>
104  intel::experimental::fp_control_key,
105  intel::experimental::kernel_attribute<T, PropertyListT>> : std::true_type {
106 };
107 
108 namespace detail {
109 template <intel::experimental::fp_mode FPMode>
110 struct PropertyMetaInfo<intel::experimental::fp_control_key::value_t<FPMode>> {
112  "Mutually exclusive fp modes are specified for the kernel.");
113  static constexpr const char *name = "sycl-floating-point-control";
116 };
117 
118 } // namespace detail
119 } // namespace ext::oneapi::experimental
120 } // namespace _V1
121 } // 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)
auto autodecltype(a) b
Definition: access.hpp:18