| 525 | |
| 526 | template <class ForwardIt, class T> |
| 527 | sycl::event find(sycl::queue &q, util::allocation_group &scratch_allocations, |
| 528 | ForwardIt first, ForwardIt last, const T &value, |
| 529 | typename std::iterator_traits<ForwardIt>::difference_type *out, |
| 530 | const std::vector<sycl::event> &deps = {}) { |
| 531 | if(first == last) |
| 532 | return sycl::event{}; |
| 533 | |
| 534 | using DiffT = typename std::iterator_traits<ForwardIt>::difference_type; |
| 535 | DiffT problem_size = std::distance(first, last); |
| 536 | |
| 537 | auto transform = [first, value, problem_size] (ForwardIt input) { |
| 538 | return (*input == value ? std::distance(first, input) : problem_size); |
| 539 | }; |
| 540 | |
| 541 | auto kernel = [=](sycl::id<1> idx, auto& reducer) { |
| 542 | auto input = first; |
| 543 | std::advance(input, idx[0]); |
| 544 | reducer.combine(transform(input)); |
| 545 | }; |
| 546 | |
| 547 | auto reduce = sycl::minimum<DiffT>{}; |
| 548 | |
| 549 | return detail::transform_reduce_impl(q, scratch_allocations, out, |
| 550 | std::numeric_limits<DiffT>::max(), |
| 551 | problem_size, kernel, reduce, deps); |
| 552 | } |
| 553 | |
| 554 | template <class ForwardIt, class UnaryPredicate> |
| 555 | sycl::event find_if(sycl::queue &q, util::allocation_group &scratch_allocations, |