Struct rustacuda::event::Event [−][src]
pub struct Event(_);
Expand description
An event to track work submitted to a stream.
See the module-level documentation for more information.
Implementations
Create a new event with the specified flags.
Example
use rustacuda::event::{Event, EventFlags}; // With default settings let event = Event::new(EventFlags::DEFAULT)?;
Add the event to the given stream of work. The event will be completed when the stream completes all previously-submitted work and reaches the event in the queue.
This function is used together with query
, synchronize
, and
elapsed_time_f32
. See the respective functions for more information.
If the event is created with EventFlags::BLOCKING_SYNC
, then record
blocks until the event has actually been recorded.
Errors
If the event and stream are not from the same context, an error is returned.
Example
use rustacuda::event::{Event, EventFlags}; let stream = Stream::new(StreamFlags::NON_BLOCKING, None)?; let event = Event::new(EventFlags::DEFAULT)?; // submit some work ... event.record(&stream)?; }
Return whether the stream this event was recorded on (see record
) has processed this event
yet or not. A return value of EventStatus::Ready
indicates that all work submitted before
the event has been completed.
Example
use rustacuda::event::{Event, EventFlags, EventStatus}; let stream = Stream::new(StreamFlags::NON_BLOCKING, None)?; let event = Event::new(EventFlags::DEFAULT)?; // do some work ... // record an event event.record(&stream)?; // ... wait some time ... // query if the work is finished let status = event.query()?; assert_eq!(status, EventStatus::Ready); }
Wait for an event to complete.
Blocks thread execution until all work submitted before the event was
recorded has completed. EventFlags::BLOCKING_SYNC
controls the mode of
blocking. If the flag is set on event creation, the thread will sleep.
Otherwise, the thread will busy-wait.
Example
use rustacuda::event::{Event, EventFlags}; let stream = Stream::new(StreamFlags::NON_BLOCKING, None)?; let event = Event::new(EventFlags::DEFAULT)?; // do some work ... // record an event event.record(&stream)?; // wait until the work is finished event.synchronize()?; }
Return the duration between two events.
The duration is computed in milliseconds with a resolution of approximately 0.5 microseconds. This can be used to measure the duration of work queued in between the two events.
Errors
CudaError::NotReady
is returned if either event is not yet complete.
CudaError::InvalidHandle
is returned if
- the two events are not from the same context, or if
record
has not been called on either event, or if- the
DISABLE_TIMING
flag is set on either event.
Example
use rustacuda::event::{Event, EventFlags}; let stream = Stream::new(StreamFlags::NON_BLOCKING, None)?; let start_event = Event::new(EventFlags::DEFAULT)?; let stop_event = Event::new(EventFlags::DEFAULT)?; // start recording time start_event.record(&stream)?; // do some work ... // stop recording time stop_event.record(&stream)?; // wait for the work to complete stop_event.synchronize()?; // compute the time elapsed between the start and stop events let time = stop_event.elapsed_time_f32(&start_event)?; }
Destroy an Event
returning an error.
Destroying an event can return errors from previous asynchronous work. This function destroys the given event and returns the error and the un-destroyed event on failure.
Example
use rustacuda::event::{Event, EventFlags}; let event = Event::new(EventFlags::DEFAULT)?; match Event::drop(event) { Ok(()) => println!("Successfully destroyed"), Err((cuda_error, event)) => { println!("Failed to destroy event: {:?}", cuda_error); // Do something with event }, }