Skip to content

Commit

Permalink
[NFC][SYCL] Refactor all_props_are_keys_of (#16141)
Browse files Browse the repository at this point in the history
First, rename it, because it's just the accident that all its current
users only supply runtime properties that just happen to be property
keys in addition to being property values.

Second, use C++17.
  • Loading branch information
aelovikov-intel authored Nov 21, 2024
1 parent 3edd618 commit e087d89
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 51 deletions.
39 changes: 8 additions & 31 deletions sycl/include/sycl/ext/oneapi/properties/properties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,38 +399,15 @@ constexpr auto get_property_or(default_t value) {
return value;
}

// helper: check_all_props_are_keys_of
template <typename SyclT> constexpr bool check_all_props_are_keys_of() {
return true;
}

template <typename SyclT, typename FirstProp, typename... RestProps>
constexpr bool check_all_props_are_keys_of() {
return ext::oneapi::experimental::is_property_key_of<FirstProp,
SyclT>::value &&
check_all_props_are_keys_of<SyclT, RestProps...>();
}

// all_props_are_keys_of
template <typename SyclT, typename PropertiesT>
struct all_props_are_keys_of : std::false_type {};

template <typename SyclT>
struct all_props_are_keys_of<SyclT,
ext::oneapi::experimental::empty_properties_t>
: std::true_type {};

template <typename SyclT, typename PropT>
struct all_props_are_keys_of<
SyclT, ext::oneapi::experimental::detail::properties_t<PropT>>
: std::bool_constant<
ext::oneapi::experimental::is_property_key_of<PropT, SyclT>::value> {
};

template <typename SyclT, typename PropListT>
struct all_are_properties_of : std::false_type /* not a properties list */ {};
template <typename SyclT, typename... Props>
struct all_props_are_keys_of<
SyclT, ext::oneapi::experimental::detail::properties_t<Props...>>
: std::bool_constant<check_all_props_are_keys_of<SyclT, Props...>()> {};
struct all_are_properties_of<SyclT, properties_t<Props...>>
: std::bool_constant<((is_property_value_of<Props, SyclT>::value && ...))> {
};
template <typename SyclT, typename PropListT>
inline constexpr bool all_are_properties_of_v =
all_are_properties_of<SyclT, PropListT>::value;

} // namespace detail
} // namespace ext::oneapi::experimental
Expand Down
30 changes: 10 additions & 20 deletions sycl/include/sycl/kernel_bundle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1058,12 +1058,9 @@ build_from_source(kernel_bundle<bundle_state::ext_oneapi_source> &SourceKB,
/////////////////////////
// syclex::create_kernel_bundle_from_source
/////////////////////////
template <
typename PropertyListT = empty_properties_t,
typename = std::enable_if_t<
is_property_list_v<PropertyListT> &&
detail::all_props_are_keys_of<detail::create_bundle_from_source_props,
PropertyListT>::value>>
template <typename PropertyListT = empty_properties_t,
typename = std::enable_if_t<detail::all_are_properties_of_v<
detail::create_bundle_from_source_props, PropertyListT>>>
kernel_bundle<bundle_state::ext_oneapi_source> create_kernel_bundle_from_source(
const context &SyclContext, source_language Language,
const std::string &Source, PropertyListT props = {}) {
Expand All @@ -1077,12 +1074,9 @@ kernel_bundle<bundle_state::ext_oneapi_source> create_kernel_bundle_from_source(
}

#if (!defined(_HAS_STD_BYTE) || _HAS_STD_BYTE != 0)
template <
typename PropertyListT = empty_properties_t,
typename = std::enable_if_t<
is_property_list_v<PropertyListT> &&
detail::all_props_are_keys_of<detail::create_bundle_from_source_props,
PropertyListT>::value>>
template <typename PropertyListT = empty_properties_t,
typename = std::enable_if_t<detail::all_are_properties_of_v<
detail::create_bundle_from_source_props, PropertyListT>>>
kernel_bundle<bundle_state::ext_oneapi_source> create_kernel_bundle_from_source(
const context &SyclContext, source_language Language,
const std::vector<std::byte> &Bytes, PropertyListT props = {}) {
Expand All @@ -1101,10 +1095,8 @@ kernel_bundle<bundle_state::ext_oneapi_source> create_kernel_bundle_from_source(
/////////////////////////

template <typename PropertyListT = empty_properties_t,
typename = std::enable_if_t<
is_property_list_v<PropertyListT> &&
detail::all_props_are_keys_of<detail::build_source_bundle_props,
PropertyListT>::value>>
typename = std::enable_if_t<detail::all_are_properties_of_v<
detail::build_source_bundle_props, PropertyListT>>>

kernel_bundle<bundle_state::executable>
build(kernel_bundle<bundle_state::ext_oneapi_source> &SourceKB,
Expand All @@ -1127,10 +1119,8 @@ build(kernel_bundle<bundle_state::ext_oneapi_source> &SourceKB,
}

template <typename PropertyListT = empty_properties_t,
typename = std::enable_if_t<
is_property_list_v<PropertyListT> &&
detail::all_props_are_keys_of<detail::build_source_bundle_props,
PropertyListT>::value>>
typename = std::enable_if_t<detail::all_are_properties_of_v<
detail::build_source_bundle_props, PropertyListT>>>
kernel_bundle<bundle_state::executable>
build(kernel_bundle<bundle_state::ext_oneapi_source> &SourceKB,
PropertyListT props = {}) {
Expand Down

0 comments on commit e087d89

Please sign in to comment.