Event

Struct Event 

Source
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

Source

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)?;
Source

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)?;
}
Source

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);
}
Source

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()?;
}
Source

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
  • 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)?;

}
Source

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
    },
}

Trait Implementations§

Source§

impl Debug for Event

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Event

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl Freeze for Event

§

impl RefUnwindSafe for Event

§

impl !Send for Event

§

impl !Sync for Event

§

impl Unpin for Event

§

impl UnwindSafe for Event

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.