| 1285 | |
| 1286 | template<class ForwardIt> |
| 1287 | sycl::event is_sorted_until(sycl::queue &q, util::allocation_group &scratch_allocations, |
| 1288 | ForwardIt first, ForwardIt last, |
| 1289 | typename std::iterator_traits<ForwardIt>::difference_type *out, |
| 1290 | const std::vector<sycl::event>& deps = {}) { |
| 1291 | if(first == last) |
| 1292 | return sycl::event{}; |
| 1293 | |
| 1294 | using DiffT = typename std::iterator_traits<ForwardIt>::difference_type; |
| 1295 | DiffT problem_size = std::distance(first, last); |
| 1296 | |
| 1297 | auto transform = [=] (ForwardIt input) { |
| 1298 | auto next = std::next(input, 1); |
| 1299 | #if __cplusplus < 202002L |
| 1300 | if((*next < *input)) |
| 1301 | #else |
| 1302 | if(std::less{}(*next, *input)) |
| 1303 | #endif |
| 1304 | return std::distance(first, input); |
| 1305 | |
| 1306 | return problem_size; |
| 1307 | }; |
| 1308 | |
| 1309 | auto kernel = [=](sycl::id<1> idx, auto& reducer) { |
| 1310 | auto input = first; |
| 1311 | std::advance(input, idx[0]); |
| 1312 | reducer.combine(transform(input)); |
| 1313 | }; |
| 1314 | |
| 1315 | auto reduce = sycl::minimum<DiffT>{}; |
| 1316 | |
| 1317 | return detail::transform_reduce_impl(q, scratch_allocations, out, std::numeric_limits<DiffT>::max(), |
| 1318 | problem_size, kernel, reduce, deps); |
| 1319 | } |
| 1320 | |
| 1321 | template<class ForwardIt, class Compare> |
| 1322 | sycl::event is_sorted_until(sycl::queue &q, util::allocation_group &scratch_allocations, |