From a037165124e0021025bd4d2194a76d1decda1d04 Mon Sep 17 00:00:00 2001 From: Dmitriy Sobolev Date: Wed, 6 Nov 2024 13:11:19 +0000 Subject: [PATCH] Allow passing a non-trivially-copyable comparator to sort (#1932) Signed-off-by: Dmitriy Sobolev --- .../dpcpp/parallel_backend_sycl_merge_sort.h | 1 + include/oneapi/dpl/pstl/hetero/dpcpp/sycl_traits.h | 10 ++++++++++ .../device_copyable.pass.cpp | 14 ++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/include/oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl_merge_sort.h b/include/oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl_merge_sort.h index db55edc37d..0765f8ef7b 100644 --- a/include/oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl_merge_sort.h +++ b/include/oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl_merge_sort.h @@ -24,6 +24,7 @@ #include // std::decay_t, std::integral_constant #include "sycl_defs.h" // __dpl_sycl::__local_accessor, __dpl_sycl::__group_barrier +#include "sycl_traits.h" // SYCL traits specialization for some oneDPL types. #include "../../utils.h" // __dpl_bit_floor, __dpl_bit_ceil #include "../../utils_ranges.h" // __difference_t #include "parallel_backend_sycl_merge.h" // __find_start_point, __serial_merge diff --git a/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_traits.h b/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_traits.h index f498a58750..2d0e88fd34 100644 --- a/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_traits.h +++ b/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_traits.h @@ -257,6 +257,9 @@ struct __write_to_id_if_else; template struct __early_exit_find_or; +template +struct __leaf_sorter; + } // namespace oneapi::dpl::__par_backend_hetero template @@ -313,6 +316,13 @@ struct sycl::is_device_copyable<_ONEDPL_SPECIALIZE_FOR(oneapi::dpl::__par_backen { }; +template +struct sycl::is_device_copyable<_ONEDPL_SPECIALIZE_FOR(oneapi::dpl::__par_backend_hetero::__leaf_sorter, _Range, + _Compare)> + : oneapi::dpl::__internal::__are_all_device_copyable<_Range, _Compare> +{ +}; + namespace oneapi::dpl::unseq_backend { diff --git a/test/general/implementation_details/device_copyable.pass.cpp b/test/general/implementation_details/device_copyable.pass.cpp index 8b137cc33e..9b1b09e8c2 100644 --- a/test/general/implementation_details/device_copyable.pass.cpp +++ b/test/general/implementation_details/device_copyable.pass.cpp @@ -190,6 +190,15 @@ test_device_copyable() oneapi::dpl::__par_backend_hetero::__early_exit_find_or>, "__early_exit_find_or is not device copyable with device copyable types"); + // __leaf_sorter + // Note that the use of noop_device_copyable/noop_non_device_copyable is valid in this context because + // sycl::is_device_copyable specialization for __leaf_sorter does not require instantiation of + // __leaf_sorter with the provided types. See [temp.inst]/1 of C++17 spec for the details. + static_assert( + sycl::is_device_copyable_v>, + "__leaf_sorter is not device copyable with device copyable types"); + //__not_pred static_assert(sycl::is_device_copyable_v>, "__not_pred is not device copyable with device copyable types"); @@ -423,6 +432,11 @@ test_non_device_copyable() noop_non_device_copyable>>, "__early_exit_find_or is device copyable with non device copyable types"); + // __leaf_sorter + static_assert(!sycl::is_device_copyable_v>, + "__leaf_sorter is device copyable with non device copyable types"); + //__not_pred static_assert(!sycl::is_device_copyable_v>, "__not_pred is device copyable with non device copyable types");