Skip to content

Commit

Permalink
[SYCL] Don't use boost/mp11 for oneapi properties sorting (#16075)
Browse files Browse the repository at this point in the history
We want to get rid of it for the upstreaming purposes.
  • Loading branch information
aelovikov-intel authored Nov 14, 2024
1 parent 80b63a2 commit 853917d
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 58 deletions.
4 changes: 2 additions & 2 deletions sycl/include/sycl/ext/intel/esimd/memory_properties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ class properties
// Deduction guides
template <typename... PropertyValueTs>
properties(PropertyValueTs... props)
-> properties<typename sycl::ext::oneapi::experimental::detail::Sorted<
PropertyValueTs...>::type>;
-> properties<typename sycl::ext::oneapi::experimental::detail::
properties_sorter<PropertyValueTs...>::type>;
#endif

/// The 'alignment' property is used to specify the alignment of memory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <sycl/ext/oneapi/properties/property_value.hpp>
#include <sycl/pointers.hpp>

#include <sycl/detail/boost/mp11/algorithm.hpp>

#include <cstddef>
#include <string_view>
#include <tuple>
Expand Down
66 changes: 58 additions & 8 deletions sycl/include/sycl/ext/oneapi/properties/properties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,54 @@ constexpr bool properties_are_valid_for_ctad = []() constexpr {

template <typename... property_tys> struct properties_type_list;
template <typename... property_tys> struct invalid_properties_type_list {};

template <typename... property_tys> struct properties_sorter {
// Not using "auto" due to MSVC bug in v19.36 and older. v19.37 and later is
// able to compile "auto" just fine. See https://godbolt.org/z/eW3rjjs7n.
static constexpr std::array<int, sizeof...(property_tys)> sorted_indices =
[]() constexpr {
int idx = 0;
int N = sizeof...(property_tys);
// std::sort isn't constexpr until C++20. Also, it's possible there will
// be a compiler builtin to sort types, in which case we should start
// using that.
std::array to_sort{
std::pair{PropertyID<property_tys>::value, idx++}...};
auto swap_pair = [](auto &x, auto &y) constexpr {
auto tmp_first = x.first;
auto tmp_second = x.second;
x.first = y.first;
x.second = y.second;
y.first = tmp_first;
y.second = tmp_second;
};
for (int i = 0; i < N; ++i)
for (int j = i; j < N; ++j)
if (to_sort[j].first < to_sort[i].first)
swap_pair(to_sort[i], to_sort[j]);

std::array<int, sizeof...(property_tys)> sorted_indices{};
for (int i = 0; i < N; ++i)
sorted_indices[i] = to_sort[i].second;

return sorted_indices;
}();

template <typename> struct helper;
template <int... IdxSeq>
struct helper<std::integer_sequence<int, IdxSeq...>> {
using type = properties_type_list<
nth_type_t<sorted_indices[IdxSeq], property_tys...>...>;
};

using type = typename helper<
std::make_integer_sequence<int, sizeof...(property_tys)>>::type;
};
// Specialization to avoid zero-size array creation.
template <> struct properties_sorter<> {
using type = properties_type_list<>;
};

} // namespace detail

template <typename properties_type_list_ty> class __SYCL_EBO properties;
Expand Down Expand Up @@ -271,17 +319,19 @@ class __SYCL_EBO properties<detail::properties_type_list<property_tys...>>
};

// Deduction guides
template <typename... PropertyValueTs,
template <typename... unsorted_property_tys,
typename = std::enable_if_t<
detail::properties_are_valid_for_ctad<PropertyValueTs...>>>
properties(PropertyValueTs... props)
-> properties<typename detail::Sorted<PropertyValueTs...>::type>;
detail::properties_are_valid_for_ctad<unsorted_property_tys...>>>
properties(unsorted_property_tys... props)
-> properties<
typename detail::properties_sorter<unsorted_property_tys...>::type>;

template <typename... PropertyValueTs,
template <typename... unsorted_property_tys,
typename = std::enable_if_t<
!detail::properties_are_valid_for_ctad<PropertyValueTs...>>>
properties(PropertyValueTs... props)
-> properties<detail::invalid_properties_type_list<PropertyValueTs...>>;
!detail::properties_are_valid_for_ctad<unsorted_property_tys...>>>
properties(unsorted_property_tys... props)
-> properties<
detail::invalid_properties_type_list<unsorted_property_tys...>>;

using empty_properties_t = decltype(properties{});

Expand Down
21 changes: 0 additions & 21 deletions sycl/include/sycl/ext/oneapi/properties/property_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@

#pragma once

#include <sycl/detail/boost/mp11/algorithm.hpp> // for mp_sort_q
#include <sycl/detail/boost/mp11/detail/mp_list.hpp> // for mp_list
#include <sycl/detail/boost/mp11/detail/mp_rename.hpp> // for mp_rename
#include <sycl/detail/boost/mp11/integral.hpp> // for mp_bool
#include <sycl/ext/oneapi/properties/property.hpp>
#include <sycl/ext/oneapi/properties/property_value.hpp>

Expand Down Expand Up @@ -94,23 +90,6 @@ template <typename RHS> struct SelectNonVoid<void, RHS> {
using type = RHS;
};

// Sort types accoring to their PropertyID.
struct SortByPropertyId {
template <typename T1, typename T2>
using fn = sycl::detail::boost::mp11::mp_bool<(PropertyID<T1>::value <
PropertyID<T2>::value)>;
};
template <typename... Ts> struct Sorted {
static_assert(detail::AllPropertyValues<std::tuple<Ts...>>::value,
"Unrecognized property in property list.");
using properties = sycl::detail::boost::mp11::mp_list<Ts...>;
using sortedProperties =
sycl::detail::boost::mp11::mp_sort_q<properties, SortByPropertyId>;
using type =
sycl::detail::boost::mp11::mp_rename<sortedProperties,
detail::properties_type_list>;
};

//******************************************************************************
// Property merging
//******************************************************************************
Expand Down
27 changes: 0 additions & 27 deletions sycl/test/include_deps/sycl_detail_core.hpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,33 +110,6 @@
// CHECK-NEXT: ext/oneapi/properties/property_value.hpp
// CHECK-NEXT: ext/oneapi/properties/properties.hpp
// CHECK-NEXT: ext/oneapi/properties/property_utils.hpp
// CHECK-NEXT: detail/boost/mp11/algorithm.hpp
// CHECK-NEXT: detail/boost/mp11/list.hpp
// CHECK-NEXT: detail/boost/mp11/integral.hpp
// CHECK-NEXT: detail/boost/mp11/version.hpp
// CHECK-NEXT: detail/boost/mp11/detail/mp_value.hpp
// CHECK-NEXT: detail/boost/mp11/detail/config.hpp
// CHECK-NEXT: detail/boost/mp11/detail/mp_list.hpp
// CHECK-NEXT: detail/boost/mp11/detail/mp_list_v.hpp
// CHECK-NEXT: detail/boost/mp11/detail/mp_is_list.hpp
// CHECK-NEXT: detail/boost/mp11/detail/mp_is_value_list.hpp
// CHECK-NEXT: detail/boost/mp11/detail/mp_front.hpp
// CHECK-NEXT: detail/boost/mp11/detail/mp_rename.hpp
// CHECK-NEXT: detail/boost/mp11/detail/mp_defer.hpp
// CHECK-NEXT: detail/boost/mp11/detail/mp_append.hpp
// CHECK-NEXT: detail/boost/mp11/detail/mp_count.hpp
// CHECK-NEXT: detail/boost/mp11/detail/mp_plus.hpp
// CHECK-NEXT: detail/boost/mp11/utility.hpp
// CHECK-NEXT: detail/boost/mp11/detail/mp_fold.hpp
// CHECK-NEXT: detail/boost/mp11/set.hpp
// CHECK-NEXT: detail/boost/mp11/function.hpp
// CHECK-NEXT: detail/boost/mp11/detail/mp_min_element.hpp
// CHECK-NEXT: detail/boost/mp11/detail/mp_void.hpp
// CHECK-NEXT: detail/boost/mp11/detail/mp_copy_if.hpp
// CHECK-NEXT: detail/boost/mp11/detail/mp_remove_if.hpp
// CHECK-NEXT: detail/boost/mp11/detail/mp_map_find.hpp
// CHECK-NEXT: detail/boost/mp11/detail/mp_with_index.hpp
// CHECK-NEXT: detail/boost/mp11/integer_sequence.hpp
// CHECK-NEXT: ext/oneapi/experimental/graph.hpp
// CHECK-NEXT: handler.hpp
// CHECK-NEXT: detail/cl.h
Expand Down

0 comments on commit 853917d

Please sign in to comment.