Skip to content

Commit a0d3bbd

Browse files
authored
Fix a subtle parameter expansion issue in sync info (#155)
It's mildly unfortunate that the function for recording the event on a SyncInfo is called "AddSynchronizationPoint". Thus we need an explicit `if constexpr` to stop the recursion such that the event record is actually avoided when we don't need it. C'est la vie.
1 parent 12f0180 commit a0d3bbd

File tree

1 file changed

+4
-23
lines changed

1 file changed

+4
-23
lines changed

include/hydrogen/SynchronizeAPI.hpp

+4-23
Original file line numberDiff line numberDiff line change
@@ -20,38 +20,19 @@ void AddSynchronizationPoint(SyncInfo<D> const &master,
2020
// synchronization points. Skip "other" call recursively with the rest.
2121
if (master.Stream() == other.Stream())
2222
{
23-
AddSynchronizationPoint(master, others...);
23+
if constexpr (sizeof...(others) > 0UL)
24+
AddSynchronizationPoint(master, others...);
2425
return;
2526
}
2627
}
2728
#endif // HYDROGEN_HAVE_GPU
2829

2930
AddSynchronizationPoint(master);
30-
int dummy[] = {(details::AddSyncPoint(master, other),
31-
details::AddSyncPoint(master, others), 0)...};
31+
int dummy[] = {(details::AddSyncPoint(master, other), 0),
32+
(details::AddSyncPoint(master, others), 0)...};
3233
(void)dummy;
3334
}
3435

35-
// Specialization of the above function for two arguments
36-
template <Device D, Device D2>
37-
void AddSynchronizationPoint(SyncInfo<D> const &master,
38-
SyncInfo<D2> const &other)
39-
{
40-
#ifdef HYDROGEN_HAVE_GPU
41-
if constexpr (D == Device::GPU && D == D2)
42-
{
43-
// When the two streams are the same, there is no need to create
44-
// synchronization points.
45-
if (master.Stream() == other.Stream())
46-
{
47-
return;
48-
}
49-
}
50-
#endif // HYDROGEN_HAVE_GPU
51-
52-
AddSynchronizationPoint(master);
53-
}
54-
5536
template <Device D, Device... Ds>
5637
void AllWaitOnMaster(SyncInfo<D> const &master, SyncInfo<Ds> const &...others)
5738
{

0 commit comments

Comments
 (0)