![]() |
NeuZephyr
Simple DL Framework
|
Internal event management system for CUDA stream synchronization (Part of StreamManager) More...
Public Member Functions | |
EventPool (const size_t maxEvent) | |
Construct an EventPool object with a specified maximum number of events. | |
~EventPool () | |
Destruct the EventPool object, releasing all managed CUDA events. | |
cudaEvent_t | recordData (cudaStream_t stream, void *data) |
Record an event in a CUDA stream associated with a given data pointer. | |
std::unordered_set< cudaEvent_t > | getEvents (void *data) |
Retrieve all CUDA events associated with a given data pointer. | |
void | syncData (void *data) |
Synchronize the program execution with the completion of all events associated with a given data pointer. | |
Internal event management system for CUDA stream synchronization (Part of StreamManager)
This class implements a thread-safe CUDA event pool with automatic recycling and data-aware synchronization capabilities. It serves as the foundational event infrastructure for nz::cuStrm::StreamManager's operation scheduling system.
cudaEventDisableTiming
events during initializationsyncData()
recordData()
:getEvents()
:syncData()
:The pool maintains three distinct event states to ensure safe CUDA event reuse:
cudaEvent_t
instances ready for allocation. Events are drawn from this pool when servicing new recording requests through acquire()
.acquire()
calls via the internal transfer()
method, ensuring safe temporal separation between event usage cycles and preventing premature reuse.std::lock_guard
for thread safetyDefinition at line 165 of file EventPool.cuh.
|
inlineexplicit |
Construct an EventPool object with a specified maximum number of events.
This constructor initializes an EventPool object with a given maximum number of CUDA events. It creates maxEvent
number of CUDA events with the cudaEventDisableTiming
flag and inserts them into the free
set, indicating that these events are initially available for use.
maxEvent | The maximum number of CUDA events that the EventPool can manage. Memory location: host. |
Memory management: The constructor allocates memory for CUDA events using cudaEventCreateWithFlags
. The responsibility of deallocating these events lies with the destructor of the EventPool
class. Exception handling: This constructor does not have an explicit exception - handling mechanism. It relies on the CUDA runtime to report any errors that occur during event creation. If an error occurs during cudaEventCreateWithFlags
, the program's behavior may be undefined. Relationship with other components: This constructor is part of the EventPool
class, which is likely used in a larger CUDA - related application to manage the lifecycle of CUDA events.
maxEvent
, as it iterates maxEvent
times to create and insert events.EventPool
object.Definition at line 191 of file EventPool.cuh.
|
inline |
Destruct the EventPool object, releasing all managed CUDA events.
This destructor iterates through the sets of free, busy, and released CUDA events and destroys each event using cudaEventDestroy
. This ensures that all resources allocated for these events are properly released.
None |
Memory management: The destructor is responsible for deallocating the memory associated with the CUDA events that were created during the lifetime of the EventPool
object. It destroys all events in the free
, busy
, and released
sets. Exception handling: This destructor does not have an explicit exception - handling mechanism. It relies on the CUDA runtime to report any errors that occur during event destruction. If an error occurs during cudaEventDestroy
, the program's behavior may be undefined. Relationship with other components: This destructor is part of the EventPool
class and is crucial for proper resource management in a CUDA - related application that uses the EventPool
to manage CUDA events.
free
, busy
, and released
sets combined.EventPool
object is destroyed.Definition at line 226 of file EventPool.cuh.
|
inline |
Retrieve all CUDA events associated with a given data pointer.
This function searches for the provided data pointer in the internal mapping and returns a set of all CUDA events associated with it. If no events are found for the given data pointer, an empty set is returned.
data | A pointer to the data for which the associated events are to be retrieved. Memory location: host or device, depending on the context. |
Memory management: The function does not allocate or deallocate any memory directly. It only accesses the internal mapping data structure of the EventPool
class. Exception handling: This function does not have an explicit exception - handling mechanism. It relies on the underlying standard library functions for std::unordered_map
operations. If an error occurs during the map lookup, the program's behavior may be undefined. Relationship with other components: This function is part of the EventPool
class. It interacts with the internal eventMap
data structure to retrieve the associated events.
std::unordered_map
for lookup. In the worst - case scenario, the time complexity is O(n), where n is the number of elements in the eventMap
.recordData
function to associate events with it. Definition at line 282 of file EventPool.cuh.
|
inline |
Record an event in a CUDA stream associated with a given data pointer.
This function records a CUDA event in the specified CUDA stream and associates it with the provided data pointer. It first acquires an available event from the event pool, then updates the mapping between data pointers and events and vice - versa. Finally, it records the event in the stream and returns the event handle.
stream | The CUDA stream in which the event will be recorded. Memory location: host. |
data | A pointer to the data associated with the event. Memory location: host or device, depending on the context. |
Memory management: The function does not allocate or deallocate any memory directly. It uses an existing event pool and updates mapping data structures. The responsibility of event memory management lies with the event pool's constructor and destructor. Exception handling: This function does not have an explicit exception - handling mechanism. It relies on the underlying CUDA functions (such as acquire
and record
) to report any errors. If an error occurs during event acquisition or recording, the program's behavior may be undefined. Relationship with other components: This function is part of the EventPool
class. It interacts with the event pool's internal state (event sets and mapping data structures) and the CUDA runtime to record events.
Definition at line 256 of file EventPool.cuh.
|
inline |
Synchronize the program execution with the completion of all events associated with a given data pointer.
This function waits until all CUDA events associated with the provided data pointer have completed. It uses a condition variable (cv
) to block the current thread until the eventMap
no longer contains any events for the given data pointer, indicating that all associated events have finished.
data | A pointer to the data for which the associated events need to be synchronized. Memory location: host or device, depending on the context. |
Memory management: The function does not allocate or deallocate any memory directly. It only accesses the internal eventMap
data structure of the EventPool
class. Exception handling: This function does not have an explicit exception - handling mechanism. It relies on the underlying standard library functions for mutex and condition variable operations. If an error occurs during locking, unlocking, or waiting, the program's behavior may be undefined. Relationship with other components: This function is part of the EventPool
class. It interacts with the internal eventMap
data structure and the condition variable (cv
) to wait for event completion.
recordData
function to associate events with it.eventMap
is updated correctly when events are completed to signal the condition variable. Definition at line 309 of file EventPool.cuh.