Skip to content

Commit 42e63c1

Browse files
[NFCI][SYCL] More properties-related refactoring (#16126)
* Modify `detail::ConflictingProperties` to accept `properties` list instead of `std::tuple` with individual property values * Remove some "useless" helpers * Change `detail::ValueOrDefault` type-trait to `detail::get_property_or` as it seems a better interface (and can, in theory, work with runtime properties too)
1 parent 8ad42d5 commit 42e63c1

File tree

9 files changed

+159
-281
lines changed

9 files changed

+159
-281
lines changed

sycl/include/sycl/ext/intel/experimental/grf_size_properties.hpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,29 +56,26 @@ template <typename Properties>
5656
struct ConflictingProperties<sycl::ext::intel::experimental::grf_size_key,
5757
Properties>
5858
: std::bool_constant<
59-
ContainsProperty<
60-
sycl::ext::intel::experimental::grf_size_automatic_key,
61-
Properties>::value ||
62-
ContainsProperty<sycl::detail::register_alloc_mode_key,
63-
Properties>::value> {};
59+
Properties::template has_property<
60+
sycl::ext::intel::experimental::grf_size_automatic_key>() ||
61+
Properties::template has_property<
62+
sycl::detail::register_alloc_mode_key>()> {};
6463

6564
template <typename Properties>
6665
struct ConflictingProperties<
6766
sycl::ext::intel::experimental::grf_size_automatic_key, Properties>
68-
: std::bool_constant<
69-
ContainsProperty<sycl::ext::intel::experimental::grf_size_key,
70-
Properties>::value ||
71-
ContainsProperty<sycl::detail::register_alloc_mode_key,
72-
Properties>::value> {};
67+
: std::bool_constant<Properties::template has_property<
68+
sycl::ext::intel::experimental::grf_size_key>() ||
69+
Properties::template has_property<
70+
sycl::detail::register_alloc_mode_key>()> {};
7371

7472
template <typename Properties>
7573
struct ConflictingProperties<sycl::detail::register_alloc_mode_key, Properties>
7674
: std::bool_constant<
77-
ContainsProperty<sycl::ext::intel::experimental::grf_size_key,
78-
Properties>::value ||
79-
ContainsProperty<
80-
sycl::ext::intel::experimental::grf_size_automatic_key,
81-
Properties>::value> {};
75+
Properties::template has_property<
76+
sycl::ext::intel::experimental::grf_size_key>() ||
77+
Properties::template has_property<
78+
sycl::ext::intel::experimental::grf_size_automatic_key>()> {};
8279

8380
} // namespace ext::oneapi::experimental::detail
8481
} // namespace _V1

sycl/include/sycl/ext/intel/experimental/pipes.hpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -376,21 +376,29 @@ class pipe : public pipe_base {
376376
static constexpr int32_t m_Capacity = _min_capacity;
377377

378378
static constexpr int32_t m_ready_latency =
379-
oneapi::experimental::detail::ValueOrDefault<
380-
_propertiesT, ready_latency_key>::template get<int32_t>(0);
379+
oneapi::experimental::detail::get_property_or<ready_latency_key,
380+
_propertiesT>(
381+
ready_latency<0>)
382+
.value;
383+
381384
static constexpr int32_t m_bits_per_symbol =
382-
oneapi::experimental::detail::ValueOrDefault<
383-
_propertiesT, bits_per_symbol_key>::template get<int32_t>(8);
385+
oneapi::experimental::detail::get_property_or<bits_per_symbol_key,
386+
_propertiesT>(
387+
bits_per_symbol<8>)
388+
.value;
384389
static constexpr bool m_uses_valid =
385-
oneapi::experimental::detail::ValueOrDefault<
386-
_propertiesT, uses_valid_key>::template get<bool>(true);
390+
oneapi::experimental::detail::get_property_or<uses_valid_key,
391+
_propertiesT>(uses_valid_on)
392+
.value;
387393
static constexpr bool m_first_symbol_in_high_order_bits =
388-
oneapi::experimental::detail::ValueOrDefault<
389-
_propertiesT,
390-
first_symbol_in_high_order_bits_key>::template get<int32_t>(0);
391-
static constexpr protocol_name m_protocol = oneapi::experimental::detail::
392-
ValueOrDefault<_propertiesT, protocol_key>::template get<protocol_name>(
393-
protocol_name::avalon_streaming_uses_ready);
394+
oneapi::experimental::detail::get_property_or<
395+
first_symbol_in_high_order_bits_key, _propertiesT>(
396+
first_symbol_in_high_order_bits_off)
397+
.value;
398+
static constexpr protocol_name m_protocol =
399+
oneapi::experimental::detail::get_property_or<protocol_key, _propertiesT>(
400+
protocol_avalon_streaming_uses_ready)
401+
.value;
394402

395403
public:
396404
static constexpr struct ConstantPipeStorageExp m_Storage = {

sycl/include/sycl/ext/intel/experimental/task_sequence.hpp

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -109,23 +109,28 @@ class task_sequence<
109109
__spv::__spirv_TaskSequenceINTEL *taskSequence;
110110
#endif
111111
static constexpr int32_t pipelined =
112-
oneapi::experimental::detail::ValueOrDefault<
113-
property_list_t, pipelined_key>::template get<int32_t>(-1);
114-
static constexpr int32_t fpga_cluster =
115-
has_property<fpga_cluster_key>()
116-
? static_cast<
117-
typename std::underlying_type<fpga_cluster_options_enum>::type>(
118-
oneapi::experimental::detail::ValueOrDefault<property_list_t,
119-
fpga_cluster_key>::
120-
template get<fpga_cluster_options_enum>(
121-
fpga_cluster_options_enum::stall_free))
122-
: -1;
112+
oneapi::experimental::detail::get_property_or<pipelined_key,
113+
property_list_t>(
114+
intel::experimental::pipelined<-1>)
115+
.value;
116+
static constexpr int32_t fpga_cluster = []() constexpr {
117+
if constexpr (has_property<fpga_cluster_key>())
118+
return static_cast<
119+
typename std::underlying_type<fpga_cluster_options_enum>::type>(
120+
get_property<fpga_cluster_key>().value);
121+
else
122+
return -1;
123+
}();
123124
static constexpr uint32_t response_capacity =
124-
oneapi::experimental::detail::ValueOrDefault<
125-
property_list_t, response_capacity_key>::template get<uint32_t>(0);
125+
oneapi::experimental::detail::get_property_or<response_capacity_key,
126+
property_list_t>(
127+
intel::experimental::response_capacity<0>)
128+
.value;
126129
static constexpr uint32_t invocation_capacity =
127-
oneapi::experimental::detail::ValueOrDefault<
128-
property_list_t, invocation_capacity_key>::template get<uint32_t>(0);
130+
oneapi::experimental::detail::get_property_or<invocation_capacity_key,
131+
property_list_t>(
132+
intel::experimental::invocation_capacity<0>)
133+
.value;
129134
};
130135

131136
} // namespace ext::intel::experimental

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

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ template <typename propertyListA = empty_properties_t,
4141
std::enable_if_t<
4242
detail::CheckTAndPropLists<void, propertyListA, propertyListB>::value,
4343
annotated_ptr<void, propertyListB>>
44-
aligned_alloc_annotated(size_t alignment, size_t numBytes,
45-
const device &syclDevice, const context &syclContext,
46-
sycl::usm::alloc kind,
44+
aligned_alloc_annotated(size_t align, size_t numBytes, const device &syclDevice,
45+
const context &syclContext, sycl::usm::alloc kind,
4746
const propertyListA &propList = propertyListA{}) {
4847
detail::ValidAllocPropertyList<void, propertyListA>::value;
4948

@@ -53,12 +52,12 @@ aligned_alloc_annotated(size_t alignment, size_t numBytes,
5352
static_cast<void>(propList);
5453

5554
constexpr size_t alignFromPropList =
56-
detail::GetAlignFromPropList<propertyListA>::value;
55+
detail::get_property_or<alignment_key, propertyListA>(alignment<0>).value;
5756
const property_list &usmPropList = get_usm_property_list<propertyListA>();
5857

59-
if constexpr (detail::HasUsmKind<propertyListA>::value) {
58+
if constexpr (propertyListA::template has_property<usm_kind_key>()) {
6059
constexpr sycl::usm::alloc usmKind =
61-
detail::GetUsmKindFromPropList<propertyListA>::value;
60+
propertyListA::template get_property<usm_kind_key>().value;
6261
if (usmKind != kind) {
6362
throw sycl::exception(
6463
sycl::make_error_code(sycl::errc::invalid),
@@ -72,7 +71,7 @@ aligned_alloc_annotated(size_t alignment, size_t numBytes,
7271
"Unknown USM allocation kind was specified.");
7372

7473
void *rawPtr =
75-
sycl::aligned_alloc(combine_align(alignment, alignFromPropList), numBytes,
74+
sycl::aligned_alloc(combine_align(align, alignFromPropList), numBytes,
7675
syclDevice, syclContext, kind, usmPropList);
7776
return annotated_ptr<void, propertyListB>(rawPtr);
7877
}
@@ -83,9 +82,8 @@ template <typename T, typename propertyListA = empty_properties_t,
8382
std::enable_if_t<
8483
detail::CheckTAndPropLists<T, propertyListA, propertyListB>::value,
8584
annotated_ptr<T, propertyListB>>
86-
aligned_alloc_annotated(size_t alignment, size_t count,
87-
const device &syclDevice, const context &syclContext,
88-
sycl::usm::alloc kind,
85+
aligned_alloc_annotated(size_t align, size_t count, const device &syclDevice,
86+
const context &syclContext, sycl::usm::alloc kind,
8987
const propertyListA &propList = propertyListA{}) {
9088
detail::ValidAllocPropertyList<T, propertyListA>::value;
9189

@@ -95,12 +93,12 @@ aligned_alloc_annotated(size_t alignment, size_t count,
9593
static_cast<void>(propList);
9694

9795
constexpr size_t alignFromPropList =
98-
detail::GetAlignFromPropList<propertyListA>::value;
96+
detail::get_property_or<alignment_key, propertyListA>(alignment<0>).value;
9997
const property_list &usmPropList = get_usm_property_list<propertyListA>();
10098

101-
if constexpr (detail::HasUsmKind<propertyListA>::value) {
99+
if constexpr (propertyListA::template has_property<usm_kind_key>()) {
102100
constexpr sycl::usm::alloc usmKind =
103-
detail::GetUsmKindFromPropList<propertyListA>::value;
101+
propertyListA::template get_property<usm_kind_key>().value;
104102
if (usmKind != kind) {
105103
throw sycl::exception(
106104
sycl::make_error_code(sycl::errc::invalid),
@@ -113,7 +111,7 @@ aligned_alloc_annotated(size_t alignment, size_t count,
113111
throw sycl::exception(sycl::make_error_code(sycl::errc::invalid),
114112
"Unknown USM allocation kind was specified.");
115113

116-
size_t combinedAlign = combine_align(alignment, alignFromPropList);
114+
size_t combinedAlign = combine_align(align, alignFromPropList);
117115
T *rawPtr = sycl::aligned_alloc<T>(combinedAlign, count, syclDevice,
118116
syclContext, kind, usmPropList);
119117
return annotated_ptr<T, propertyListB>(rawPtr);
@@ -212,7 +210,9 @@ std::enable_if_t<
212210
malloc_annotated(size_t numBytes, const device &syclDevice,
213211
const context &syclContext, const propertyListA &propList) {
214212
constexpr sycl::usm::alloc usmKind =
215-
detail::GetUsmKindFromPropList<propertyListA>::value;
213+
detail::get_property_or<usm_kind_key, propertyListA>(
214+
usm_kind<sycl::usm::alloc::unknown>)
215+
.value;
216216
static_assert(usmKind != sycl::usm::alloc::unknown,
217217
"USM kind is not specified. Please specify it as an argument "
218218
"or in the input property list.");
@@ -228,7 +228,9 @@ std::enable_if_t<
228228
malloc_annotated(size_t count, const device &syclDevice,
229229
const context &syclContext, const propertyListA &propList) {
230230
constexpr sycl::usm::alloc usmKind =
231-
detail::GetUsmKindFromPropList<propertyListA>::value;
231+
detail::get_property_or<usm_kind_key, propertyListA>(
232+
usm_kind<sycl::usm::alloc::unknown>)
233+
.value;
232234
static_assert(usmKind != sycl::usm::alloc::unknown,
233235
"USM kind is not specified. Please specify it as an argument "
234236
"or in the input property list.");

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

Lines changed: 6 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -25,52 +25,6 @@ namespace detail {
2525
// Type traits for USM allocation with property support
2626
////
2727

28-
// Merge a property list with the usm_kind property
29-
template <sycl::usm::alloc Kind, typename PropertyListT>
30-
using MergeUsmKind =
31-
detail::merged_properties_t<PropertyListT,
32-
decltype(properties{usm_kind<Kind>})>;
33-
34-
// Check if a property list contains the a certain property
35-
template <typename PropKey, typename PropertyListT>
36-
struct HasProperty
37-
: std::bool_constant<PropertyListT::template has_property<PropKey>()> {};
38-
39-
template <typename PropertyListT>
40-
using HasAlign = HasProperty<alignment_key, PropertyListT>;
41-
template <typename PropertyListT>
42-
using HasUsmKind = HasProperty<usm_kind_key, PropertyListT>;
43-
template <typename PropertyListT>
44-
using HasBufferLocation = HasProperty<buffer_location_key, PropertyListT>;
45-
46-
template <typename PropKey, typename ConstType, typename DefaultPropVal,
47-
typename... Props>
48-
struct GetPropertyValueFromPropList<PropKey, ConstType, DefaultPropVal,
49-
detail::properties_t<Props...>>
50-
: GetPropertyValueFromPropList<PropKey, ConstType, DefaultPropVal,
51-
std::tuple<Props...>> {};
52-
53-
// Get the value of alignment from a property list
54-
// If alignment is not present in the property list, set to default value 0
55-
template <typename PropertyListT>
56-
using GetAlignFromPropList =
57-
GetPropertyValueFromPropList<alignment_key, size_t, decltype(alignment<0>),
58-
PropertyListT>;
59-
// Get the value of usm_kind from a property list
60-
// The usm_kind is sycl::usm::alloc::unknown by default
61-
template <typename PropertyListT>
62-
using GetUsmKindFromPropList =
63-
GetPropertyValueFromPropList<usm_kind_key, sycl::usm::alloc,
64-
decltype(usm_kind<sycl::usm::alloc::unknown>),
65-
PropertyListT>;
66-
// Get the value of buffer_location from a property list
67-
// The buffer location is -1 by default
68-
template <typename PropertyListT>
69-
using GetBufferLocationFromPropList = GetPropertyValueFromPropList<
70-
buffer_location_key, int,
71-
decltype(sycl::ext::intel::experimental::buffer_location<-1>),
72-
PropertyListT>;
73-
7428
// Check if a runtime property is valid
7529
template <typename Prop> struct IsRuntimePropertyValid : std::false_type {};
7630

@@ -143,9 +97,10 @@ struct GetAnnotatedPtrPropertiesWithUsmKind<Kind,
14397
using filtered_input_properties_t =
14498
typename GetCompileTimeProperties<input_properties_t>::type;
14599

146-
static_assert(!HasUsmKind<input_properties_t>::value ||
147-
GetUsmKindFromPropList<input_properties_t>::value == Kind,
148-
"Input property list contains conflicting USM kind.");
100+
static_assert(
101+
detail::get_property_or<usm_kind_key, input_properties_t>(usm_kind<Kind>)
102+
.value == Kind,
103+
"Input property list contains conflicting USM kind.");
149104

150105
using type =
151106
detail::merged_properties_t<filtered_input_properties_t,
@@ -211,10 +166,10 @@ struct CheckTAndPropListsWithUsmKind<Kind, T, detail::properties_t<PropsA...>,
211166
// runtime). Right now only the `buffer_location<N>` has its corresponding USM
212167
// runtime property and is transformable
213168
template <typename PropertyListT> inline property_list get_usm_property_list() {
214-
if constexpr (detail::HasBufferLocation<PropertyListT>::value) {
169+
if constexpr (PropertyListT::template has_property<buffer_location_key>()) {
215170
return property_list{
216171
sycl::ext::intel::experimental::property::usm::buffer_location(
217-
detail::GetBufferLocationFromPropList<PropertyListT>::value)};
172+
PropertyListT::template get_property<buffer_location_key>().value)};
218173
}
219174
return {};
220175
}

0 commit comments

Comments
 (0)