@@ -970,6 +970,123 @@ sycl::event sort(sycl::queue &q, RandomIt first, RandomIt last,
970970 return sorting::bitonic_sort (q, first, last, comp, deps);
971971}
972972
973+ template <class ForwardIt >
974+ sycl::event is_sorted (sycl::queue &q, ForwardIt first, ForwardIt last,
975+ detail::early_exit_flag_t * out,
976+ const std::vector<sycl::event>& deps = {}) {
977+ std::size_t problem_size = std::distance (first, last);
978+ if (problem_size == 0 )
979+ return sycl::event{};
980+
981+ auto evt = detail::early_exit_for_each (q, problem_size, out,
982+ [=](sycl::id<1 > idx) -> bool {
983+ auto it = first;
984+ std::advance (it, idx[0 ]);
985+ if (it != last-1 ) {
986+ auto next = std::next (it, 1 );
987+ #if __cplusplus < 202002L
988+ return (*next < *it);
989+ #else
990+ return std::less{}(*next, *it);
991+ #endif
992+ }
993+ return false ;
994+ }, deps);
995+ return q.single_task (evt, [=](){
996+ *out = static_cast <detail::early_exit_flag_t >(!(*out));
997+ });
998+ }
999+
1000+ template <class ForwardIt , class Compare >
1001+ sycl::event is_sorted (sycl::queue &q, ForwardIt first, ForwardIt last,
1002+ detail::early_exit_flag_t * out,
1003+ Compare comp,
1004+ const std::vector<sycl::event>& deps = {}) {
1005+ std::size_t problem_size = std::distance (first, last);
1006+ if (problem_size == 0 )
1007+ return sycl::event{};
1008+
1009+ auto evt = detail::early_exit_for_each (q, problem_size, out,
1010+ [=](sycl::id<1 > idx) -> bool {
1011+ auto it = std::next (first, idx[0 ]);
1012+ if (it != last-1 ) {
1013+ auto next = std::next (it, 1 );
1014+ return comp (*next, *it);
1015+ }
1016+ return false ;
1017+ }, deps);
1018+ return q.single_task (evt, [=](){
1019+ *out = static_cast <detail::early_exit_flag_t >(!(*out));
1020+ });
1021+ }
1022+
1023+ template <class ForwardIt >
1024+ sycl::event is_sorted_until (sycl::queue &q, util::allocation_group &scratch_allocations,
1025+ ForwardIt first, ForwardIt last,
1026+ typename std::iterator_traits<ForwardIt>::difference_type *out,
1027+ const std::vector<sycl::event>& deps = {}) {
1028+ if (first == last)
1029+ return sycl::event{};
1030+
1031+ using DiffT = typename std::iterator_traits<ForwardIt>::difference_type;
1032+ DiffT problem_size = std::distance (first, last);
1033+
1034+ auto transform = [=] (ForwardIt input) {
1035+ auto next = std::next (input, 1 );
1036+ #if __cplusplus < 202002L
1037+ if ((*next < *input))
1038+ #else
1039+ if (std::less{}(*next, *input))
1040+ #endif
1041+ return std::distance (first, input);
1042+
1043+ return problem_size;
1044+ };
1045+
1046+ auto kernel = [=](sycl::id<1 > idx, auto & reducer) {
1047+ auto input = first;
1048+ std::advance (input, idx[0 ]);
1049+ reducer.combine (transform (input));
1050+ };
1051+
1052+ auto reduce = sycl::minimum<DiffT>{};
1053+
1054+ return detail::transform_reduce_impl (q, scratch_allocations, out, std::numeric_limits<DiffT>::max (),
1055+ problem_size, kernel, reduce, deps);
1056+ }
1057+
1058+ template <class ForwardIt , class Compare >
1059+ sycl::event is_sorted_until (sycl::queue &q, util::allocation_group &scratch_allocations,
1060+ ForwardIt first, ForwardIt last,
1061+ typename std::iterator_traits<ForwardIt>::difference_type *out,
1062+ Compare comp,
1063+ const std::vector<sycl::event>& deps = {}) {
1064+ if (first == last)
1065+ return sycl::event{};
1066+
1067+ using DiffT = typename std::iterator_traits<ForwardIt>::difference_type;
1068+ DiffT problem_size = std::distance (first, last);
1069+
1070+ auto transform = [=] (ForwardIt input) {
1071+ auto next = std::next (input, 1 );
1072+ if (comp (*next, *input))
1073+ return std::distance (first, input);
1074+
1075+ return problem_size;
1076+ };
1077+
1078+ auto kernel = [=](sycl::id<1 > idx, auto & reducer) {
1079+ auto input = first;
1080+ std::advance (input, idx[0 ]);
1081+ reducer.combine (transform (input));
1082+ };
1083+
1084+ auto reduce = sycl::minimum<DiffT>{};
1085+
1086+ return detail::transform_reduce_impl (q, scratch_allocations, out, std::numeric_limits<DiffT>::max (),
1087+ problem_size, kernel, reduce, deps);
1088+ }
1089+
9731090template < class ForwardIt1 , class ForwardIt2 ,
9741091 class ForwardIt3 , class Compare >
9751092sycl::event merge (sycl::queue& q,
0 commit comments