Skip to content

Commit

Permalink
Fix a subtle parameter expansion issue in sync info (#155)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
benson31 committed Aug 8, 2023
1 parent 12f0180 commit a0d3bbd
Showing 1 changed file with 4 additions and 23 deletions.
27 changes: 4 additions & 23 deletions include/hydrogen/SynchronizeAPI.hpp
Expand Up @@ -20,38 +20,19 @@ void AddSynchronizationPoint(SyncInfo<D> const &master,
// synchronization points. Skip "other" call recursively with the rest.
if (master.Stream() == other.Stream())
{
AddSynchronizationPoint(master, others...);
if constexpr (sizeof...(others) > 0UL)
AddSynchronizationPoint(master, others...);
return;
}
}
#endif // HYDROGEN_HAVE_GPU

AddSynchronizationPoint(master);
int dummy[] = {(details::AddSyncPoint(master, other),
details::AddSyncPoint(master, others), 0)...};
int dummy[] = {(details::AddSyncPoint(master, other), 0),
(details::AddSyncPoint(master, others), 0)...};
(void)dummy;
}

// Specialization of the above function for two arguments
template <Device D, Device D2>
void AddSynchronizationPoint(SyncInfo<D> const &master,
SyncInfo<D2> const &other)
{
#ifdef HYDROGEN_HAVE_GPU
if constexpr (D == Device::GPU && D == D2)
{
// When the two streams are the same, there is no need to create
// synchronization points.
if (master.Stream() == other.Stream())
{
return;
}
}
#endif // HYDROGEN_HAVE_GPU

AddSynchronizationPoint(master);
}

template <Device D, Device... Ds>
void AllWaitOnMaster(SyncInfo<D> const &master, SyncInfo<Ds> const &...others)
{
Expand Down

0 comments on commit a0d3bbd

Please sign in to comment.