| 688 | |
| 689 | template <class ForwardIt1, class ForwardIt2> |
| 690 | sycl::event find_first_of(sycl::queue &q, util::allocation_group &scratch_allocations, |
| 691 | ForwardIt1 first, ForwardIt1 last, ForwardIt2 s_first, |
| 692 | ForwardIt2 s_last, |
| 693 | typename std::iterator_traits<ForwardIt1>::difference_type *out, |
| 694 | const std::vector<sycl::event> &deps = {}) { |
| 695 | if (first == last || s_first == s_last) |
| 696 | return sycl::event{}; |
| 697 | |
| 698 | using DiffT = typename std::iterator_traits<ForwardIt1>::difference_type; |
| 699 | DiffT problem_size = std::distance(first, last); |
| 700 | |
| 701 | auto transform = [=] (ForwardIt1 input) { |
| 702 | auto s_it = s_first; |
| 703 | for (; s_it != s_last; ++s_it) { |
| 704 | if(*input == *s_it) |
| 705 | return std::distance(first, input); |
| 706 | } |
| 707 | return problem_size; |
| 708 | }; |
| 709 | |
| 710 | auto kernel = [=](sycl::id<1> idx, auto& reducer) { |
| 711 | auto input = first; |
| 712 | std::advance(input, idx[0]); |
| 713 | reducer.combine(transform(input)); |
| 714 | }; |
| 715 | |
| 716 | auto reduce = sycl::minimum<DiffT>{}; |
| 717 | |
| 718 | return detail::transform_reduce_impl(q, scratch_allocations, out, |
| 719 | std::numeric_limits<DiffT>::max(), |
| 720 | problem_size, kernel, reduce, deps); |
| 721 | } |
| 722 | |
| 723 | template <class ForwardIt1, class ForwardIt2, class BinaryPredicate> |
| 724 | sycl::event find_first_of(sycl::queue &q, util::allocation_group &scratch_allocations, |