Skip to content

Commit

Permalink
[oneDPL][ranges] + include <ranges>
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeDvorskiy committed Mar 22, 2024
1 parent c5efe4e commit 1997370
Showing 1 changed file with 16 additions and 24 deletions.
40 changes: 16 additions & 24 deletions include/oneapi/dpl/pstl/hetero/algorithm_ranges_impl_hetero.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
# include "dpcpp/parallel_backend_sycl_utils.h"
#endif

#if _ONEDPL___cplusplus >= 202002L
#include <ranges>
#endif //_ONEDPL___cplusplus >= 202002L

namespace oneapi
{
namespace dpl
Expand Down Expand Up @@ -53,7 +57,6 @@ __pattern_walk_n(__hetero_tag<_BackendTag>, _ExecutionPolicy&& __exec, _Function
}
}

#if _ONEDPL___cplusplus >= 202002L
//---------------------------------------------------------------------------------------------------------------------
// pattern_for_each
//---------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -89,7 +92,6 @@ __pattern_transform(__hetero_tag<_BackendTag> __tag, _ExecutionPolicy&& __exec,

return __return_t{__in_r.begin() + __in_r.size(), __out_r.begin() + __out_r.size()};
}
#endif //_ONEDPL___cplusplus >= 202002L

//------------------------------------------------------------------------
// swap
Expand Down Expand Up @@ -171,7 +173,6 @@ __pattern_find_if(__hetero_tag<_BackendTag>, _ExecutionPolicy&& __exec, _Range&&
_Predicate{__pred}, _TagType{}, ::std::forward<_Range>(__rng));
}

#if _ONEDPL___cplusplus >= 202002L
template <typename _BackendTag, typename _ExecutionPolicy, typename _R, typename _Proj, typename _Pred>
decltype(auto)
__pattern_find_if(__hetero_tag<_BackendTag> __tag, _ExecutionPolicy&& __exec, _R&& __r, _Pred __pred, _Proj __proj)
Expand All @@ -182,7 +183,6 @@ __pattern_find_if(__hetero_tag<_BackendTag> __tag, _ExecutionPolicy&& __exec, _R

return std::ranges::borrowed_iterator_t<_R>(__r.begin() + __idx);
}
#endif //_ONEDPL___cplusplus >= 202002L

//------------------------------------------------------------------------
// find_end
Expand Down Expand Up @@ -304,7 +304,6 @@ __pattern_search(__hetero_tag<_BackendTag> __tag, _ExecutionPolicy&& __exec, _Ra
_Predicate{__pred}, _TagType{}, ::std::forward<_Range1>(__rng1), ::std::forward<_Range2>(__rng2));
}

#if _ONEDPL___cplusplus >= 202002L
template<typename _BackendTag, typename _ExecutionPolicy, typename _R1, typename _R2, typename _Pred, typename _Proj1,
typename _Proj2>
decltype(auto)
Expand All @@ -321,7 +320,6 @@ __pattern_search(__hetero_tag<_BackendTag> __tag, _ExecutionPolicy&& __exec, _R1
auto __end = (__idx == __r1.size() ? __r1.begin() + __idx : __r1.begin() + __idx + __r2.size());
return std::ranges::borrowed_subrange_t<_R1>(__r1.begin() + __idx, __end);
}
#endif //_ONEDPL___cplusplus >= 202002L

//------------------------------------------------------------------------
// search_n
Expand All @@ -338,11 +336,10 @@ __pattern_search_n(__hetero_tag<_BackendTag> __tag, _ExecutionPolicy&& __exec, _
auto __s_rng = oneapi::dpl::experimental::ranges::views::iota(0, __count) |
oneapi::dpl::experimental::ranges::views::transform([__value](auto) { return __value; });

return __ranges::__pattern_search(__tag, ::std::forward<_ExecutionPolicy>(__exec), ::std::forward<_Range>(__rng),
__s_rng, __pred);
return __pattern_search(__tag, ::std::forward<_ExecutionPolicy>(__exec), ::std::forward<_Range>(__rng), __s_rng,
__pred);
}

#if _ONEDPL___cplusplus >= 202002L
template<typename _BackendTag, typename _ExecutionPolicy, typename _R, typename _T, typename _Pred, typename _Proj>
decltype(auto)
__pattern_search_n(__hetero_tag<_BackendTag> __tag, _ExecutionPolicy&& __exec, _R&& __r,
Expand All @@ -354,7 +351,6 @@ __pattern_search_n(__hetero_tag<_BackendTag> __tag, _ExecutionPolicy&& __exec, _

return std::ranges::borrowed_subrange_t<_R>(__r.begin() + __idx, __r.begin() + __idx + __count);
}
#endif //_ONEDPL___cplusplus >= 202002L

template <typename _Size>
_Size
Expand All @@ -377,7 +373,7 @@ return_value(_Size1 __res, _Size2 __size, ::std::false_type)
template <typename _BackendTag, typename _ExecutionPolicy, typename _Range, typename _BinaryPredicate,
typename _OrFirstTag>
oneapi::dpl::__internal::__difference_t<_Range>
__pattern_adjacent_find(__hetero_tag<_BackendTag>, _ExecutionPolicy&& __exec, _Range&& __rng,
__pattern_adjacent_find2(__hetero_tag<_BackendTag>, _ExecutionPolicy&& __exec, _Range&& __rng,
_BinaryPredicate __predicate, _OrFirstTag __is__or_semantic)
{
if (__rng.size() < 2)
Expand Down Expand Up @@ -408,21 +404,19 @@ __pattern_adjacent_find(__hetero_tag<_BackendTag>, _ExecutionPolicy&& __exec, _R
return return_value(result, __rng.size(), __is__or_semantic);
}

#if _ONEDPL___cplusplus >= 202002L
template <typename _BackendTag, typename _ExecutionPolicy, typename _R, typename _Proj, typename _Pred>
decltype(auto)
__pattern_adjacent_find2(__hetero_tag<_BackendTag> __tag, _ExecutionPolicy&& __exec, _R&& __r, _Pred __pred,
__pattern_adjacent_find(__hetero_tag<_BackendTag> __tag, _ExecutionPolicy&& __exec, _R&& __r, _Pred __pred,
_Proj __proj)
{
auto __pred_2 = [__pred, __proj](auto&& __val, auto&& __next) { return __pred(__proj(__val), __proj(__next));};

auto __idx = oneapi::dpl::__internal::__ranges::__pattern_adjacent_find(__tag,
auto __idx = oneapi::dpl::__internal::__ranges::__pattern_adjacent_find2(__tag,
std::forward<_ExecutionPolicy>(__exec), oneapi::dpl::views::all_read(std::forward<_R>(__r)), __pred_2,
oneapi::dpl::__internal::__first_semantic());

return std::ranges::borrowed_iterator_t<_R>(__r.begin() + __idx);
}
#endif //_ONEDPL___cplusplus >= 202002L

template <typename _BackendTag, typename _ExecutionPolicy, typename _Range, typename _Predicate>
oneapi::dpl::__internal::__difference_t<_Range>
Expand Down Expand Up @@ -510,9 +504,8 @@ __pattern_copy_if(__hetero_tag<_BackendTag> __tag, _ExecutionPolicy&& __exec, _R
unseq_backend::__create_mask<_Predicate, _SizeType> __create_mask_op{__pred};
unseq_backend::__copy_by_mask<_ReduceOp, _Assign, /*inclusive*/ ::std::true_type, 1> __copy_by_mask_op;

return __ranges::__pattern_scan_copy(__tag, ::std::forward<_ExecutionPolicy>(__exec),
::std::forward<_Range1>(__rng1), ::std::forward<_Range2>(__rng2),
__create_mask_op, __copy_by_mask_op);
return __pattern_scan_copy(__tag, ::std::forward<_ExecutionPolicy>(__exec), ::std::forward<_Range1>(__rng1),
::std::forward<_Range2>(__rng2), __create_mask_op, __copy_by_mask_op);
}

//------------------------------------------------------------------------
Expand Down Expand Up @@ -559,9 +552,8 @@ __pattern_unique_copy(__hetero_tag<_BackendTag> __tag, _ExecutionPolicy&& __exec
__create_mask_unique_copy<__not_pred<_BinaryPredicate>, _It1DifferenceType> __create_mask_op{
__not_pred<_BinaryPredicate>{__pred}};

return __ranges::__pattern_scan_copy(__tag, ::std::forward<_ExecutionPolicy>(__exec),
::std::forward<_Range1>(__rng), ::std::forward<_Range2>(__result),
__create_mask_op, __copy_by_mask_op);
return __pattern_scan_copy(__tag, ::std::forward<_ExecutionPolicy>(__exec), ::std::forward<_Range1>(__rng),
::std::forward<_Range2>(__result), __create_mask_op, __copy_by_mask_op);
}

//------------------------------------------------------------------------
Expand All @@ -582,9 +574,9 @@ __pattern_unique(__hetero_tag<_BackendTag> __tag, _ExecutionPolicy&& __exec, _Ra
auto res = __ranges::__pattern_unique_copy(__tag, __exec, __rng, res_rng, __pred,
oneapi::dpl::__internal::__pstl_assign());

__ranges::__pattern_walk_n(__tag, ::std::forward<_ExecutionPolicy>(__exec),
__brick_copy<__hetero_tag<_BackendTag>, _ExecutionPolicy>{}, res_rng,
::std::forward<_Range>(__rng));
__pattern_walk_n(__tag, ::std::forward<_ExecutionPolicy>(__exec),
__brick_copy<__hetero_tag<_BackendTag>, _ExecutionPolicy>{}, res_rng,
::std::forward<_Range>(__rng));
return res;
}

Expand Down

0 comments on commit 1997370

Please sign in to comment.