Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pack __parallel_for and etc. calls into __internal::__except_handler #1458

Merged
merged 30 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
732a54a
Pack __parallel_copy_if calls into __except_handler
Mar 13, 2024
578b104
Pack __parallel_find calls into __except_handler
Mar 13, 2024
0e2db3c
Pack __parallel_find_or calls into __except_handler
Mar 13, 2024
012dcf4
Pack __parallel_for calls into __except_handler
Mar 13, 2024
0d4e36f
Pack __parallel_merge calls into __except_handler
Mar 13, 2024
ddeb81b
Pack __parallel_or calls into __except_handler
Mar 13, 2024
ab6baba
Pack __parallel_partial_sort calls into __except_handler
Mar 13, 2024
4b224c2
Pack __parallel_scan_copy calls into __except_handler
Mar 13, 2024
3fb4155
Pack __parallel_set_op calls into __except_handler
Mar 13, 2024
29949dd
Pack __parallel_set_union_op calls into __except_handler
Mar 13, 2024
fb8231d
Pack __parallel_stable_sort calls into __except_handler
Mar 13, 2024
9fba93f
Pack __parallel_transform_reduce calls into __except_handler
Mar 13, 2024
53031d9
Pack __parallel_transform_scan calls into __except_handler
Mar 13, 2024
d2f5362
Pack __parallel_transform_scan_base calls into __except_handler
Mar 13, 2024
cac7725
Pack __pattern_fill_async calls into __except_handler
Mar 13, 2024
bee2aed
Pack __pattern_transform_reduce_async calls into __except_handler
Mar 13, 2024
3938c73
Pack __pattern_transform_scan_async calls into __except_handler
Mar 13, 2024
690591b
Pack __pattern_walk1_async calls into __except_handler
Mar 13, 2024
3602c78
Pack __pattern_walk2_async calls into __except_handler
Mar 13, 2024
e7b7c77
Pack __pattern_walk2_brick_async calls into __except_handler
Mar 13, 2024
6471a42
Pack __pattern_walk3_async calls into __except_handler
Mar 13, 2024
35fec88
Apply GitHUB clang format
Mar 21, 2024
3c14b3f
Directly return result from __except_handler without temporary local …
Mar 21, 2024
41819d7
include/oneapi/dpl/pstl/hetero/algorithm_ranges_impl_hetero.h - fix s…
Mar 21, 2024
237419b
Revert changes from files inside include/oneapi/dpl/pstl/hetero folder
Mar 21, 2024
9e28c6c
include/oneapi/dpl/pstl/hetero/numeric_impl_hetero.h - fix review com…
Mar 21, 2024
d420aa9
include/oneapi/dpl/pstl/hetero/algorithm_ranges_impl_hetero.h - fix s…
Mar 21, 2024
77020ee
include/oneapi/dpl/pstl/hetero/algorithm_impl_hetero.h - fix spelling…
Mar 21, 2024
858d369
include/oneapi/dpl/internal/async_impl/glue_async_impl.h - fix review…
Mar 21, 2024
e35db5d
include/oneapi/dpl/internal/binary_search_impl.h - fix review comment…
Mar 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
223 changes: 122 additions & 101 deletions include/oneapi/dpl/pstl/algorithm_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1719,11 +1719,14 @@ __pattern_reverse(__parallel_tag<_IsVector>, _ExecutionPolicy&& __exec, _RandomA
if (__first == __last)
return;

__par_backend::__parallel_for(
__backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __first, __first + (__last - __first) / 2,
[__first, __last](_RandomAccessIterator __inner_first, _RandomAccessIterator __inner_last) {
__internal::__brick_reverse(__inner_first, __inner_last, __last - (__inner_first - __first), _IsVector{});
});
__internal::__except_handler([&]() {
__par_backend::__parallel_for(
__backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __first, __first + (__last - __first) / 2,
[__first, __last](_RandomAccessIterator __inner_first, _RandomAccessIterator __inner_last) {
__internal::__brick_reverse(__inner_first, __inner_last, __last - (__inner_first - __first),
_IsVector{});
});
});
}

//------------------------------------------------------------------------
Expand Down Expand Up @@ -1772,13 +1775,15 @@ __pattern_reverse_copy(__parallel_tag<_IsVector>, _ExecutionPolicy&& __exec, _Ra
if (__len == 0)
return __d_first;

__par_backend::__parallel_for(
__backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __first, __last,
[__first, __len, __d_first](_RandomAccessIterator1 __inner_first, _RandomAccessIterator1 __inner_last) {
__internal::__brick_reverse_copy(__inner_first, __inner_last,
__d_first + (__len - (__inner_last - __first)), _IsVector{});
});
return __d_first + __len;
return __internal::__except_handler([&]() {
__par_backend::__parallel_for(
__backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __first, __last,
[__first, __len, __d_first](_RandomAccessIterator1 __inner_first, _RandomAccessIterator1 __inner_last) {
__internal::__brick_reverse_copy(__inner_first, __inner_last,
__d_first + (__len - (__inner_last - __first)), _IsVector{});
});
return __d_first + __len;
});
}

//------------------------------------------------------------------------
Expand Down Expand Up @@ -1950,29 +1955,31 @@ __pattern_rotate_copy(__parallel_tag<_IsVector>, _ExecutionPolicy&& __exec, _Ran
{
using __backend_tag = typename __parallel_tag<_IsVector>::__backend_tag;

__par_backend::__parallel_for(
__backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __first, __last,
[__first, __last, __middle, __result](_RandomAccessIterator1 __b, _RandomAccessIterator1 __e) {
__internal::__brick_copy<__parallel_tag<_IsVector>, _ExecutionPolicy> __copy{};
if (__b > __middle)
{
__copy(__b, __e, __result + (__b - __middle), _IsVector{});
}
else
{
_RandomAccessIterator2 __new_result = __result + ((__last - __middle) + (__b - __first));
if (__e < __middle)
return __internal::__except_handler([&]() {
__par_backend::__parallel_for(
__backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __first, __last,
[__first, __last, __middle, __result](_RandomAccessIterator1 __b, _RandomAccessIterator1 __e) {
__internal::__brick_copy<__parallel_tag<_IsVector>, _ExecutionPolicy> __copy{};
if (__b > __middle)
{
__copy(__b, __e, __new_result, _IsVector{});
__copy(__b, __e, __result + (__b - __middle), _IsVector{});
SergeyKopienko marked this conversation as resolved.
Show resolved Hide resolved
}
else
{
__copy(__b, __middle, __new_result, _IsVector{});
__copy(__middle, __e, __result, _IsVector{});
_RandomAccessIterator2 __new_result = __result + ((__last - __middle) + (__b - __first));
if (__e < __middle)
{
__copy(__b, __e, __new_result, _IsVector{});
}
else
{
__copy(__b, __middle, __new_result, _IsVector{});
__copy(__middle, __e, __result, _IsVector{});
}
}
}
});
return __result + (__last - __first);
});
return __result + (__last - __first);
});
}

//------------------------------------------------------------------------
Expand Down Expand Up @@ -3025,13 +3032,16 @@ __pattern_merge(__parallel_tag<_IsVector>, _ExecutionPolicy&& __exec, _RandomAcc
{
using __backend_tag = typename __parallel_tag<_IsVector>::__backend_tag;

__par_backend::__parallel_merge(
__backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, __d_first,
__comp,
[](_RandomAccessIterator1 __f1, _RandomAccessIterator1 __l1, _RandomAccessIterator2 __f2,
_RandomAccessIterator2 __l2, _RandomAccessIterator3 __f3,
_Compare __comp) { return __internal::__brick_merge(__f1, __l1, __f2, __l2, __f3, __comp, _IsVector{}); });
return __d_first + (__last1 - __first1) + (__last2 - __first2);
return __internal::__except_handler([&]() {
__par_backend::__parallel_merge(
__backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, __d_first,
__comp,
[](_RandomAccessIterator1 __f1, _RandomAccessIterator1 __l1, _RandomAccessIterator2 __f2,
_RandomAccessIterator2 __l2, _RandomAccessIterator3 __f3, _Compare __comp) {
return __internal::__brick_merge(__f1, __l1, __f2, __l2, __f3, __comp, _IsVector{});
});
return __d_first + (__last1 - __first1) + (__last2 - __first2);
});
}

//------------------------------------------------------------------------
Expand Down Expand Up @@ -3533,29 +3543,33 @@ __pattern_set_intersection(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& _
if (__m1 > __set_algo_cut_off)
{
//we know proper offset due to [first1; left_bound_seq_1) < [first2; last2)
return __internal::__parallel_set_op(
__tag, ::std::forward<_ExecutionPolicy>(__exec), __left_bound_seq_1, __last1, __first2, __last2, __result,
__comp, [](_DifferenceType __n, _DifferenceType __m) { return ::std::min(__n, __m); },
[](_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2,
_RandomAccessIterator2 __last2, _T* __result, _Compare __comp) {
return oneapi::dpl::__utils::__set_intersection_construct(__first1, __last1, __first2, __last2,
__result, __comp);
});
return __internal::__except_handler([&]() {
return __internal::__parallel_set_op(
__tag, ::std::forward<_ExecutionPolicy>(__exec), __left_bound_seq_1, __last1, __first2, __last2,
__result, __comp, [](_DifferenceType __n, _DifferenceType __m) { return ::std::min(__n, __m); },
[](_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2,
_RandomAccessIterator2 __last2, _T* __result, _Compare __comp) {
return oneapi::dpl::__utils::__set_intersection_construct(__first1, __last1, __first2, __last2,
__result, __comp);
});
});
}

const auto __m2 = __last2 - __left_bound_seq_2 + __n1;
if (__m2 > __set_algo_cut_off)
{
//we know proper offset due to [first2; left_bound_seq_2) < [first1; last1)
__result = __internal::__parallel_set_op(
__tag, ::std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __left_bound_seq_2, __last2, __result,
__comp, [](_DifferenceType __n, _DifferenceType __m) { return ::std::min(__n, __m); },
[](_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2,
_RandomAccessIterator2 __last2, _T* __result, _Compare __comp) {
return oneapi::dpl::__utils::__set_intersection_construct(__first2, __last2, __first1, __last1,
__result, __comp);
});
return __result;
return __internal::__except_handler([&]() {
__result = __internal::__parallel_set_op(
__tag, ::std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __left_bound_seq_2, __last2,
__result, __comp, [](_DifferenceType __n, _DifferenceType __m) { return ::std::min(__n, __m); },
[](_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2,
_RandomAccessIterator2 __last2, _T* __result, _Compare __comp) {
return oneapi::dpl::__utils::__set_intersection_construct(__first2, __last2, __first1, __last1,
__result, __comp);
});
return __result;
});
}

// [left_bound_seq_1; last1) and [left_bound_seq_2; last2) - use serial algorithm
Expand Down Expand Up @@ -3701,13 +3715,15 @@ __pattern_set_symmetric_difference(__parallel_tag<_IsVector> __tag, _ExecutionPo
return ::std::set_symmetric_difference(__first1, __last1, __first2, __last2, __result, __comp);

typedef typename ::std::iterator_traits<_RandomAccessIterator3>::value_type _T;
return __internal::__parallel_set_union_op(
__tag, ::std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, __result, __comp,
[](_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2,
_RandomAccessIterator2 __last2, _T* __result, _Compare __comp) {
return oneapi::dpl::__utils::__set_symmetric_difference_construct(
__first1, __last1, __first2, __last2, __result, __comp, __BrickCopyConstruct<_IsVector>());
});
return __internal::__except_handler([&]() {
return __internal::__parallel_set_union_op(
__tag, ::std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, __result, __comp,
[](_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2,
_RandomAccessIterator2 __last2, _T* __result, _Compare __comp) {
return oneapi::dpl::__utils::__set_symmetric_difference_construct(
__first1, __last1, __first2, __last2, __result, __comp, __BrickCopyConstruct<_IsVector>());
});
});
}

//------------------------------------------------------------------------
Expand Down Expand Up @@ -4129,30 +4145,33 @@ __pattern_lexicographical_compare(__parallel_tag<_IsVector> __tag, _ExecutionPol
{
typedef typename ::std::iterator_traits<_RandomAccessIterator1>::reference _RefType1;
typedef typename ::std::iterator_traits<_RandomAccessIterator2>::reference _RefType2;
--__last1;
--__last2;
auto __n = ::std::min(__last1 - __first1, __last2 - __first2);
auto __result = __internal::__parallel_find(
__tag, ::std::forward<_ExecutionPolicy>(__exec), __first1, __first1 + __n,
[__first1, __first2, &__comp](_RandomAccessIterator1 __i, _RandomAccessIterator1 __j) {
return __internal::__brick_mismatch(
__i, __j, __first2 + (__i - __first1), __first2 + (__j - __first1),
[&__comp](const _RefType1 __x, const _RefType2 __y) {
return !__comp(__x, __y) && !__comp(__y, __x);
},
_IsVector{})
.first;
},
::std::true_type{});

if (__result == __last1 && __first2 + (__result - __first1) != __last2)
{ // if first sequence shorter than second
return !__comp(*(__first2 + (__result - __first1)), *__result);
}
else
{ // if second sequence shorter than first or both have the same number of elements
return __comp(*__result, *(__first2 + (__result - __first1)));
}
return __internal::__except_handler([&]() {
--__last1;
--__last2;
auto __n = ::std::min(__last1 - __first1, __last2 - __first2);
auto __result = __internal::__parallel_find(
__tag, ::std::forward<_ExecutionPolicy>(__exec), __first1, __first1 + __n,
[__first1, __first2, &__comp](_RandomAccessIterator1 __i, _RandomAccessIterator1 __j) {
return __internal::__brick_mismatch(
__i, __j, __first2 + (__i - __first1), __first2 + (__j - __first1),
[&__comp](const _RefType1 __x, const _RefType2 __y) {
return !__comp(__x, __y) && !__comp(__y, __x);
},
_IsVector{})
.first;
},
::std::true_type{});

if (__result == __last1 && __first2 + (__result - __first1) != __last2)
{ // if first sequence shorter than second
return !__comp(*(__first2 + (__result - __first1)), *__result);
}
else
{ // if second sequence shorter than first or both have the same number of elements
return __comp(*__result, *(__first2 + (__result - __first1)));
}
});
}
}

Expand Down Expand Up @@ -4268,30 +4287,32 @@ __pattern_shift_left(__parallel_tag<_IsVector>, _ExecutionPolicy&& __exec, _Rand
_DiffType __mid = __size / 2 + __size % 2;
_DiffType __size_res = __size - __n;

//1. n >= size/2; there is enough memory to 'total' parallel copying
if (__n >= __mid)
{
__par_backend::__parallel_for(__backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __n, __size,
[__first, __n](_DiffType __i, _DiffType __j) {
__brick_move<__parallel_tag<_IsVector>, _ExecutionPolicy>{}(
__first + __i, __first + __j, __first + __i - __n, _IsVector{});
});
}
else //2. n < size/2; there is not enough memory to parallel copying; doing parallel copying by n elements
{
//TODO: to consider parallel processing by the 'internal' loop (but we may probably get cache locality issues)
for (auto __k = __n; __k < __size; __k += __n)
return __internal::__except_handler([&]() {
//1. n >= size/2; there is enough memory to 'total' parallel copying
if (__n >= __mid)
{
auto __end = ::std::min(__k + __n, __size);
__par_backend::__parallel_for(__backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __k, __end,
__par_backend::__parallel_for(__backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __n, __size,
[__first, __n](_DiffType __i, _DiffType __j) {
__brick_move<__parallel_tag<_IsVector>, _ExecutionPolicy>{}(
__first + __i, __first + __j, __first + __i - __n, _IsVector{});
});
}
}
else //2. n < size/2; there is not enough memory to parallel copying; doing parallel copying by n elements
{
//TODO: to consider parallel processing by the 'internal' loop (but we may probably get cache locality issues)
for (auto __k = __n; __k < __size; __k += __n)
{
auto __end = ::std::min(__k + __n, __size);
__par_backend::__parallel_for(__backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __k, __end,
[__first, __n](_DiffType __i, _DiffType __j) {
__brick_move<__parallel_tag<_IsVector>, _ExecutionPolicy>{}(
__first + __i, __first + __j, __first + __i - __n, _IsVector{});
});
}
}

return __first + __size_res;
return __first + __size_res;
});
}

template <class _Tag, class _ExecutionPolicy, class _BidirectionalIterator>
Expand Down
4 changes: 2 additions & 2 deletions include/oneapi/dpl/pstl/hetero/algorithm_impl_hetero.h
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ __pattern_adjacent_find(__hetero_tag<_BackendTag>, _ExecutionPolicy&& __exec, _I
auto __keep2 = oneapi::dpl::__ranges::__get_sycl_range<__par_backend_hetero::access_mode::read, _Iterator>();
auto __buf2 = __keep2(__first + 1, __last);

// TODO: in case of confilicting names
// TODO: in case of conflicting names
// __par_backend_hetero::make_wrapped_policy<__par_backend_hetero::__or_policy_wrapper>()
bool result = __par_backend_hetero::__parallel_find_or(
_BackendTag{}, ::std::forward<_ExecutionPolicy>(__exec),
Expand Down Expand Up @@ -688,7 +688,7 @@ __pattern_equal(__hetero_tag<_BackendTag>, _ExecutionPolicy&& __exec, _Iterator1
auto __keep2 = oneapi::dpl::__ranges::__get_sycl_range<__par_backend_hetero::access_mode::read, _Iterator2>();
auto __buf2 = __keep2(__first2, __last2);

// TODO: in case of confilicting names
// TODO: in case of conflicting names
// __par_backend_hetero::make_wrapped_policy<__par_backend_hetero::__or_policy_wrapper>()
return !__par_backend_hetero::__parallel_find_or(
_BackendTag{}, ::std::forward<_ExecutionPolicy>(__exec), _Predicate{equal_predicate<_Pred>{__pred}},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ __pattern_equal(__hetero_tag<_BackendTag>, _ExecutionPolicy&& __exec, _Range1&&

using _Predicate = oneapi::dpl::unseq_backend::single_match_pred<_ExecutionPolicy, equal_predicate<_Pred>>;

// TODO: in case of confilicting names
// TODO: in case of conflicting names
// __par_backend_hetero::make_wrapped_policy<__par_backend_hetero::__or_policy_wrapper>()
return !oneapi::dpl::__par_backend_hetero::__parallel_find_or(
_BackendTag{}, ::std::forward<_ExecutionPolicy>(__exec), _Predicate{equal_predicate<_Pred>{__pred}},
Expand Down
Loading
Loading