pub struct Event(/* private fields */);Expand description
An event to track work submitted to a stream.
See the module-level documentation for more information.
Implementations§
Source§impl Event
impl Event
Sourcepub fn new(flags: EventFlags) -> CudaResult<Self>
pub fn new(flags: EventFlags) -> CudaResult<Self>
Create a new event with the specified flags.
§Example
use rustacuda::event::{Event, EventFlags};
// With default settings
let event = Event::new(EventFlags::DEFAULT)?;Sourcepub fn record(&self, stream: &Stream) -> CudaResult<()>
pub fn record(&self, stream: &Stream) -> CudaResult<()>
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)?;
}Sourcepub fn query(&self) -> CudaResult<EventStatus>
pub fn query(&self) -> CudaResult<EventStatus>
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);
}Sourcepub fn synchronize(&self) -> CudaResult<()>
pub fn synchronize(&self) -> CudaResult<()>
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()?;
}Sourcepub fn elapsed_time_f32(&self, start: &Self) -> CudaResult<f32>
pub fn elapsed_time_f32(&self, start: &Self) -> CudaResult<f32>
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
recordhas not been called on either event, or if- the
DISABLE_TIMINGflag 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)?;
}Sourcepub fn drop(event: Event) -> DropResult<Event>
pub fn drop(event: Event) -> DropResult<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
},
}