DPC++ Runtime
Runtime libraries for oneAPI DPC++
uniform.hpp
Go to the documentation of this file.
1 //==------ uniform.hpp - SYCL uniform extension --------*- C++ -*-----------==//
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 // Implemenation of the sycl_ext_oneapi_uniform extension.
9 // https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/proposed/sycl_ext_oneapi_uniform.asciidoc
10 // ===--------------------------------------------------------------------=== //
11 
12 #pragma once
13 
14 // SYCL extension macro definition as required by the SYCL specification.
15 // 1 - Initial extension version. Base features are supported.
16 #define SYCL_EXT_ONEAPI_UNIFORM 1
17 
18 #include <type_traits>
19 
20 // Forward declarations of types not allowed to be wrapped in uniform:
21 namespace sycl {
22 inline namespace _V1 {
23 
24 struct sub_group;
25 template <int, bool> class item;
26 template <int> class id;
27 template <int> class nd_item;
28 template <int> class h_item;
29 template <int> class group;
30 template <int> class nd_range;
31 using sycl::sub_group;
32 
33 namespace ext::oneapi::experimental {
34 namespace detail {
35 
36 template <class T, template <int> class Tmpl>
37 struct is_instance_of_tmpl_int : std::false_type {};
38 template <int N, template <int> class T, template <int> class Tmpl>
39 struct is_instance_of_tmpl_int<T<N>, Tmpl>
40  : std::conditional<std::is_same_v<T<N>, Tmpl<N>>, std::true_type,
41  std::false_type> {};
42 template <class T, template <int> class Tmpl>
43 static inline constexpr bool is_instance_of_tmpl_int_v =
45 
46 template <class T, template <int, bool> class Tmpl>
47 struct is_instance_of_tmpl_int_bool : std::false_type {};
48 template <int N, bool X, template <int, bool> class T,
49  template <int, bool> class Tmpl>
50 struct is_instance_of_tmpl_int_bool<T<N, X>, Tmpl>
51  : std::conditional<std::is_same_v<T<N, X>, Tmpl<N, X>>, std::true_type,
52  std::false_type> {};
53 template <class T, template <int, bool> class Tmpl>
54 static inline constexpr bool is_instance_of_tmpl_int_bool_v =
56 } // namespace detail
57 
58 template <class T> class uniform {
59  template <class U> static constexpr bool can_be_uniform() {
60  return !detail::is_instance_of_tmpl_int_bool_v<U, sycl::item> &&
61  !detail::is_instance_of_tmpl_int_v<U, sycl::nd_item> &&
62  !detail::is_instance_of_tmpl_int_v<U, sycl::h_item> &&
63  !detail::is_instance_of_tmpl_int_v<U, sycl::group> &&
64  !detail::is_instance_of_tmpl_int_v<U, sycl::nd_range> &&
65  !std::is_same_v<U, sycl::sub_group>;
66  }
67  static_assert(can_be_uniform<T>() && "type not allowed to be `uniform`");
68 
69 public:
70  explicit uniform(T x) noexcept : Val(x) {}
71 
72  // TODO provide a ways to reflect this conversion from uniform to T in the IR
73  // so that the compiler can take advantage of uniformness. Could be marked
74  // with some intrinsic call like `__builtin_uniform_unwrap(Val);`
75 
77  operator const T() const { return Val; }
78 
79  uniform &operator=(const uniform &) = delete;
80 
81  /* Other explicitly deleted operators improve error messages
82  if a user incorrectly attempts to modify a uniform */
83  uniform &operator+=(const T &) = delete;
84  uniform &operator-=(const T &) = delete;
85  uniform &operator*=(const T &) = delete;
86  uniform &operator/=(const T &) = delete;
87  uniform &operator%=(const T &) = delete;
88  uniform &operator&=(const T &) = delete;
89  uniform &operator|=(const T &) = delete;
90  uniform &operator^=(const T &) = delete;
91  uniform &operator<<=(const T &) = delete;
92  uniform &operator>>=(const T &) = delete;
93  uniform &operator++() = delete;
94  uniform &operator++(int) = delete;
95  uniform &operator--() = delete;
96  uniform &operator--(int) = delete;
97 
98 private:
99  T Val;
100 };
101 
102 } // namespace ext::oneapi::experimental
103 } // namespace _V1
104 } // namespace sycl
uniform & operator^=(const T &)=delete
uniform & operator%=(const T &)=delete
uniform & operator|=(const T &)=delete
uniform & operator=(const uniform &)=delete
uniform & operator>>=(const T &)=delete
uniform & operator*=(const T &)=delete
uniform & operator&=(const T &)=delete
uniform & operator/=(const T &)=delete
uniform & operator<<=(const T &)=delete
uniform & operator+=(const T &)=delete
uniform & operator-=(const T &)=delete
static constexpr bool is_instance_of_tmpl_int_bool_v
Definition: uniform.hpp:54
static constexpr bool is_instance_of_tmpl_int_v
Definition: uniform.hpp:43
Definition: access.hpp:18
_Abi const simd< _Tp, _Abi > & noexcept
Definition: simd.hpp:1324