| 612 | |
| 613 | template <class ForwardIt1, class ForwardIt2> |
| 614 | sycl::event find_end(sycl::queue &q, util::allocation_group &scratch_allocations, |
| 615 | ForwardIt1 first, ForwardIt1 last, ForwardIt2 s_first, |
| 616 | ForwardIt2 s_last, |
| 617 | typename std::iterator_traits<ForwardIt1>::difference_type *out, |
| 618 | const std::vector<sycl::event> &deps = {}) { |
| 619 | if (first == last || s_first == s_last) |
| 620 | return sycl::event{}; |
| 621 | |
| 622 | if (std::distance(first, last) < std::distance(s_first, s_last)) |
| 623 | return sycl::event{}; |
| 624 | |
| 625 | using DiffT = typename std::iterator_traits<ForwardIt1>::difference_type; |
| 626 | DiffT problem_size = std::distance(first, last); |
| 627 | |
| 628 | auto transform = [=](ForwardIt1 input) { |
| 629 | auto it = input; |
| 630 | for (ForwardIt1 s_it = s_first; s_it != s_last; ++s_it) { |
| 631 | if(!(*it++ == *s_it)) |
| 632 | return std::numeric_limits<DiffT>::min(); |
| 633 | } |
| 634 | return std::distance(first, input); |
| 635 | }; |
| 636 | |
| 637 | auto kernel = [=](sycl::id<1> idx, auto& reducer) { |
| 638 | auto input = first; |
| 639 | std::advance(input, idx[0]); |
| 640 | reducer.combine(transform(input)); |
| 641 | }; |
| 642 | |
| 643 | auto reduce = sycl::maximum<DiffT>{}; |
| 644 | |
| 645 | return detail::transform_reduce_impl(q, scratch_allocations, out, |
| 646 | std::numeric_limits<DiffT>::min(), |
| 647 | problem_size, kernel, reduce, deps); |
| 648 | } |
| 649 | |
| 650 | |
| 651 | template <class ForwardIt1, class ForwardIt2, class BinaryPredicate> |