Gromacs  2024.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Variables
gpueventsynchronizer.h File Reference
#include "config.h"
#include "gromacs/utility/classhelpers.h"
#include "gromacs/utility/exceptions.h"
#include "gromacs/utility/gmxassert.h"
#include "device_event.h"
+ Include dependency graph for gpueventsynchronizer.h:
+ This graph shows which files directly or indirectly include this file:

Description

Implements a GpuEventSynchronizer class.

Author
Andrey Alekseenko al42a.nosp@m.nd@g.nosp@m.mail..nosp@m.com
Artem Zhmurov zhmur.nosp@m.ov@g.nosp@m.mail..nosp@m.com
Aleksei Iupinov a.yup.nosp@m.inov.nosp@m.@gmai.nosp@m.l.co.nosp@m.m

Variables

constexpr bool g_useEventConsumptionCounting = true
 A class which allows for CPU thread to mark and wait for certain GPU stream execution point. More...
 

Variable Documentation

constexpr bool g_useEventConsumptionCounting = true

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 GpuEventSynchronizer::markEvent and then later waited on with GpuEventSynchronizer::waitForEvent or GpuEventSynchronizer::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.

  • When the class is constructed, a required minimal (minConsumptionCount) and maximal (maxConsumptionCount) number of consumptions can be specified. By default, both are set to 1.
  • The event is considered fully consumed if its current number of consumptions c equals maxConsumptionCount.
  • The event is considered sufficiently consumed if minConsumptionCount <= c <= maxConsumptionCount.
  • The class is initialized in the fully consumed state, so it can not be consumed right away.
  • Consuming the event is only possible if it is not fully consumed (c < maxConsumptionCount). Consuming the event increments c by 1. Trying to consume fully consumed event throws gmx::InternalError.
  • GpuEventSynchronizer::reset returns object into the initial fully consumed state. This function is intended to manually override the consumption limits.
  • GpuEventSynchronizer::consume consumes the event, without doing anything else. This function is intended to manually override the consumption limits.
  • GpuEventSynchronizer::markEvent enqueues new event into the provided stream, and sets to 0. Marking is only possible if the event is sufficiently consumed, otherwise gmx::InternalError is thrown.
  • GpuEventSynchronizer::waitForEvent consumes the event and blocks the host thread until the event is ready (complete).
  • GpuEventSynchronizer::enqueueWaitEvent consumes the event and blocks the inserts a blocking barrier into the provided stream which blocks the execution of all tasks later submitted to this stream until the event is ready (completes).

Default minConsumptionCount=maxConsumptionCount=1 limits mean that each call to GpuEventSynchronizer::markEvent must be followed by exactly one GpuEventSynchronizer::enqueueWaitEvent or GpuEventSynchronizer::enqueueWaitEvent. This is the recommended pattern for most use cases. By providing other constructor arguments, this requirement can be relaxed as needed.