pub struct Event { /* private fields */ }Expand description
A CUDA event for timing and synchronisation.
Events are lightweight markers that can be recorded into a
Stream. They support two primary use-cases:
- Timing — measure elapsed GPU time between two recorded events
via
Event::elapsed_time. - Synchronisation — make one stream wait for work recorded in
another stream via
Stream::wait_event.
Implementations§
Source§impl Event
impl Event
Sourcepub fn new() -> CudaResult<Self>
pub fn new() -> CudaResult<Self>
Creates a new event with CU_EVENT_DEFAULT flags.
Default events record timing data. Use Event::with_flags to
create events with different characteristics (e.g. disable timing
for lower overhead).
§Errors
Returns a CudaError if the driver
call fails.
Sourcepub fn with_flags(flags: u32) -> CudaResult<Self>
pub fn with_flags(flags: u32) -> CudaResult<Self>
Creates a new event with the specified flags.
Common flag values (from crate::ffi):
| Constant | Value | Description |
|---|---|---|
CU_EVENT_DEFAULT | 0 | Default (records timing) |
CU_EVENT_BLOCKING_SYNC | 1 | Use blocking synchronisation |
CU_EVENT_DISABLE_TIMING | 2 | Disable timing (lower overhead) |
CU_EVENT_INTERPROCESS | 4 | Usable across processes |
Flags can be combined with bitwise OR.
§Errors
Returns a CudaError if the flags
are invalid or the driver call otherwise fails.
Sourcepub fn record(&self, stream: &Stream) -> CudaResult<()>
pub fn record(&self, stream: &Stream) -> CudaResult<()>
Records this event on the given stream.
The event captures the point in the stream’s command queue at
which it was recorded. Subsequent calls to Event::synchronize
or Event::elapsed_time reference this recorded point.
§Errors
Returns a CudaError if the stream
or event handle is invalid.
Sourcepub fn query(&self) -> CudaResult<bool>
pub fn query(&self) -> CudaResult<bool>
Sourcepub fn synchronize(&self) -> CudaResult<()>
pub fn synchronize(&self) -> CudaResult<()>
Sourcepub fn elapsed_time(start: &Event, end: &Event) -> CudaResult<f32>
pub fn elapsed_time(start: &Event, end: &Event) -> CudaResult<f32>
Computes the elapsed time in milliseconds between two recorded events.
Both start and end must have been previously recorded on a
stream, and end must have completed (e.g. via
Event::synchronize).
§Errors
Returns a CudaError if either event
has not been recorded, or if timing data is not available (e.g.
the events were created with CU_EVENT_DISABLE_TIMING).