Skip to content

Commit e8be8fb

Browse files
[SYCL] Don't use boost/mp11 for properties filtering (#16076)
We want to get rid of it for the upstreaming purposes.
1 parent adc98e3 commit e8be8fb

File tree

2 files changed

+53
-17
lines changed

2 files changed

+53
-17
lines changed

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

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
#include <sycl/ext/oneapi/properties/property_value.hpp>
2020
#include <sycl/pointers.hpp>
2121

22-
#include <sycl/detail/boost/mp11/algorithm.hpp>
23-
2422
#include <cstddef>
2523
#include <string_view>
2624
#include <tuple>
@@ -56,16 +54,10 @@ template <typename... Ts>
5654
using contains_alignment =
5755
detail::ContainsProperty<alignment_key, std::tuple<Ts...>>;
5856

59-
// properties filter
60-
template <typename property_list, template <class...> typename filter>
61-
using PropertiesFilter =
62-
sycl::detail::boost::mp11::mp_copy_if<property_list, filter>;
63-
6457
// filter properties that are applied on annotations
65-
template <typename... Props>
66-
using annotation_filter =
67-
properties<PropertiesFilter<detail::properties_type_list<Props...>,
68-
propagateToPtrAnnotation>>;
58+
template <typename PropertyListTy>
59+
using annotation_filter = decltype(filter_properties<propagateToPtrAnnotation>(
60+
std::declval<PropertyListTy>()));
6961
} // namespace detail
7062

7163
template <typename I, typename P> struct annotationHelper {};
@@ -110,8 +102,8 @@ class annotated_ref<T, detail::properties_t<Props...>> {
110102
// implicit conversion with annotaion
111103
operator T() const {
112104
#ifdef __SYCL_DEVICE_ONLY__
113-
return annotationHelper<T, detail::annotation_filter<Props...>>::load(
114-
m_Ptr);
105+
return annotationHelper<
106+
T, detail::annotation_filter<property_list_t>>::load(m_Ptr);
115107
#else
116108
return *m_Ptr;
117109
#endif
@@ -121,8 +113,8 @@ class annotated_ref<T, detail::properties_t<Props...>> {
121113
template <class O, typename = std::enable_if_t<!detail::is_ann_ref_v<O>>>
122114
T operator=(O &&Obj) const {
123115
#ifdef __SYCL_DEVICE_ONLY__
124-
return annotationHelper<T, detail::annotation_filter<Props...>>::store(
125-
m_Ptr, Obj);
116+
return annotationHelper<
117+
T, detail::annotation_filter<property_list_t>>::store(m_Ptr, Obj);
126118
#else
127119
return *m_Ptr = std::forward<O>(Obj);
128120
#endif
@@ -387,8 +379,8 @@ __SYCL_TYPE(annotated_ptr) annotated_ptr<T, detail::properties_t<Props...>> {
387379

388380
T *get() const noexcept {
389381
#ifdef __SYCL_DEVICE_ONLY__
390-
return annotationHelper<T, detail::annotation_filter<Props...>>::annotate(
391-
m_Ptr);
382+
return annotationHelper<
383+
T, detail::annotation_filter<property_list_t>>::annotate(m_Ptr);
392384
#else
393385
return m_Ptr;
394386
#endif

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,50 @@ struct ConditionalPropertyMetaInfo
305305
: std::conditional_t<Condition, PropertyMetaInfo<PropT>,
306306
IgnoredPropertyMetaInfo> {};
307307

308+
template <template <typename> typename predicate, typename... property_tys>
309+
struct filter_properties_impl {
310+
static constexpr auto idx_info = []() constexpr {
311+
constexpr int N = sizeof...(property_tys);
312+
std::array<int, N> indexes{};
313+
int num_matched = 0;
314+
int idx = 0;
315+
(((predicate<property_tys>::value ? indexes[num_matched++] = idx++ : idx++),
316+
...));
317+
318+
return std::pair{indexes, num_matched};
319+
}();
320+
321+
// Helper to convert constexpr indices values to an std::index_sequence type.
322+
// Values -> type is the key here.
323+
template <int... Idx>
324+
static constexpr auto idx_seq(std::integer_sequence<int, Idx...>) {
325+
return std::integer_sequence<int, idx_info.first[Idx]...>{};
326+
}
327+
328+
using selected_idx_seq =
329+
decltype(idx_seq(std::make_integer_sequence<int, idx_info.second>{}));
330+
331+
// Using prop_list_ty so that we don't need to explicitly spell out
332+
// `properties` template parameters' implementation-details.
333+
template <typename prop_list_ty, int... Idxs>
334+
static constexpr auto apply_impl(const prop_list_ty &props,
335+
std::integer_sequence<int, Idxs...>) {
336+
return properties{props.template get_property<
337+
typename nth_type_t<Idxs, property_tys...>::key_t>()...};
338+
}
339+
340+
template <typename prop_list_ty>
341+
static constexpr auto apply(const prop_list_ty &props) {
342+
return apply_impl(props, selected_idx_seq{});
343+
}
344+
};
345+
346+
template <template <typename> typename predicate, typename... property_tys>
347+
constexpr auto filter_properties(
348+
const properties<properties_type_list<property_tys...>> &props) {
349+
return filter_properties_impl<predicate, property_tys...>::apply(props);
350+
}
351+
308352
} // namespace detail
309353
} // namespace ext::oneapi::experimental
310354
} // namespace _V1

0 commit comments

Comments
 (0)