Skip to content

Commit 853917d

Browse files
[SYCL] Don't use boost/mp11 for oneapi properties sorting (#16075)
We want to get rid of it for the upstreaming purposes.
1 parent 80b63a2 commit 853917d

File tree

5 files changed

+62
-58
lines changed

5 files changed

+62
-58
lines changed

sycl/include/sycl/ext/intel/esimd/memory_properties.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ class properties
7777
// Deduction guides
7878
template <typename... PropertyValueTs>
7979
properties(PropertyValueTs... props)
80-
-> properties<typename sycl::ext::oneapi::experimental::detail::Sorted<
81-
PropertyValueTs...>::type>;
80+
-> properties<typename sycl::ext::oneapi::experimental::detail::
81+
properties_sorter<PropertyValueTs...>::type>;
8282
#endif
8383

8484
/// The 'alignment' property is used to specify the alignment of memory

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

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

22+
#include <sycl/detail/boost/mp11/algorithm.hpp>
23+
2224
#include <cstddef>
2325
#include <string_view>
2426
#include <tuple>

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

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,54 @@ constexpr bool properties_are_valid_for_ctad = []() constexpr {
132132

133133
template <typename... property_tys> struct properties_type_list;
134134
template <typename... property_tys> struct invalid_properties_type_list {};
135+
136+
template <typename... property_tys> struct properties_sorter {
137+
// Not using "auto" due to MSVC bug in v19.36 and older. v19.37 and later is
138+
// able to compile "auto" just fine. See https://godbolt.org/z/eW3rjjs7n.
139+
static constexpr std::array<int, sizeof...(property_tys)> sorted_indices =
140+
[]() constexpr {
141+
int idx = 0;
142+
int N = sizeof...(property_tys);
143+
// std::sort isn't constexpr until C++20. Also, it's possible there will
144+
// be a compiler builtin to sort types, in which case we should start
145+
// using that.
146+
std::array to_sort{
147+
std::pair{PropertyID<property_tys>::value, idx++}...};
148+
auto swap_pair = [](auto &x, auto &y) constexpr {
149+
auto tmp_first = x.first;
150+
auto tmp_second = x.second;
151+
x.first = y.first;
152+
x.second = y.second;
153+
y.first = tmp_first;
154+
y.second = tmp_second;
155+
};
156+
for (int i = 0; i < N; ++i)
157+
for (int j = i; j < N; ++j)
158+
if (to_sort[j].first < to_sort[i].first)
159+
swap_pair(to_sort[i], to_sort[j]);
160+
161+
std::array<int, sizeof...(property_tys)> sorted_indices{};
162+
for (int i = 0; i < N; ++i)
163+
sorted_indices[i] = to_sort[i].second;
164+
165+
return sorted_indices;
166+
}();
167+
168+
template <typename> struct helper;
169+
template <int... IdxSeq>
170+
struct helper<std::integer_sequence<int, IdxSeq...>> {
171+
using type = properties_type_list<
172+
nth_type_t<sorted_indices[IdxSeq], property_tys...>...>;
173+
};
174+
175+
using type = typename helper<
176+
std::make_integer_sequence<int, sizeof...(property_tys)>>::type;
177+
};
178+
// Specialization to avoid zero-size array creation.
179+
template <> struct properties_sorter<> {
180+
using type = properties_type_list<>;
181+
};
182+
135183
} // namespace detail
136184

137185
template <typename properties_type_list_ty> class __SYCL_EBO properties;
@@ -271,17 +319,19 @@ class __SYCL_EBO properties<detail::properties_type_list<property_tys...>>
271319
};
272320

273321
// Deduction guides
274-
template <typename... PropertyValueTs,
322+
template <typename... unsorted_property_tys,
275323
typename = std::enable_if_t<
276-
detail::properties_are_valid_for_ctad<PropertyValueTs...>>>
277-
properties(PropertyValueTs... props)
278-
-> properties<typename detail::Sorted<PropertyValueTs...>::type>;
324+
detail::properties_are_valid_for_ctad<unsorted_property_tys...>>>
325+
properties(unsorted_property_tys... props)
326+
-> properties<
327+
typename detail::properties_sorter<unsorted_property_tys...>::type>;
279328

280-
template <typename... PropertyValueTs,
329+
template <typename... unsorted_property_tys,
281330
typename = std::enable_if_t<
282-
!detail::properties_are_valid_for_ctad<PropertyValueTs...>>>
283-
properties(PropertyValueTs... props)
284-
-> properties<detail::invalid_properties_type_list<PropertyValueTs...>>;
331+
!detail::properties_are_valid_for_ctad<unsorted_property_tys...>>>
332+
properties(unsorted_property_tys... props)
333+
-> properties<
334+
detail::invalid_properties_type_list<unsorted_property_tys...>>;
285335

286336
using empty_properties_t = decltype(properties{});
287337

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

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88

99
#pragma once
1010

11-
#include <sycl/detail/boost/mp11/algorithm.hpp> // for mp_sort_q
12-
#include <sycl/detail/boost/mp11/detail/mp_list.hpp> // for mp_list
13-
#include <sycl/detail/boost/mp11/detail/mp_rename.hpp> // for mp_rename
14-
#include <sycl/detail/boost/mp11/integral.hpp> // for mp_bool
1511
#include <sycl/ext/oneapi/properties/property.hpp>
1612
#include <sycl/ext/oneapi/properties/property_value.hpp>
1713

@@ -94,23 +90,6 @@ template <typename RHS> struct SelectNonVoid<void, RHS> {
9490
using type = RHS;
9591
};
9692

97-
// Sort types accoring to their PropertyID.
98-
struct SortByPropertyId {
99-
template <typename T1, typename T2>
100-
using fn = sycl::detail::boost::mp11::mp_bool<(PropertyID<T1>::value <
101-
PropertyID<T2>::value)>;
102-
};
103-
template <typename... Ts> struct Sorted {
104-
static_assert(detail::AllPropertyValues<std::tuple<Ts...>>::value,
105-
"Unrecognized property in property list.");
106-
using properties = sycl::detail::boost::mp11::mp_list<Ts...>;
107-
using sortedProperties =
108-
sycl::detail::boost::mp11::mp_sort_q<properties, SortByPropertyId>;
109-
using type =
110-
sycl::detail::boost::mp11::mp_rename<sortedProperties,
111-
detail::properties_type_list>;
112-
};
113-
11493
//******************************************************************************
11594
// Property merging
11695
//******************************************************************************

sycl/test/include_deps/sycl_detail_core.hpp.cpp

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -110,33 +110,6 @@
110110
// CHECK-NEXT: ext/oneapi/properties/property_value.hpp
111111
// CHECK-NEXT: ext/oneapi/properties/properties.hpp
112112
// CHECK-NEXT: ext/oneapi/properties/property_utils.hpp
113-
// CHECK-NEXT: detail/boost/mp11/algorithm.hpp
114-
// CHECK-NEXT: detail/boost/mp11/list.hpp
115-
// CHECK-NEXT: detail/boost/mp11/integral.hpp
116-
// CHECK-NEXT: detail/boost/mp11/version.hpp
117-
// CHECK-NEXT: detail/boost/mp11/detail/mp_value.hpp
118-
// CHECK-NEXT: detail/boost/mp11/detail/config.hpp
119-
// CHECK-NEXT: detail/boost/mp11/detail/mp_list.hpp
120-
// CHECK-NEXT: detail/boost/mp11/detail/mp_list_v.hpp
121-
// CHECK-NEXT: detail/boost/mp11/detail/mp_is_list.hpp
122-
// CHECK-NEXT: detail/boost/mp11/detail/mp_is_value_list.hpp
123-
// CHECK-NEXT: detail/boost/mp11/detail/mp_front.hpp
124-
// CHECK-NEXT: detail/boost/mp11/detail/mp_rename.hpp
125-
// CHECK-NEXT: detail/boost/mp11/detail/mp_defer.hpp
126-
// CHECK-NEXT: detail/boost/mp11/detail/mp_append.hpp
127-
// CHECK-NEXT: detail/boost/mp11/detail/mp_count.hpp
128-
// CHECK-NEXT: detail/boost/mp11/detail/mp_plus.hpp
129-
// CHECK-NEXT: detail/boost/mp11/utility.hpp
130-
// CHECK-NEXT: detail/boost/mp11/detail/mp_fold.hpp
131-
// CHECK-NEXT: detail/boost/mp11/set.hpp
132-
// CHECK-NEXT: detail/boost/mp11/function.hpp
133-
// CHECK-NEXT: detail/boost/mp11/detail/mp_min_element.hpp
134-
// CHECK-NEXT: detail/boost/mp11/detail/mp_void.hpp
135-
// CHECK-NEXT: detail/boost/mp11/detail/mp_copy_if.hpp
136-
// CHECK-NEXT: detail/boost/mp11/detail/mp_remove_if.hpp
137-
// CHECK-NEXT: detail/boost/mp11/detail/mp_map_find.hpp
138-
// CHECK-NEXT: detail/boost/mp11/detail/mp_with_index.hpp
139-
// CHECK-NEXT: detail/boost/mp11/integer_sequence.hpp
140113
// CHECK-NEXT: ext/oneapi/experimental/graph.hpp
141114
// CHECK-NEXT: handler.hpp
142115
// CHECK-NEXT: detail/cl.h

0 commit comments

Comments
 (0)