Skip to content

Commit c5845a7

Browse files
[NFCI][SYCL] Remove most uses of ContainsProperty (#16103)
First, `properties` itself has an interface that does exactly that. Second, this trait uses `std::tuple` which is relatively expensive to instantiate and that happens *on top* of the normal `properties` instantation that doesn't use `std::tuple` anymore. Remaining uses are related to `ConflictingProperties` which is ugly enough to be addressed in a separate PR.
1 parent 2e11d26 commit c5845a7

File tree

5 files changed

+51
-58
lines changed

5 files changed

+51
-58
lines changed

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

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -319,28 +319,25 @@ struct propagateToPtrAnnotation<buffer_location_key> : std::true_type {};
319319
//===----------------------------------------------------------------------===//
320320
//
321321
namespace detail {
322-
template <typename... Args> struct checkValidFPGAPropertySet {
323-
using list = std::tuple<Args...>;
324-
static constexpr bool has_BufferLocation =
325-
ContainsProperty<buffer_location_key, list>::value;
322+
template <typename property_list_t> struct checkValidFPGAPropertySet {
323+
template <typename... Keys>
324+
static constexpr bool has_one_of =
325+
((property_list_t::template has_property<Keys>() || ...));
326+
327+
static constexpr bool has_BufferLocation = has_one_of<buffer_location_key>;
326328

327329
static constexpr bool has_InterfaceConfig =
328-
ContainsProperty<awidth_key, list>::value ||
329-
ContainsProperty<dwidth_key, list>::value ||
330-
ContainsProperty<latency_key, list>::value ||
331-
ContainsProperty<read_write_mode_key, list>::value ||
332-
ContainsProperty<maxburst_key, list>::value ||
333-
ContainsProperty<wait_request_key, list>::value;
330+
has_one_of<awidth_key, dwidth_key, latency_key, read_write_mode_key,
331+
maxburst_key, wait_request_key>;
334332

335333
static constexpr bool value = !(!has_BufferLocation && has_InterfaceConfig);
336334
};
337335

338-
template <typename... Args> struct checkHasConduitAndRegisterMap {
339-
using list = std::tuple<Args...>;
336+
template <typename property_list_t> struct checkHasConduitAndRegisterMap {
340337
static constexpr bool has_Conduit =
341-
ContainsProperty<conduit_key, list>::value;
338+
property_list_t::template has_property<conduit_key>();
342339
static constexpr bool has_RegisterMap =
343-
ContainsProperty<register_map_key, list>::value;
340+
property_list_t::template has_property<register_map_key>();
344341
static constexpr bool value = !(has_Conduit && has_RegisterMap);
345342
};
346343
} // namespace detail

sycl/include/sycl/ext/oneapi/experimental/annotated_arg/annotated_arg.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,13 @@ __SYCL_TYPE(annotated_arg) annotated_arg<T *, detail::properties_t<Props...>> {
214214
"The property list contains invalid property.");
215215
// check the set if FPGA specificed properties are used
216216
static constexpr bool hasValidFPGAProperties =
217-
detail::checkValidFPGAPropertySet<Props...>::value;
217+
detail::checkValidFPGAPropertySet<property_list_t>::value;
218218
static_assert(hasValidFPGAProperties,
219219
"FPGA Interface properties (i.e. awidth, dwidth, etc.) "
220220
"can only be set with BufferLocation together.");
221221
// check if conduit and register_map properties are specified together
222222
static constexpr bool hasConduitAndRegisterMapProperties =
223-
detail::checkHasConduitAndRegisterMap<Props...>::value;
223+
detail::checkHasConduitAndRegisterMap<property_list_t>::value;
224224
static_assert(hasConduitAndRegisterMapProperties,
225225
"The properties conduit and register_map cannot be "
226226
"specified at the same time.");
@@ -447,13 +447,13 @@ __SYCL_TYPE(annotated_arg) annotated_arg<T, detail::properties_t<Props...>> {
447447
"The property list contains invalid property.");
448448
// check the set if FPGA specificed properties are used
449449
static constexpr bool hasValidFPGAProperties =
450-
detail::checkValidFPGAPropertySet<Props...>::value;
450+
detail::checkValidFPGAPropertySet<property_list_t>::value;
451451
static_assert(hasValidFPGAProperties,
452452
"FPGA Interface properties (i.e. awidth, dwidth, etc.) "
453453
"can only be set with BufferLocation together.");
454454
// check if conduit and register_map properties are specified together
455455
static constexpr bool hasConduitAndRegisterMapProperties =
456-
detail::checkHasConduitAndRegisterMap<Props...>::value;
456+
detail::checkHasConduitAndRegisterMap<property_list_t>::value;
457457
static_assert(hasConduitAndRegisterMapProperties,
458458
"The properties conduit and register_map cannot be "
459459
"specified at the same time.");

sycl/include/sycl/ext/oneapi/experimental/annotated_ptr/annotated_ptr.hpp

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ template <class T>
5050
constexpr bool is_ann_ref_v =
5151
is_ann_ref_impl<std::remove_reference_t<T>>::value;
5252

53-
template <typename... Ts>
54-
using contains_alignment =
55-
detail::ContainsProperty<alignment_key, std::tuple<Ts...>>;
56-
5753
// filter properties that are applied on annotations
5854
template <typename PropertyListTy>
5955
using annotation_filter = decltype(filter_properties<propagateToPtrAnnotation>(
@@ -392,69 +388,69 @@ __SYCL_TYPE(annotated_ptr) annotated_ptr<T, detail::properties_t<Props...>> {
392388
// turned off for these operators to make sure the complete error notes are
393389
// printed
394390
// clang-format off
395-
template <bool has_alignment = detail::contains_alignment<Props...>::value,
391+
template <bool has_alignment = property_list_t::template has_property<alignment_key>(),
396392
class = std::enable_if_t<!has_alignment>>
397393
reference operator[](std::ptrdiff_t idx) const noexcept {
398394
return reference(m_Ptr + idx);
399395
}
400396

401-
template <bool has_alignment = detail::contains_alignment<Props...>::value,
397+
template <bool has_alignment = property_list_t::template has_property<alignment_key>(),
402398
class = std::enable_if_t<has_alignment>>
403399
auto operator[](std::ptrdiff_t idx) const noexcept -> decltype("operator[] is not available when alignment is specified!") = delete;
404400

405-
template <bool has_alignment = detail::contains_alignment<Props...>::value,
401+
template <bool has_alignment = property_list_t::template has_property<alignment_key>(),
406402
class = std::enable_if_t<!has_alignment>>
407403
annotated_ptr operator+(size_t offset) const noexcept {
408404
return annotated_ptr(m_Ptr + offset);
409405
}
410406

411-
template <bool has_alignment = detail::contains_alignment<Props...>::value,
407+
template <bool has_alignment = property_list_t::template has_property<alignment_key>(),
412408
class = std::enable_if_t<has_alignment>>
413409
auto operator+(size_t offset) const noexcept -> decltype("operator+ is not available when alignment is specified!") = delete;
414410

415-
template <bool has_alignment = detail::contains_alignment<Props...>::value,
411+
template <bool has_alignment = property_list_t::template has_property<alignment_key>(),
416412
class = std::enable_if_t<!has_alignment>>
417413
annotated_ptr &operator++() noexcept {
418414
m_Ptr += 1;
419415
return *this;
420416
}
421417

422-
template <bool has_alignment = detail::contains_alignment<Props...>::value,
418+
template <bool has_alignment = property_list_t::template has_property<alignment_key>(),
423419
class = std::enable_if_t<has_alignment>>
424420
auto operator++() noexcept -> decltype("operator++ is not available when alignment is specified!") = delete;
425421

426-
template <bool has_alignment = detail::contains_alignment<Props...>::value,
422+
template <bool has_alignment = property_list_t::template has_property<alignment_key>(),
427423
class = std::enable_if_t<!has_alignment>>
428424
annotated_ptr operator++(int) noexcept {
429425
auto tmp = *this;
430426
m_Ptr += 1;
431427
return tmp;
432428
}
433429

434-
template <bool has_alignment = detail::contains_alignment<Props...>::value,
430+
template <bool has_alignment = property_list_t::template has_property<alignment_key>(),
435431
class = std::enable_if_t<has_alignment>>
436432
auto operator++(int) noexcept -> decltype("operator++ is not available when alignment is specified!") = delete;
437433

438-
template <bool has_alignment = detail::contains_alignment<Props...>::value,
434+
template <bool has_alignment = property_list_t::template has_property<alignment_key>(),
439435
class = std::enable_if_t<!has_alignment>>
440436
annotated_ptr &operator--() noexcept {
441437
m_Ptr -= 1;
442438
return *this;
443439
}
444440

445-
template <bool has_alignment = detail::contains_alignment<Props...>::value,
441+
template <bool has_alignment = property_list_t::template has_property<alignment_key>(),
446442
class = std::enable_if_t<has_alignment>>
447443
auto operator--() noexcept -> decltype("operator-- is not available when alignment is specified!") = delete;
448444

449-
template <bool has_alignment = detail::contains_alignment<Props...>::value,
445+
template <bool has_alignment = property_list_t::template has_property<alignment_key>(),
450446
class = std::enable_if_t<!has_alignment>>
451447
annotated_ptr operator--(int) noexcept {
452448
auto tmp = *this;
453449
m_Ptr -= 1;
454450
return tmp;
455451
}
456452

457-
template <bool has_alignment = detail::contains_alignment<Props...>::value,
453+
template <bool has_alignment = property_list_t::template has_property<alignment_key>(),
458454
class = std::enable_if_t<has_alignment>>
459455
auto operator--(int) noexcept -> decltype("operator-- is not available when alignment is specified!") = delete;
460456

@@ -485,13 +481,13 @@ __SYCL_TYPE(annotated_ptr) annotated_ptr<T, detail::properties_t<Props...>> {
485481
"The property list contains invalid property.");
486482
// check the set if FPGA specificed properties are used
487483
static constexpr bool hasValidFPGAProperties =
488-
detail::checkValidFPGAPropertySet<Props...>::value;
484+
detail::checkValidFPGAPropertySet<property_list_t>::value;
489485
static_assert(hasValidFPGAProperties,
490486
"FPGA Interface properties (i.e. awidth, dwidth, etc.) "
491487
"can only be set with BufferLocation together.");
492488
// check if conduit and register_map properties are specified together
493489
static constexpr bool hasConduitAndRegisterMapProperties =
494-
detail::checkHasConduitAndRegisterMap<Props...>::value;
490+
detail::checkHasConduitAndRegisterMap<property_list_t>::value;
495491
static_assert(hasConduitAndRegisterMapProperties,
496492
"The properties conduit and register_map cannot be "
497493
"specified at the same time.");

sycl/include/sycl/ext/oneapi/experimental/annotated_ptr/annotated_ptr_properties.hpp

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,24 +55,26 @@ struct PropertyMetaInfo<usm_kind_key::value_t<Kind>> {
5555
static constexpr sycl::usm::alloc value = Kind;
5656
};
5757

58-
template <typename PropertyListT> struct IsUsmKindDevice : std::false_type {};
59-
template <typename... Props>
60-
struct IsUsmKindDevice<detail::properties_t<Props...>>
61-
: detail::ContainsProperty<std::remove_const_t<decltype(usm_kind_device)>,
62-
std::tuple<Props...>> {};
63-
64-
template <typename PropertyListT> struct IsUsmKindHost : std::false_type {};
65-
template <typename... Props>
66-
struct IsUsmKindHost<detail::properties_t<Props...>>
67-
: detail::ContainsProperty<std::remove_const_t<decltype(usm_kind_host)>,
68-
std::tuple<Props...>> {};
69-
70-
template <typename PropertyListT> struct IsUsmKindShared : std::false_type {};
71-
template <typename... Props>
72-
struct IsUsmKindShared<detail::properties_t<Props...>>
73-
: detail::ContainsProperty<std::remove_const_t<decltype(usm_kind_shared)>,
74-
std::tuple<Props...>> {};
58+
template <typename PropertyListT, sycl::usm::alloc Kind>
59+
inline constexpr bool is_usm_kind = []() constexpr {
60+
if constexpr (PropertyListT::template has_property<usm_kind_key>())
61+
return PropertyListT::template get_property<usm_kind_key>() ==
62+
usm_kind<Kind>;
63+
else
64+
return false;
65+
}();
7566

67+
template <typename PropertyListT>
68+
struct IsUsmKindDevice
69+
: std::bool_constant<is_usm_kind<PropertyListT, sycl::usm::alloc::device>> {
70+
};
71+
template <typename PropertyListT>
72+
struct IsUsmKindHost
73+
: std::bool_constant<is_usm_kind<PropertyListT, sycl::usm::alloc::host>> {};
74+
template <typename PropertyListT>
75+
struct IsUsmKindShared
76+
: std::bool_constant<is_usm_kind<PropertyListT, sycl::usm::alloc::shared>> {
77+
};
7678
} // namespace detail
7779

7880
} // namespace experimental

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,9 @@ using MergeUsmKind =
3232
decltype(properties{usm_kind<Kind>})>;
3333

3434
// Check if a property list contains the a certain property
35-
template <typename PropKey, typename PropertyListT> struct HasProperty {};
36-
37-
template <typename PropKey, typename... Props>
38-
struct HasProperty<PropKey, detail::properties_t<Props...>>
39-
: detail::ContainsProperty<PropKey, std::tuple<Props...>> {};
35+
template <typename PropKey, typename PropertyListT>
36+
struct HasProperty
37+
: std::bool_constant<PropertyListT::template has_property<PropKey>()> {};
4038

4139
template <typename PropertyListT>
4240
using HasAlign = HasProperty<alignment_key, PropertyListT>;

0 commit comments

Comments
 (0)