Skip to content

Commit 69572a2

Browse files
[SYCL] Refactor compile-time properties' detail:: traits (#16099)
* Prefer to perform the check on values and not keys * Use `std::is_empty_v` to distinguish between compile/run-time properties * Remove unused traits (including the ones that became such after changes above) Technically, I'm (almost?) able to remove the `compile_time_property_key` and `run_time_property_key` base classes at this point, but I'd prefer to do that later once `property_value` template is removed from the spec too, as both of these changes will require updating all the properties and I'd rather do that once.
1 parent a0401d0 commit 69572a2

File tree

5 files changed

+55
-107
lines changed

5 files changed

+55
-107
lines changed

sycl/include/sycl/ext/oneapi/experimental/annotated_usm/alloc_util.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ struct ValidAllocPropertyList<T, detail::properties_t<Prop, Props...>>
8989
IsRuntimePropertyValid<Prop>::value) &&
9090
ValidAllocPropertyList<
9191
T, detail::properties_t<Props...>>::value> {
92+
static_assert(is_property_value_v<Prop>);
93+
static constexpr bool is_compile_time = std::is_empty_v<Prop>;
9294
// check if a compile-time property is valid for annotated_ptr
93-
static_assert(!detail::IsCompileTimePropertyValue<Prop>::value ||
94-
is_valid_property<T *, Prop>::value,
95+
static_assert(!is_compile_time || is_valid_property<T *, Prop>::value,
9596
"Found invalid compile-time property in the property list.");
9697
// check if a runtime property is valid for malloc
97-
static_assert(!detail::IsRuntimeProperty<Prop>::value ||
98-
IsRuntimePropertyValid<Prop>::value,
98+
static_assert(is_compile_time || IsRuntimePropertyValid<Prop>::value,
9999
"Found invalid runtime property in the property list.");
100100
};
101101

@@ -110,15 +110,15 @@ template <> struct GetCompileTimeProperties<empty_properties_t> {
110110
template <typename Prop>
111111
struct GetCompileTimeProperties<detail::properties_t<Prop>> {
112112
using type =
113-
std::conditional_t<detail::IsCompileTimePropertyValue<Prop>::value,
114-
detail::properties_t<Prop>, empty_properties_t>;
113+
std::conditional_t<std::is_empty_v<Prop>, detail::properties_t<Prop>,
114+
empty_properties_t>;
115115
};
116116

117117
template <typename Prop, typename... Props>
118118
struct GetCompileTimeProperties<detail::properties_t<Prop, Props...>> {
119119
using filtered_this_property_t =
120-
std::conditional_t<detail::IsCompileTimePropertyValue<Prop>::value,
121-
detail::properties_t<Prop>, empty_properties_t>;
120+
std::conditional_t<std::is_empty_v<Prop>, detail::properties_t<Prop>,
121+
empty_properties_t>;
122122
using filtered_other_properties_t =
123123
typename GetCompileTimeProperties<detail::properties_t<Props...>>::type;
124124
using type = detail::merged_properties_t<filtered_this_property_t,

sycl/include/sycl/ext/oneapi/properties/property.hpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -289,29 +289,6 @@ template <typename PropertyT> struct PropertyID {
289289
static_cast<int>(PropertyToKind<PropertyT>::Kind);
290290
};
291291

292-
// Trait for identifying runtime properties.
293-
template <typename PropertyT>
294-
struct IsRuntimeProperty
295-
: std::bool_constant<
296-
!is_property_list_v<PropertyT> &&
297-
std::is_base_of_v<property_key_base_tag, PropertyT> &&
298-
!std::is_base_of_v<compile_time_property_key_base_tag, PropertyT>> {};
299-
300-
// Trait for identifying compile-time properties.
301-
template <typename PropertyT>
302-
struct IsCompileTimeProperty
303-
: std::bool_constant<
304-
!is_property_list_v<PropertyT> &&
305-
std::is_base_of_v<property_key_base_tag, PropertyT> &&
306-
std::is_base_of_v<compile_time_property_key_base_tag, PropertyT>> {};
307-
308-
// Checks if a type is either a runtime property or if it is a compile-time
309-
// property
310-
template <typename T> struct IsProperty {
311-
static constexpr bool value =
312-
IsRuntimeProperty<T>::value || IsCompileTimeProperty<T>::value;
313-
};
314-
315292
// Trait for property compile-time meta names and values.
316293
template <typename PropertyT> struct PropertyMetaInfo {
317294
// Some properties don't have meaningful compile-time values.

sycl/include/sycl/ext/oneapi/properties/property_utils.hpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,6 @@ template <int N, typename... Ts>
4343
using nth_type_t = typename nth_type<N, Ts...>::type;
4444
#endif
4545

46-
//******************************************************************************
47-
// Property identification
48-
//******************************************************************************
49-
50-
// Checks that all types in a tuple are valid properties.
51-
template <typename T> struct AllPropertyValues {};
52-
template <typename... Ts>
53-
struct AllPropertyValues<std::tuple<Ts...>> : std::true_type {};
54-
template <typename T, typename... Ts>
55-
struct AllPropertyValues<std::tuple<T, Ts...>>
56-
: std::conditional_t<IsPropertyValue<T>::value,
57-
AllPropertyValues<std::tuple<Ts...>>,
58-
std::false_type> {};
59-
6046
//******************************************************************************
6147
// Property value tooling
6248
//******************************************************************************

sycl/include/sycl/ext/oneapi/properties/property_value.hpp

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -48,60 +48,45 @@ struct property_value
4848
PropertyT> {};
4949

5050
template <typename PropertyT, typename... A, typename... B>
51-
constexpr std::enable_if_t<detail::IsCompileTimeProperty<PropertyT>::value,
51+
constexpr std::enable_if_t<std::is_empty_v<property_value<PropertyT, A...>>,
5252
bool>
5353
operator==(const property_value<PropertyT, A...> &,
5454
const property_value<PropertyT, B...> &) {
5555
return (std::is_same<A, B>::value && ...);
5656
}
5757

5858
template <typename PropertyT, typename... A, typename... B>
59-
constexpr std::enable_if_t<detail::IsCompileTimeProperty<PropertyT>::value,
59+
constexpr std::enable_if_t<std::is_empty_v<property_value<PropertyT, A...>>,
6060
bool>
6161
operator!=(const property_value<PropertyT, A...> &,
6262
const property_value<PropertyT, B...> &) {
6363
return (!std::is_same<A, B>::value || ...);
6464
}
6565

66-
template <typename V, typename = void> struct is_property_value {
67-
static constexpr bool value =
68-
detail::IsRuntimeProperty<V>::value && is_property_key<V>::value;
69-
};
70-
template <typename V, typename O, typename = void> struct is_property_value_of {
71-
static constexpr bool value =
72-
detail::IsRuntimeProperty<V>::value && is_property_key_of<V, O>::value;
73-
};
74-
// Specialization for compile-time-constant properties
7566
template <typename V>
76-
struct is_property_value<V, std::void_t<typename V::key_t>>
77-
: is_property_key<typename V::key_t> {};
78-
template <typename V, typename O>
79-
struct is_property_value_of<V, O, std::void_t<typename V::key_t>>
80-
: is_property_key_of<typename V::key_t, O> {};
67+
struct is_property_value
68+
: std::bool_constant<!is_property_list_v<V> &&
69+
std::is_base_of_v<detail::property_tag, V>> {};
8170

8271
template <typename V>
8372
inline constexpr bool is_property_value_v = is_property_value<V>::value;
8473

74+
template <typename V, typename O> struct is_property_value_of {
75+
static constexpr bool value = []() constexpr {
76+
if constexpr (is_property_value_v<V>)
77+
return is_property_key_of<typename V::key_t, O>::value;
78+
else
79+
return false;
80+
}();
81+
};
82+
8583
namespace detail {
8684

8785
// Specialization of PropertyID for propagating IDs through property_value.
8886
template <typename PropertyT, typename... PropertyValueTs>
8987
struct PropertyID<property_value<PropertyT, PropertyValueTs...>>
9088
: PropertyID<PropertyT> {};
9189

92-
// Checks if a type is a compile-time property values.
93-
template <typename PropertyT>
94-
struct IsCompileTimePropertyValue : std::false_type {};
95-
template <typename PropertyT, typename... PropertyValueTs>
96-
struct IsCompileTimePropertyValue<property_value<PropertyT, PropertyValueTs...>>
97-
: IsCompileTimeProperty<PropertyT> {};
98-
99-
// Checks if a type is a valid property value, i.e either runtime property or
100-
// property_value with a valid compile-time property
101-
template <typename T> struct IsPropertyValue {
102-
static constexpr bool value =
103-
IsRuntimeProperty<T>::value || IsCompileTimePropertyValue<T>::value;
104-
};
10590
} // namespace detail
10691
} // namespace ext::oneapi::experimental
10792
} // namespace _V1

sycl/test/extensions/annotated_usm/fake_properties.hpp

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -62,39 +62,39 @@ struct foz : detail::run_time_property_key<foz, fakePropKind(4)> {
6262
};
6363

6464
// clang-format off
65-
struct rt_prop1 : detail::run_time_property_key<rt_prop1, fakePropKind(5)> {};
66-
struct rt_prop2 : detail::run_time_property_key<rt_prop2, fakePropKind(6)> {};
67-
struct rt_prop3 : detail::run_time_property_key<rt_prop3, fakePropKind(7)> {};
68-
struct rt_prop4 : detail::run_time_property_key<rt_prop4, fakePropKind(8)> {};
69-
struct rt_prop5 : detail::run_time_property_key<rt_prop5, fakePropKind(9)> {};
70-
struct rt_prop6 : detail::run_time_property_key<rt_prop6, fakePropKind(10)> {};
71-
struct rt_prop7 : detail::run_time_property_key<rt_prop7, fakePropKind(11)> {};
72-
struct rt_prop8 : detail::run_time_property_key<rt_prop8, fakePropKind(12)> {};
73-
struct rt_prop9 : detail::run_time_property_key<rt_prop9, fakePropKind(13)> {};
74-
struct rt_prop10 : detail::run_time_property_key<rt_prop10, fakePropKind(14)> {};
75-
struct rt_prop11 : detail::run_time_property_key<rt_prop11, fakePropKind(15)> {};
76-
struct rt_prop12 : detail::run_time_property_key<rt_prop12, fakePropKind(16)> {};
77-
struct rt_prop13 : detail::run_time_property_key<rt_prop13, fakePropKind(17)> {};
78-
struct rt_prop14 : detail::run_time_property_key<rt_prop14, fakePropKind(18)> {};
79-
struct rt_prop15 : detail::run_time_property_key<rt_prop15, fakePropKind(19)> {};
80-
struct rt_prop16 : detail::run_time_property_key<rt_prop16, fakePropKind(20)> {};
81-
struct rt_prop17 : detail::run_time_property_key<rt_prop17, fakePropKind(21)> {};
82-
struct rt_prop18 : detail::run_time_property_key<rt_prop18, fakePropKind(22)> {};
83-
struct rt_prop19 : detail::run_time_property_key<rt_prop19, fakePropKind(23)> {};
84-
struct rt_prop20 : detail::run_time_property_key<rt_prop20, fakePropKind(24)> {};
85-
struct rt_prop21 : detail::run_time_property_key<rt_prop21, fakePropKind(25)> {};
86-
struct rt_prop22 : detail::run_time_property_key<rt_prop22, fakePropKind(26)> {};
87-
struct rt_prop23 : detail::run_time_property_key<rt_prop23, fakePropKind(27)> {};
88-
struct rt_prop24 : detail::run_time_property_key<rt_prop24, fakePropKind(28)> {};
89-
struct rt_prop25 : detail::run_time_property_key<rt_prop25, fakePropKind(29)> {};
90-
struct rt_prop26 : detail::run_time_property_key<rt_prop26, fakePropKind(30)> {};
91-
struct rt_prop27 : detail::run_time_property_key<rt_prop27, fakePropKind(31)> {};
92-
struct rt_prop28 : detail::run_time_property_key<rt_prop28, fakePropKind(32)> {};
93-
struct rt_prop29 : detail::run_time_property_key<rt_prop29, fakePropKind(33)> {};
94-
struct rt_prop30 : detail::run_time_property_key<rt_prop30, fakePropKind(34)> {};
95-
struct rt_prop31 : detail::run_time_property_key<rt_prop31, fakePropKind(35)> {};
96-
struct rt_prop32 : detail::run_time_property_key<rt_prop32, fakePropKind(36)> {};
97-
struct rt_prop33 : detail::run_time_property_key<rt_prop33, fakePropKind(37)> {};
65+
struct rt_prop1 : detail::run_time_property_key<rt_prop1, fakePropKind(5)> { int x; };
66+
struct rt_prop2 : detail::run_time_property_key<rt_prop2, fakePropKind(6)> { int x; };
67+
struct rt_prop3 : detail::run_time_property_key<rt_prop3, fakePropKind(7)> { int x; };
68+
struct rt_prop4 : detail::run_time_property_key<rt_prop4, fakePropKind(8)> { int x; };
69+
struct rt_prop5 : detail::run_time_property_key<rt_prop5, fakePropKind(9)> { int x; };
70+
struct rt_prop6 : detail::run_time_property_key<rt_prop6, fakePropKind(10)> { int x; };
71+
struct rt_prop7 : detail::run_time_property_key<rt_prop7, fakePropKind(11)> { int x; };
72+
struct rt_prop8 : detail::run_time_property_key<rt_prop8, fakePropKind(12)> { int x; };
73+
struct rt_prop9 : detail::run_time_property_key<rt_prop9, fakePropKind(13)> { int x; };
74+
struct rt_prop10 : detail::run_time_property_key<rt_prop10, fakePropKind(14)> { int x; };
75+
struct rt_prop11 : detail::run_time_property_key<rt_prop11, fakePropKind(15)> { int x; };
76+
struct rt_prop12 : detail::run_time_property_key<rt_prop12, fakePropKind(16)> { int x; };
77+
struct rt_prop13 : detail::run_time_property_key<rt_prop13, fakePropKind(17)> { int x; };
78+
struct rt_prop14 : detail::run_time_property_key<rt_prop14, fakePropKind(18)> { int x; };
79+
struct rt_prop15 : detail::run_time_property_key<rt_prop15, fakePropKind(19)> { int x; };
80+
struct rt_prop16 : detail::run_time_property_key<rt_prop16, fakePropKind(20)> { int x; };
81+
struct rt_prop17 : detail::run_time_property_key<rt_prop17, fakePropKind(21)> { int x; };
82+
struct rt_prop18 : detail::run_time_property_key<rt_prop18, fakePropKind(22)> { int x; };
83+
struct rt_prop19 : detail::run_time_property_key<rt_prop19, fakePropKind(23)> { int x; };
84+
struct rt_prop20 : detail::run_time_property_key<rt_prop20, fakePropKind(24)> { int x; };
85+
struct rt_prop21 : detail::run_time_property_key<rt_prop21, fakePropKind(25)> { int x; };
86+
struct rt_prop22 : detail::run_time_property_key<rt_prop22, fakePropKind(26)> { int x; };
87+
struct rt_prop23 : detail::run_time_property_key<rt_prop23, fakePropKind(27)> { int x; };
88+
struct rt_prop24 : detail::run_time_property_key<rt_prop24, fakePropKind(28)> { int x; };
89+
struct rt_prop25 : detail::run_time_property_key<rt_prop25, fakePropKind(29)> { int x; };
90+
struct rt_prop26 : detail::run_time_property_key<rt_prop26, fakePropKind(30)> { int x; };
91+
struct rt_prop27 : detail::run_time_property_key<rt_prop27, fakePropKind(31)> { int x; };
92+
struct rt_prop28 : detail::run_time_property_key<rt_prop28, fakePropKind(32)> { int x; };
93+
struct rt_prop29 : detail::run_time_property_key<rt_prop29, fakePropKind(33)> { int x; };
94+
struct rt_prop30 : detail::run_time_property_key<rt_prop30, fakePropKind(34)> { int x; };
95+
struct rt_prop31 : detail::run_time_property_key<rt_prop31, fakePropKind(35)> { int x; };
96+
struct rt_prop32 : detail::run_time_property_key<rt_prop32, fakePropKind(36)> { int x; };
97+
struct rt_prop33 : detail::run_time_property_key<rt_prop33, fakePropKind(37)> { int x; };
9898
// clang-format on
9999

100100
using foo_key = foo;

0 commit comments

Comments
 (0)