-
Notifications
You must be signed in to change notification settings - Fork 117
Unify return type of oneapi::dpl::__Internal::__ranges::__pattern_minmax_element
#2496
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
base: main
Are you sure you want to change the base?
Changes from 57 commits
601bd65
d617268
36cc203
d774033
a1422c5
7f5257b
8aaad1a
4b4452d
c1c7fa8
095dead
8f01d1d
659ffeb
d8cd950
83462de
56db3b4
9b70191
ea5a684
e433702
b4ca0c9
4309083
435f5b4
fb22a88
d912ec8
a3b51b7
42ce3ba
0b445fa
6c0d832
d9b5da0
5196ffd
79b55d0
04b78fe
cac6744
5959306
a0e7610
e70a6c3
243dc62
33a7581
be15f37
c1d8d2c
30b1a23
86c79c2
ce40dfd
ea84263
b64c1c1
0636f9d
1b0b06b
646b9b2
71337cb
3d358e1
24d1f8a
90413ab
774da31
6f14490
053aa98
01a71e2
5feae77
2793222
077aca5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -1244,7 +1244,7 @@ __pattern_min_element_impl(_BackendTag __tag, _ExecutionPolicy&& __exec, _Range& | |||||
{ | ||||||
assert(oneapi::dpl::__ranges::__size(__rng) > 0); | ||||||
|
||||||
using _IteratorValueType = typename ::std::iterator_traits<decltype(__rng.begin())>::value_type; | ||||||
using _IteratorValueType = oneapi::dpl::__internal::__value_t<_Range>; | ||||||
using _IndexValueType = oneapi::dpl::__internal::__difference_t<_Range>; | ||||||
using _ReduceValueType = oneapi::dpl::__internal::tuple<_IndexValueType, _IteratorValueType>; | ||||||
|
||||||
|
@@ -1312,14 +1312,21 @@ __pattern_min(__hetero_tag<_BackendTag>, _ExecutionPolicy&& __exec, _R&& __r, _C | |||||
// minmax_element | ||||||
//------------------------------------------------------------------------ | ||||||
|
||||||
template <typename _Range> | ||||||
using __range_index_and_value = | ||||||
std::pair<oneapi::dpl::__internal::__difference_t<_Range>, oneapi::dpl::__internal::__value_t<_Range>>; | ||||||
|
||||||
template <typename _Range> | ||||||
using __pattern_minmax_element_impl_return_t = | ||||||
std::pair<__range_index_and_value<_Range>, __range_index_and_value<_Range>>; | ||||||
|
||||||
template <typename _BackendTag, typename _ExecutionPolicy, typename _Range, typename _Compare> | ||||||
std::pair<std::pair<oneapi::dpl::__internal::__difference_t<_Range>, oneapi::dpl::__internal::__value_t<_Range>>, | ||||||
std::pair<oneapi::dpl::__internal::__difference_t<_Range>, oneapi::dpl::__internal::__value_t<_Range>>> | ||||||
__pattern_minmax_element_impl_return_t<_Range> | ||||||
__pattern_minmax_element_impl(_BackendTag, _ExecutionPolicy&& __exec, _Range&& __rng, _Compare __comp) | ||||||
{ | ||||||
assert(oneapi::dpl::__ranges::__size(__rng) > 0); | ||||||
|
||||||
using _IteratorValueType = typename ::std::iterator_traits<decltype(__rng.begin())>::value_type; | ||||||
using _IteratorValueType = oneapi::dpl::__internal::__value_t<_Range>; | ||||||
using _IndexValueType = oneapi::dpl::__internal::__difference_t<_Range>; | ||||||
using _ReduceValueType = | ||||||
oneapi::dpl::__internal::tuple<_IndexValueType, _IndexValueType, _IteratorValueType, _IteratorValueType>; | ||||||
|
@@ -1333,48 +1340,52 @@ __pattern_minmax_element_impl(_BackendTag, _ExecutionPolicy&& __exec, _Range&& _ | |||||
// a `tuple` of `difference_type`, not the `difference_type` itself. | ||||||
oneapi::dpl::__internal::__pattern_minmax_element_transform_fn<_ReduceValueType> __transform_fn; | ||||||
|
||||||
const auto& [__idx_min, __idx_max, __min, __max] = | ||||||
const auto& [__idx_min, __idx_max, __val_min, __val_max] = | ||||||
oneapi::dpl::__par_backend_hetero::__parallel_transform_reduce<_ReduceValueType, | ||||||
::std::false_type /*is_commutative*/>( | ||||||
_BackendTag{}, ::std::forward<_ExecutionPolicy>(__exec), __reduce_fn, __transform_fn, | ||||||
unseq_backend::__no_init_value{}, // no initial value | ||||||
oneapi::dpl::__ranges::__get_subscription_view(std::forward<_Range>(__rng))) | ||||||
.get(); | ||||||
|
||||||
return {{__idx_min, __min}, {__idx_max, __max}}; | ||||||
return {{__idx_min, __val_min}, {__idx_max, __val_max}}; | ||||||
} | ||||||
|
||||||
template <typename _BackendTag, typename _ExecutionPolicy, typename _Range, typename _Compare> | ||||||
std::pair<oneapi::dpl::__internal::__difference_t<_Range>, oneapi::dpl::__internal::__difference_t<_Range>> | ||||||
std::pair<oneapi::dpl::__ranges::__iterator_t<_Range>, oneapi::dpl::__ranges::__iterator_t<_Range>> | ||||||
__pattern_minmax_element(__hetero_tag<_BackendTag>, _ExecutionPolicy&& __exec, _Range&& __rng, _Compare __comp) | ||||||
{ | ||||||
auto __begin = oneapi::dpl::__ranges::__begin(__rng); | ||||||
|
||||||
//If size == 1, result is the zero-indexed element. If size == 0, result is 0. | ||||||
if (oneapi::dpl::__ranges::__size(__rng) < 2) | ||||||
return {0, 0}; | ||||||
|
||||||
[[maybe_unused]] const auto& [__res_min, __res_max] = __pattern_minmax_element_impl( | ||||||
_BackendTag{}, std::forward<_ExecutionPolicy>(__exec), | ||||||
oneapi::dpl::__ranges::__get_subscription_view(std::forward<_Range>(__rng)), __comp); | ||||||
return {__begin, __begin}; | ||||||
|
||||||
[[maybe_unused]] const auto& [__idx_min, __min] = __res_min; | ||||||
[[maybe_unused]] const auto& [__idx_max, __max] = __res_max; | ||||||
__pattern_minmax_element_impl_return_t<_Range> __res = | ||||||
__pattern_minmax_element_impl(_BackendTag{}, std::forward<_ExecutionPolicy>(__exec), __rng, __comp); | ||||||
|
||||||
return {__idx_min, __idx_max}; | ||||||
return {__begin + __res.first.first, __begin + __res.second.first}; | ||||||
} | ||||||
|
||||||
#if _ONEDPL_CPP20_RANGES_PRESENT | ||||||
template <typename _BackendTag, typename _ExecutionPolicy, typename _R, typename _Proj, typename _Comp> | ||||||
std::pair<std::ranges::borrowed_iterator_t<_R>, std::ranges::borrowed_iterator_t<_R>> | ||||||
std::pair<std::ranges::iterator_t<_R>, std::ranges::iterator_t<_R>> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The return type should use
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Declined. As far as we apply the result of this function like in template <typename _ExecutionPolicy, typename _Range, typename _Compare>
oneapi::dpl::__internal::__enable_if_execution_policy<
_ExecutionPolicy,
::std::pair<oneapi::dpl::__internal::__difference_t<_Range>, oneapi::dpl::__internal::__difference_t<_Range>>>
minmax_element(_ExecutionPolicy&& __exec, _Range&& __rng, _Compare __comp)
{
const auto __dispatch_tag = oneapi::dpl::__ranges::__select_backend(__exec, __rng);
auto __begin = __rng.begin();
auto [__it_min, __it_max] = oneapi::dpl::__internal::__ranges::__pattern_minmax_element(
__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), views::all_read(__rng), __comp);
return {std::distance(__begin, __it_min), std::distance(__begin, __it_max)};
} we can't return Also this implementation of
SergeyKopienko marked this conversation as resolved.
Show resolved
Hide resolved
SergeyKopienko marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
__pattern_minmax_element(__hetero_tag<_BackendTag> __tag, _ExecutionPolicy&& __exec, _R&& __r, _Comp __comp, | ||||||
_Proj __proj) | ||||||
{ | ||||||
oneapi::dpl::__internal::__binary_op<_Comp, _Proj, _Proj> __comp_2{__comp, __proj, __proj}; | ||||||
|
||||||
const auto [__min_idx, __max_idx] = | ||||||
oneapi::dpl::__internal::__ranges::__pattern_minmax_element(__tag, std::forward<_ExecutionPolicy>(__exec), | ||||||
oneapi::dpl::__ranges::views::all_read(__r), __comp_2); | ||||||
auto __r_begin = __r.begin(); | ||||||
|
||||||
auto __view = oneapi::dpl::__ranges::views::all_read(__r); | ||||||
auto __v_begin = __view.begin(); | ||||||
using __v_iterator_t = decltype(__v_begin); | ||||||
|
||||||
return {std::ranges::begin(__r) + __min_idx, std::ranges::begin(__r) + __max_idx}; | ||||||
std::pair<__v_iterator_t, __v_iterator_t> __res = oneapi::dpl::__internal::__ranges::__pattern_minmax_element( | ||||||
__tag, std::forward<_ExecutionPolicy>(__exec), __view, __comp_2); | ||||||
|
||||||
return {__r_begin + std::ranges::distance(__v_begin, __res.first), | ||||||
__r_begin + std::ranges::distance(__v_begin, __res.second)}; | ||||||
} | ||||||
|
||||||
template <typename _BackendTag, typename _ExecutionPolicy, typename _R, typename _Proj, typename _Comp> | ||||||
|
@@ -1383,14 +1394,10 @@ __pattern_minmax(__hetero_tag<_BackendTag>, _ExecutionPolicy&& __exec, _R&& __r, | |||||
{ | ||||||
oneapi::dpl::__internal::__binary_op<_Comp, _Proj, _Proj> __comp_2{__comp, __proj, __proj}; | ||||||
|
||||||
[[maybe_unused]] const auto& [__res_min, __res_max] = | ||||||
__pattern_minmax_element_impl(_BackendTag{}, std::forward<_ExecutionPolicy>(__exec), | ||||||
oneapi::dpl::__ranges::__get_subscription_view(std::forward<_R>(__r)), __comp_2); | ||||||
|
||||||
[[maybe_unused]] const auto& [__idx_min, __min] = __res_min; | ||||||
[[maybe_unused]] const auto& [__idx_max, __max] = __res_max; | ||||||
__pattern_minmax_element_impl_return_t<_R> __res = __pattern_minmax_element_impl( | ||||||
_BackendTag{}, std::forward<_ExecutionPolicy>(__exec), std::forward<_R>(__r), __comp_2); | ||||||
|
||||||
return {__min, __max}; | ||||||
return {__res.first.second, __res.second.second}; | ||||||
} | ||||||
|
||||||
template <typename _BackendTag, typename _ExecutionPolicy, typename _R1, typename _R2, typename _Pred, typename _Proj1, | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This version of
minmax_element
is a part of experimental API which can accept a SYCl buffer. In that caseviews::all_read
returns a placeholder accessor.SYCL spec tells:
"... a placeholder accessor is not yet bound to a command group. Before such an accessor can be used in a command, it must be bound by calling handler::require(). Passing a placeholder accessor as an argument to a command without first being bound to a command group with handler::require() will result in undefined behavior."
So, a result of
accessor::begin()
call is undefined behavior.