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

[Perf] Break loop in __early_exit_find_or after first found element #1644

Merged
Merged
Changes from 9 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d4476b9
include/oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl.h - insert…
SergeyKopienko Jun 26, 2024
65b29e0
include/oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl.h - fix re…
SergeyKopienko Jun 26, 2024
3538d15
include/oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl.h - __some…
SergeyKopienko Jun 26, 2024
a934c68
include/oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl.h - analyz…
SergeyKopienko Jun 26, 2024
4a4b281
Revert "include/oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl.h …
SergeyKopienko Jun 26, 2024
39a7b6e
include/oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl.h - additi…
SergeyKopienko Jun 26, 2024
0ca5810
include/oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl.h - using …
SergeyKopienko Jun 26, 2024
7c66a61
include/oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl.h - introd…
SergeyKopienko Jun 26, 2024
42eb498
Merge branch 'dev/skopienko/tmp/fetch_min_fetch_max' into dev/skopien…
SergeyKopienko Jun 26, 2024
37d84c4
Revert "Merge branch 'dev/skopienko/tmp/fetch_min_fetch_max' into dev…
SergeyKopienko Jun 27, 2024
a91eab3
include/oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl.h - additi…
SergeyKopienko Jun 27, 2024
2b3c4e0
include/oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl.h - fix re…
SergeyKopienko Jun 27, 2024
ad012ea
include/oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl.h - additi…
SergeyKopienko Jun 27, 2024
7c10e91
include/oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl.h - introd…
SergeyKopienko Jun 27, 2024
371472d
Update include/oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl.h
SergeyKopienko Jun 27, 2024
0106e81
Update include/oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl.h
SergeyKopienko Jun 27, 2024
bf8cc73
Update include/oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl.h
SergeyKopienko Jun 27, 2024
dd9e1fc
Update include/oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl.h
SergeyKopienko Jun 27, 2024
afb624b
Update include/oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl.h
SergeyKopienko Jun 27, 2024
e64dab7
include/oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl.h - fix pe…
SergeyKopienko Jun 28, 2024
02287e3
include/oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl.h - fix pe…
SergeyKopienko Jun 28, 2024
343b61c
include/oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl.h - apply …
SergeyKopienko Jun 28, 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
42 changes: 29 additions & 13 deletions include/oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,11 @@ struct __early_exit_find_or
_LocalAtomic& __found_local, _BrickTag, _Ranges&&... __rngs) const
{
using __par_backend_hetero::__parallel_or_tag;

// There is 3 possible tag types here:
SergeyKopienko marked this conversation as resolved.
Show resolved Hide resolved
// - __parallel_find_forward_tag : in case when we find the first value in the data;
// - __parallel_find_backward_tag : in case when we find the last value in the data;
// - __parallel_or_tag : in case when we find any value in the data.
using _OrTagType = ::std::is_same<_BrickTag, __par_backend_hetero::__parallel_or_tag>;
using _BackwardTagType = ::std::is_same<typename _BrickTag::_Compare, oneapi::dpl::__internal::__pstl_greater>;

Expand Down Expand Up @@ -1068,16 +1073,21 @@ struct __early_exit_find_or
{
if constexpr (_OrTagType::value)
danhoeflinger marked this conversation as resolved.
Show resolved Hide resolved
{
// As far as we find any value of the data here, we can set the atomic value to 1
// No additional actions required.
__found_local.store(1);
break;
}
else
{
for (auto __old = __found_local.load(); __comp(__shifted_idx, __old); __old = __found_local.load())
{
__found_local.compare_exchange_strong(__old, __shifted_idx);
}
// As far as we find the first/last value of the data here, we need to set the atomic value to the index of the found data.
// But only in this case when this value is less (if we find the first value)/greater(if we find the last value) than the current value of the atomic.
SergeyKopienko marked this conversation as resolved.
Show resolved Hide resolved
if constexpr (!_BackwardTagType::value)
__found_local.fetch_min(__shifted_idx);
else
__found_local.fetch_max(__shifted_idx);
}

break;
julianmi marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand All @@ -1101,7 +1111,9 @@ __parallel_find_or(oneapi::dpl::__internal::__device_backend_tag, _ExecutionPoli
oneapi::dpl::__par_backend_hetero::__internal::__kernel_name_generator<__find_or_kernel, _CustomName, _Brick,
_BrickTag, _Ranges...>;

constexpr bool __or_tag_check = ::std::is_same_v<_BrickTag, __parallel_or_tag>;
constexpr bool __or_tag_check = std::is_same_v<_BrickTag, __parallel_or_tag>;
using _BackwardTagType = std::is_same<typename _BrickTag::_Compare, oneapi::dpl::__internal::__pstl_greater>;

auto __rng_n = oneapi::dpl::__ranges::__get_first_range_size(__rngs...);
assert(__rng_n > 0);

Expand Down Expand Up @@ -1165,16 +1177,20 @@ __parallel_find_or(oneapi::dpl::__internal::__device_backend_tag, _ExecutionPoli
__dpl_sycl::__group_barrier(__item_id);

// Set local atomic value to global atomic
if (__local_idx == 0 && __comp(__found_local.load(), __found.load()))
if (__local_idx == 0)
{
if constexpr (__or_tag_check)
__found.store(1);
else
const auto __found_local_state = __found_local.load();

if (__comp(__found_local_state, __found.load()))
{
for (auto __old = __found.load(); __comp(__found_local.load(), __old);
__old = __found.load())
if constexpr (__or_tag_check)
__found.store(1);
else
{
__found.compare_exchange_strong(__old, __found_local.load());
if constexpr (!_BackwardTagType::value)
__found.fetch_min(__found_local_state);
else
__found.fetch_max(__found_local_state);
}
}
}
Expand Down
Loading