-
Notifications
You must be signed in to change notification settings - Fork 114
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
Re-implement SYCL backend parallel_for
to improve bandwidth utilization
#1976
base: main
Are you sure you want to change the base?
Changes from all commits
9764a57
c836b1d
55f33a4
adadd56
71d7bcc
ebb3d56
2c4ecd0
dc6bd0c
d5126b2
6433a50
d376124
a7c7606
b8aa15c
b45a7c2
4f9a360
7bb1d2b
a2ad920
47fe214
79a18e9
3ab8c75
4a70fe2
5530209
90f19d4
1ac65b9
6a5a562
357032f
ca9e594
e4060f5
283b053
75e4beb
7990bc1
4aaa81f
65e4a68
b4657a6
3086dd3
df17673
fd4e2c3
58fd466
094124f
82135f6
e979118
4bfaada
8ae18db
6cb11c7
505bdf3
114924d
845de21
71678d0
8b0b18b
f7d9753
83c5ca4
fedd5de
08aa260
a5eca96
32612a1
1336735
c5e7d61
0c6ca75
be8aeda
86b9c89
ffd95cc
537a6f0
50a60ea
1081ab8
9513edb
b274c8d
92f3374
eb2cdf8
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 |
---|---|---|
|
@@ -37,13 +37,19 @@ enum class search_algorithm | |
binary_search | ||
}; | ||
|
||
template <typename Comp, typename T, search_algorithm func> | ||
struct custom_brick | ||
#if _ONEDPL_BACKEND_SYCL | ||
template <typename Comp, typename T, typename _Range, search_algorithm func> | ||
struct custom_brick : oneapi::dpl::unseq_backend::walk_scalar_base<_Range> | ||
{ | ||
Comp comp; | ||
T size; | ||
bool use_32bit_indexing; | ||
|
||
custom_brick(Comp comp, T size, bool use_32bit_indexing) | ||
: comp(comp), size(size), use_32bit_indexing(use_32bit_indexing) | ||
{ | ||
} | ||
|
||
template <typename _Size, typename _ItemId, typename _Acc> | ||
void | ||
search_impl(_ItemId idx, _Acc acc) const | ||
|
@@ -68,17 +74,23 @@ struct custom_brick | |
get<2>(acc[idx]) = (value != end_orig) && (get<1>(acc[idx]) == get<0>(acc[value])); | ||
} | ||
} | ||
|
||
template <typename _ItemId, typename _Acc> | ||
template <typename _IsFull, typename _ItemId, typename _Acc> | ||
void | ||
operator()(_ItemId idx, _Acc acc) const | ||
__scalar_path_impl(_IsFull, _ItemId idx, _Acc acc) const | ||
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. I believe that we may try to improve this code by replacing run-time const bool use_32bit_indexing = size <= std::numeric_limits<std::uint32_t>::max(); so it's not big deal to add 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. As discussed offline, I will reevaluate performance here and provide an update. The advantage of the current approach is that we only compile a single kernel whereas your suggestion may improve kernel performance with the cost of increased JIT overhead. |
||
{ | ||
if (use_32bit_indexing) | ||
search_impl<std::uint32_t>(idx, acc); | ||
else | ||
search_impl<std::uint64_t>(idx, acc); | ||
} | ||
template <typename _IsFull, typename _ItemId, typename _Acc> | ||
void | ||
operator()(_IsFull __is_full, _ItemId idx, _Acc acc) const | ||
{ | ||
__scalar_path_impl(__is_full, idx, acc); | ||
} | ||
}; | ||
#endif | ||
|
||
template <class _Tag, typename Policy, typename InputIterator1, typename InputIterator2, typename OutputIterator, | ||
typename StrictWeakOrdering> | ||
|
@@ -155,7 +167,8 @@ lower_bound_impl(__internal::__hetero_tag<_BackendTag>, Policy&& policy, InputIt | |
const bool use_32bit_indexing = size <= std::numeric_limits<std::uint32_t>::max(); | ||
__bknd::__parallel_for( | ||
_BackendTag{}, ::std::forward<decltype(policy)>(policy), | ||
custom_brick<StrictWeakOrdering, decltype(size), search_algorithm::lower_bound>{comp, size, use_32bit_indexing}, | ||
custom_brick<StrictWeakOrdering, decltype(size), decltype(zip_vw), search_algorithm::lower_bound>{ | ||
danhoeflinger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
comp, size, use_32bit_indexing}, | ||
value_size, zip_vw) | ||
.__deferrable_wait(); | ||
return result + value_size; | ||
|
@@ -187,7 +200,8 @@ upper_bound_impl(__internal::__hetero_tag<_BackendTag>, Policy&& policy, InputIt | |
const bool use_32bit_indexing = size <= std::numeric_limits<std::uint32_t>::max(); | ||
__bknd::__parallel_for( | ||
_BackendTag{}, std::forward<decltype(policy)>(policy), | ||
custom_brick<StrictWeakOrdering, decltype(size), search_algorithm::upper_bound>{comp, size, use_32bit_indexing}, | ||
custom_brick<StrictWeakOrdering, decltype(size), decltype(zip_vw), search_algorithm::upper_bound>{ | ||
comp, size, use_32bit_indexing}, | ||
value_size, zip_vw) | ||
.__deferrable_wait(); | ||
return result + value_size; | ||
|
@@ -217,10 +231,11 @@ binary_search_impl(__internal::__hetero_tag<_BackendTag>, Policy&& policy, Input | |
auto result_buf = keep_result(result, result + value_size); | ||
auto zip_vw = make_zip_view(input_buf.all_view(), value_buf.all_view(), result_buf.all_view()); | ||
const bool use_32bit_indexing = size <= std::numeric_limits<std::uint32_t>::max(); | ||
__bknd::__parallel_for(_BackendTag{}, std::forward<decltype(policy)>(policy), | ||
custom_brick<StrictWeakOrdering, decltype(size), search_algorithm::binary_search>{ | ||
comp, size, use_32bit_indexing}, | ||
value_size, zip_vw) | ||
__bknd::__parallel_for( | ||
_BackendTag{}, std::forward<decltype(policy)>(policy), | ||
custom_brick<StrictWeakOrdering, decltype(size), decltype(zip_vw), search_algorithm::binary_search>{ | ||
comp, size, use_32bit_indexing}, | ||
value_size, zip_vw) | ||
.__deferrable_wait(); | ||
return result + value_size; | ||
} | ||
|
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.
Lets fix the naming of this while were touching all its instances
__custom_brick
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.
It seems that the historical convention within the
internal/
directory is to not use any leading underscores although it has changed a bit over time.I do not have a strong preference if we make this change or leave it as is, but maybe it fits in a broader discussion regarding the remaining implementations in this directory.
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.
I'm not sure if there is compelling reason other than resistance to making purely cosmetic changes in the changelog to have a different convention here. This is why I suggest adjusting it while we are already touching all (or most) instances of it. Perhaps someone with a longer historical knowledge of this code could chime in here if there is a reason to keep this with different conventions.
Not super important to me, so optional nitpick.
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.
I will wait a bit longer to see if anyone has objections. If not, then I will add this suggestion.