Gromacs
2022.2
|
#include <gromacs/gpu_utils/gpueventsynchronizer.h>
A class which allows for CPU thread to mark and wait for certain GPU stream execution point.
The event can be put into the stream with markEvent and then later waited on with waitForEvent or enqueueWaitEvent.
Additionally, this class offers facilities for runtime checking of correctness by counting how many times each marked event is used as a synchronization point.
minConsumptionCount
) and maximal (maxConsumptionCount
) number of consumptions can be specified. By default, both are set to 1.c
equals maxConsumptionCount
.minConsumptionCount <= c <= maxConsumptionCount
.c < maxConsumptionCount
). Consuming the event increments c
by 1. Trying to consume fully consumed event throws gmx::InternalError.to
0. Marking is only possible if the event is sufficiently consumed, otherwise gmx::InternalError is thrown.Default minConsumptionCount=maxConsumptionCount=1
limits mean that each call to markEvent must be followed by exactly one enqueueWaitEvent or enqueueWaitEvent. This is the recommended pattern for most use cases. By providing other constructor arguments, this requirement can be relaxed as needed.
Public Member Functions | |
GpuEventSynchronizer (int minConsumptionCount, int maxConsumptionCount) | |
A constructor. | |
~GpuEventSynchronizer ()=default | |
A destructor. | |
GpuEventSynchronizer & | operator= (const GpuEventSynchronizer &)=delete |
Remove copy assignment, because we can not copy the underlying event object. | |
GpuEventSynchronizer (const GpuEventSynchronizer &)=delete | |
Remove copy constructor, because we can not copy the underlying event object. | |
GpuEventSynchronizer & | operator= (GpuEventSynchronizer &&)=delete |
Remove move assignment, because we don't allow moving the underlying event object. | |
GpuEventSynchronizer (GpuEventSynchronizer &&)=delete | |
Remove move constructor, because we don't allow moving the underlying event object. | |
void | markEvent (const DeviceStream &deviceStream) |
Marks the synchronization point in the stream and reset the consumption counter. More... | |
void | waitForEvent () |
Synchronizes the host thread on the marked event. More... | |
bool | isReady () |
Checks the completion of the underlying event and consumes the event if it is ready. | |
bool | isMarked () const |
Checks whether the event was marked (and was not reset since then). | |
void | consume () |
Manually consume the event without waiting for it. More... | |
void | resetIfFullyConsumed () |
Helper function to reset the event when it is fully consumed. | |
void | enqueueWaitEvent (const DeviceStream &deviceStream) |
Enqueues a wait for the recorded event in stream deviceStream . More... | |
void | reset () |
Resets the event to unmarked state, releasing the underlying event object if needed. | |
void | setConsumptionLimits (int minConsumptionCount, int maxConsumptionCount) |
Set the event consumption limits. | |
|
inline |
Manually consume the event without waiting for it.
If the event is already fully consumed, throws gmx::InternalError.
|
inline |
Enqueues a wait for the recorded event in stream deviceStream
.
Consumes the event if able, otherwise throws gmx::InternalError.
|
inline |
Marks the synchronization point in the stream
and reset the consumption counter.
Should be called before implicitly consuming actions (waitForEvent() or enqueueWaitEvent()) are executed or explicit consume() calls are made.
If the event has been marked before and not fully consumed, throws gmx::InternalError.
|
inline |
Synchronizes the host thread on the marked event.
Consumes the event if able, otherwise throws gmx::InternalError.