From c496f7a543a3fb1678ae2f15ec738ed27073760f Mon Sep 17 00:00:00 2001 From: Andrei Elovikov Date: Fri, 8 Nov 2024 16:44:51 -0800 Subject: [PATCH 1/3] [SYCL] Don't use boost/mp11 for oneapi properties sorting --- .../ext/intel/esimd/memory_properties.hpp | 4 +- .../annotated_ptr/annotated_ptr.hpp | 2 + .../sycl/ext/oneapi/properties/properties.hpp | 60 ++++++++++++++++--- .../ext/oneapi/properties/property_utils.hpp | 21 ------- .../include_deps/sycl_detail_core.hpp.cpp | 27 --------- 5 files changed, 56 insertions(+), 58 deletions(-) diff --git a/sycl/include/sycl/ext/intel/esimd/memory_properties.hpp b/sycl/include/sycl/ext/intel/esimd/memory_properties.hpp index 94b3b2cebd61d..da9ca3d5506d3 100644 --- a/sycl/include/sycl/ext/intel/esimd/memory_properties.hpp +++ b/sycl/include/sycl/ext/intel/esimd/memory_properties.hpp @@ -77,8 +77,8 @@ class properties // Deduction guides template properties(PropertyValueTs... props) - -> properties::type>; + -> properties::type>; #endif /// The 'alignment' property is used to specify the alignment of memory diff --git a/sycl/include/sycl/ext/oneapi/experimental/annotated_ptr/annotated_ptr.hpp b/sycl/include/sycl/ext/oneapi/experimental/annotated_ptr/annotated_ptr.hpp index ea90f3d9d1cef..b7e90788175a8 100644 --- a/sycl/include/sycl/ext/oneapi/experimental/annotated_ptr/annotated_ptr.hpp +++ b/sycl/include/sycl/ext/oneapi/experimental/annotated_ptr/annotated_ptr.hpp @@ -19,6 +19,8 @@ #include #include +#include + #include #include #include diff --git a/sycl/include/sycl/ext/oneapi/properties/properties.hpp b/sycl/include/sycl/ext/oneapi/properties/properties.hpp index cecb310b97eb7..22fafcf9cb6b5 100644 --- a/sycl/include/sycl/ext/oneapi/properties/properties.hpp +++ b/sycl/include/sycl/ext/oneapi/properties/properties.hpp @@ -132,6 +132,50 @@ constexpr bool properties_are_valid_for_ctad = []() constexpr { template struct properties_type_list; template struct invalid_properties_type_list {}; + +template struct properties_sorter { + static constexpr auto 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::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 sorted_indices{}; + for (int i = 0; i < N; ++i) + sorted_indices[i] = to_sort[i].second; + + return sorted_indices; + }(); + + template struct helper; + template + struct helper> { + using type = properties_type_list< + nth_type_t...>; + }; + + using type = typename helper< + std::make_integer_sequence>::type; +}; +// Specialization to avoid zero-size array creation. +template <> struct properties_sorter<> { + using type = properties_type_list<>; +}; + } // namespace detail template class __SYCL_EBO properties; @@ -271,17 +315,17 @@ class __SYCL_EBO properties> }; // Deduction guides -template >> -properties(PropertyValueTs... props) - -> properties::type>; + detail::properties_are_valid_for_ctad>> +properties(unsorted_property_tys... props) -> properties< + typename detail::properties_sorter::type>; -template >> -properties(PropertyValueTs... props) - -> properties>; + !detail::properties_are_valid_for_ctad>> +properties(unsorted_property_tys... props) -> properties< + detail::invalid_properties_type_list>; using empty_properties_t = decltype(properties{}); diff --git a/sycl/include/sycl/ext/oneapi/properties/property_utils.hpp b/sycl/include/sycl/ext/oneapi/properties/property_utils.hpp index aee53419498eb..3cf38f8d1dad0 100644 --- a/sycl/include/sycl/ext/oneapi/properties/property_utils.hpp +++ b/sycl/include/sycl/ext/oneapi/properties/property_utils.hpp @@ -8,10 +8,6 @@ #pragma once -#include // for mp_sort_q -#include // for mp_list -#include // for mp_rename -#include // for mp_bool #include #include @@ -94,23 +90,6 @@ template struct SelectNonVoid { using type = RHS; }; -// Sort types accoring to their PropertyID. -struct SortByPropertyId { - template - using fn = sycl::detail::boost::mp11::mp_bool<(PropertyID::value < - PropertyID::value)>; -}; -template struct Sorted { - static_assert(detail::AllPropertyValues>::value, - "Unrecognized property in property list."); - using properties = sycl::detail::boost::mp11::mp_list; - using sortedProperties = - sycl::detail::boost::mp11::mp_sort_q; - using type = - sycl::detail::boost::mp11::mp_rename; -}; - //****************************************************************************** // Property merging //****************************************************************************** diff --git a/sycl/test/include_deps/sycl_detail_core.hpp.cpp b/sycl/test/include_deps/sycl_detail_core.hpp.cpp index 4abe5f39073c7..dc959046444af 100644 --- a/sycl/test/include_deps/sycl_detail_core.hpp.cpp +++ b/sycl/test/include_deps/sycl_detail_core.hpp.cpp @@ -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 From a8eac7959ee35d99cebdb801eab0f95b74be64dd Mon Sep 17 00:00:00 2001 From: Andrei Elovikov Date: Wed, 13 Nov 2024 11:04:13 -0800 Subject: [PATCH 2/3] Make CI's clang-format happy --- sycl/include/sycl/ext/oneapi/properties/properties.hpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sycl/include/sycl/ext/oneapi/properties/properties.hpp b/sycl/include/sycl/ext/oneapi/properties/properties.hpp index 22fafcf9cb6b5..059e82d3c7a5c 100644 --- a/sycl/include/sycl/ext/oneapi/properties/properties.hpp +++ b/sycl/include/sycl/ext/oneapi/properties/properties.hpp @@ -318,14 +318,16 @@ class __SYCL_EBO properties> template >> -properties(unsorted_property_tys... props) -> properties< - typename detail::properties_sorter::type>; +properties(unsorted_property_tys... props) + -> properties< + typename detail::properties_sorter::type>; template >> -properties(unsorted_property_tys... props) -> properties< - detail::invalid_properties_type_list>; +properties(unsorted_property_tys... props) + -> properties< + detail::invalid_properties_type_list>; using empty_properties_t = decltype(properties{}); From 26e5bf5ac102316e9d750bca87065a29ca34cce7 Mon Sep 17 00:00:00 2001 From: Andrei Elovikov Date: Wed, 13 Nov 2024 15:08:07 -0800 Subject: [PATCH 3/3] Workaround MSVC bug --- .../sycl/ext/oneapi/properties/properties.hpp | 56 ++++++++++--------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/sycl/include/sycl/ext/oneapi/properties/properties.hpp b/sycl/include/sycl/ext/oneapi/properties/properties.hpp index 059e82d3c7a5c..190a16ce5d4c3 100644 --- a/sycl/include/sycl/ext/oneapi/properties/properties.hpp +++ b/sycl/include/sycl/ext/oneapi/properties/properties.hpp @@ -134,32 +134,36 @@ template struct properties_type_list; template struct invalid_properties_type_list {}; template struct properties_sorter { - static constexpr auto 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::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 sorted_indices{}; - for (int i = 0; i < N; ++i) - sorted_indices[i] = to_sort[i].second; - - return sorted_indices; - }(); + // 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 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::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 sorted_indices{}; + for (int i = 0; i < N; ++i) + sorted_indices[i] = to_sort[i].second; + + return sorted_indices; + }(); template struct helper; template