|
7 | 7 | //===----------------------------------------------------------------------===//
|
8 | 8 |
|
9 | 9 | // HOW-TO: Add new compile-time property
|
10 |
| -// 1. Add a new enumerator to `sycl::ext::oneapi::detail::PropKind` |
11 |
| -// representing the new property. Increment |
12 |
| -// `sycl::ext::oneapi::detail::PropKind::PropKindSize` |
13 |
| -// 2. Define property class with `value_t` that must be `property_value` with |
14 |
| -// the first template argument being the property class itself. |
15 |
| -// 3. Add an `inline constexpr` variable in the same namespace as the property. |
16 |
| -// The variable should have the same type as `value_t` of the property class |
17 |
| -// and should be named as the property class with `_v` appended, e.g. for a |
18 |
| -// property `foo`, there should be a definition |
19 |
| -// `inline constexpr foo::value_t foo_v`. |
20 |
| -// 4. Specialize `sycl::ext::oneapi::detail::PropertyToKind` for the new |
21 |
| -// property class. The specialization should have a `Kind` member with the |
22 |
| -// value equal to the enumerator added in 1. |
23 |
| -// 5. Specialize `sycl::ext::oneapi::detail::IsCompileTimeProperty` for the new |
24 |
| -// property class. This specialization should derive from `std::true_type`. |
25 |
| -// 6. Specialize `sycl::is_property` and `sycl::is_property_of` for the |
26 |
| -// property class. |
| 10 | +// 1. Add a new enumerator to |
| 11 | +// `sycl::ext::oneapi::experimental::detail::PropKind` representing the new |
| 12 | +// property. Increment |
| 13 | +// `sycl::ext::oneapi::experimental::detail::PropKind::PropKindSize` |
| 14 | +// 2. Define property key class with `value_t` that must be `property_value` |
| 15 | +// with the first template argument being the property class itself. The |
| 16 | +// name of the key class must be the property name suffixed by `_key`, i.e. |
| 17 | +// for a property `foo` the class should be named `foo_key`. |
| 18 | +// 3. Add an `inline constexpr` variable in the same namespace as the property |
| 19 | +// key. The variable should have the same type as `value_t` of the property |
| 20 | +// class, e.g. for a property `foo`, there should be a definition |
| 21 | +// `inline constexpr foo_key::value_t foo`. |
| 22 | +// 4. Specialize `sycl::ext::oneapi::experimental::is_property` and |
| 23 | +// `sycl::ext::oneapi::experimental::is_property_of` for the property key |
| 24 | +// class. |
| 25 | +// 5. Specialize `sycl::ext::oneapi::experimental::detail::PropertyToKind` for |
| 26 | +// the new property key class. The specialization should have a `Kind` |
| 27 | +// member with the value equal to the enumerator added in 1. |
| 28 | +// 6. Specialize |
| 29 | +// `sycl::ext::oneapi::experimental::detail::IsCompileTimeProperty` for the |
| 30 | +// new property key class. This specialization should derive from |
| 31 | +// `std::true_type`. |
27 | 32 | /******************************** EXAMPLE **************************************
|
28 |
| ----------- sycl/include/sycl/ext/oneapi/property_list/properties.hpp ----------- |
| 33 | +------------- sycl/include/sycl/ext/oneapi/properties/property.hpp ------------- |
29 | 34 | // (1.)
|
30 | 35 | enum PropKind : uint32_t {
|
31 | 36 | ...
|
32 | 37 | Bar,
|
33 | 38 | PropKindSize = N + 1, // N was the previous value
|
34 | 39 | };
|
35 | 40 | ---------------------- path/to/new/property/file.hpp ---------------------------
|
36 |
| -namespace sycl { |
37 |
| -namespace ext { |
38 |
| -namespace oneapi { |
| 41 | +namespace sycl::ext::oneapi::experimental { |
39 | 42 |
|
40 | 43 | // (2.)
|
41 |
| -struct bar { |
42 |
| - using value_t = property_value<bar>; |
| 44 | +struct bar_key { |
| 45 | + using value_t = property_value<bar_key>; |
43 | 46 | };
|
44 | 47 |
|
45 | 48 | // (3.)
|
46 |
| -inline constexpr bar::value_t bar_v; |
| 49 | +inline constexpr bar_key::value_t bar; |
| 50 | +
|
| 51 | +// (4.) |
| 52 | +template <> struct is_property<bar_key> : std::true_type {}; |
| 53 | +// Replace SYCL_OBJ with the SYCL object to support the property. |
| 54 | +template <> struct is_property_of<bar_key, SYCL_OBJ> : std::true_type {}; |
47 | 55 |
|
48 | 56 | namespace detail {
|
49 | 57 |
|
50 |
| -// (4.) |
51 |
| -template <> struct PropertyToKind<bar> { |
| 58 | +// (5.) |
| 59 | +template <> struct PropertyToKind<bar_key> { |
52 | 60 | static constexpr PropKind Kind = PropKind::Bar;
|
53 | 61 | };
|
54 | 62 |
|
55 |
| -// (5.) |
56 |
| -template <> struct IsCompileTimeProperty<bar> : std::true_type {}; |
57 |
| -
|
58 |
| -} // namespace detail |
59 |
| -} // namespace oneapi |
60 |
| -} // namespace ext |
61 |
| -
|
62 | 63 | // (6.)
|
63 |
| -template <> struct is_property<ext::oneapi::bar> : std::true_type {}; |
64 |
| -// Replace SYCL_OBJ with the SYCL object to support the property. |
65 |
| -template <> struct is_property_of<ext::oneapi::bar, SYCL_OBJ> |
66 |
| - : std::true_type {}; |
| 64 | +template <> struct IsCompileTimeProperty<bar_key> : std::true_type {}; |
67 | 65 |
|
68 |
| -} // namespace sycl |
| 66 | +} // namespace detail |
| 67 | +} // namespace sycl::ext::oneapi::experimental |
69 | 68 | *******************************************************************************/
|
70 | 69 |
|
71 | 70 | // HOW-TO: Add new runtime property
|
72 | 71 | // 1. Add a new enumerator to `sycl::ext::oneapi::detail::PropKind`
|
73 | 72 | // representing the new property. Increment
|
74 |
| -// `sycl::ext::oneapi::detail::PropKind::PropKindSize` |
| 73 | +// `sycl::ext::oneapi::experimental::detail::PropKind::PropKindSize` |
75 | 74 | // 2. Define property class.
|
76 |
| -// 3. Overload the `==` and `!=` operators for the new property class. The |
| 75 | +// 3. Declare the property key as an alias to the property class. The name of |
| 76 | +// the key class must be the property name suffixed by `_key`, i.e. for a |
| 77 | +// property `foo` the class should be named `foo_key`. |
| 78 | +// 4. Overload the `==` and `!=` operators for the new property class. The |
77 | 79 | // comparison should compare all data members of the property class.
|
78 |
| -// 4. Specialize `sycl::ext::oneapi::detail::PropertyToKind` for the new |
| 80 | +// 5. Specialize `sycl::ext::oneapi::experimental::is_property` and |
| 81 | +// `sycl::ext::oneapi::experimental::is_property_of` for the property class. |
| 82 | +// 6. Specialize `sycl::ext::oneapi::detail::PropertyToKind` for the new |
79 | 83 | // property class. The specialization should have a `Kind` member with the
|
80 | 84 | // value equal to the enumerator added in 1.
|
81 |
| -// 5. Specialize `sycl::ext::oneapi::detail::IsRuntimeProperty` for the new |
82 |
| -// property class. This specialization should derive from `std::true_type`. |
83 |
| -// 6. Specialize `sycl::is_property` and `sycl::is_property_of` for the |
84 |
| -// property class. |
| 85 | +// 7. Specialize `sycl::ext::oneapi::experimental::detail::IsRuntimeProperty` |
| 86 | +// for the new property class. This specialization should derive from |
| 87 | +// `std::true_type`. |
85 | 88 | /******************************* EXAMPLE ***************************************
|
86 |
| ----------- sycl/include/sycl/ext/oneapi/property_list/properties.hpp ----------- |
| 89 | +------------- sycl/include/sycl/ext/oneapi/properties/property.hpp ------------- |
87 | 90 | // (1.)
|
88 | 91 | enum PropKind : uint32_t {
|
89 | 92 | ...
|
90 | 93 | Foo,
|
91 | 94 | PropKindSize = N + 1, // N was the previous value
|
92 | 95 | };
|
93 | 96 | ---------------------- path/to/new/property/file.hpp ---------------------------
|
94 |
| -namespace sycl { |
95 |
| -namespace ext { |
96 |
| -namespace oneapi { |
| 97 | +namespace sycl::ext::oneapi::experimental { |
97 | 98 |
|
98 | 99 | // (2.)
|
99 | 100 | struct foo {
|
100 | 101 | foo(int v) : value(v) {}
|
101 | 102 | int value;
|
102 | 103 | };
|
103 | 104 |
|
104 |
| -// (3.) |
| 105 | +// 3. |
| 106 | +using foo_key = foo; |
| 107 | +
|
| 108 | +// (4.) |
105 | 109 | inline bool operator==(const foo &lhs, const foo &rhs) {
|
106 | 110 | return lhs.value == rhs.value;
|
107 | 111 | }
|
108 | 112 | inline bool operator!=(const foo &lhs, const foo &rhs) {
|
109 | 113 | return !(lhs == rhs);
|
110 | 114 | }
|
111 | 115 |
|
| 116 | +// (5.) |
| 117 | +template <> struct is_property_key<foo> : std::true_type {}; |
| 118 | +// Replace SYCL_OBJ with the SYCL object to support the property. |
| 119 | +template <> struct is_property_key_of<foo, SYCL_OBJ> : std::true_type {}; |
| 120 | +
|
112 | 121 | namespace detail {
|
113 | 122 |
|
114 |
| -// (4.) |
| 123 | +// (6.) |
115 | 124 | template <> struct PropertyToKind<foo> {
|
116 | 125 | static constexpr PropKind Kind = PropKind::Foo;
|
117 | 126 | };
|
118 | 127 |
|
119 |
| -// (5.) |
| 128 | +// (7.) |
120 | 129 | template <> struct IsRuntimeProperty<foo> : std::true_type {};
|
121 |
| -} // namespace detail |
122 |
| -} // namespace oneapi |
123 |
| -} // namespace ext |
124 |
| -
|
125 |
| -// (6.) |
126 |
| -template <> struct is_property<ext::oneapi::foo> : std::true_type {}; |
127 |
| -// Replace SYCL_OBJ with the SYCL object to support the property. |
128 |
| -template <> struct is_property_of<ext::oneapi::foo, SYCL_OBJ> |
129 |
| - : std::true_type {}; |
130 | 130 |
|
131 |
| -} // namespace sycl |
| 131 | +} // namespace detail |
| 132 | +} // namespace sycl::ext::oneapi::experimental |
132 | 133 | *******************************************************************************/
|
133 | 134 |
|
134 | 135 | #pragma once
|
@@ -162,6 +163,10 @@ template <typename PropertyT> struct IsRuntimeProperty : std::false_type {};
|
162 | 163 | template <typename PropertyT> struct IsCompileTimeProperty : std::false_type {};
|
163 | 164 |
|
164 | 165 | } // namespace detail
|
| 166 | + |
| 167 | +template <typename> struct is_property_key : std::false_type {}; |
| 168 | +template <typename, typename> struct is_property_key_of : std::false_type {}; |
| 169 | + |
165 | 170 | } // namespace experimental
|
166 | 171 | } // namespace oneapi
|
167 | 172 | } // namespace ext
|
|
0 commit comments