Struct rust_cuda::host::Stream

source ·
pub struct Stream<'stream> { /* private fields */ }
Available on crate feature host only.

Implementations§

source§

impl<'stream> Stream<'stream>

source

pub fn with<O>( stream: &mut Stream, inner: impl for<'new_stream> FnOnce(Stream<'new_stream>) -> O ) -> O

Create a new uniquely branded Stream, which can bind async operations to the Stream that they are computed on.

The uniqueness guarantees are provided by using branded types, as inspired by the Ghost Cell paper by Yanovski, J., Dang, H.-H., Jung, R., and Dreyer, D.: https://doi.org/10.1145/3473597.

§Examples

The following example shows that two Stream’s with different 'stream lifetime brands cannot be used interchangeably.

use rust_cuda::host::Stream;

fn check_same<'stream>(_stream_a: Stream<'stream>, _stream_b: Stream<'stream>) {}

fn two_streams<'stream_a, 'stream_b>(stream_a: Stream<'stream_a>, stream_b: Stream<'stream_b>) {
    check_same(stream_a, stream_b);
}

Methods from Deref<Target = Stream>§

source

pub fn get_flags(&self) -> Result<StreamFlags, CudaError>

Return the flags which were used to create this stream.

§Examples
use rustacuda::stream::{Stream, StreamFlags};

let stream = Stream::new(StreamFlags::NON_BLOCKING, None)?;
assert_eq!(StreamFlags::NON_BLOCKING, stream.get_flags().unwrap());
source

pub fn get_priority(&self) -> Result<i32, CudaError>

Return the priority of this stream.

If this stream was created without a priority, returns the default priority. If the stream was created with a priority outside the valid range, returns the clamped priority.

§Examples
use rustacuda::stream::{Stream, StreamFlags};

let stream = Stream::new(StreamFlags::NON_BLOCKING, 1i32.into())?;
println!("{}", stream.get_priority()?);
source

pub fn add_callback<T>(&self, callback: Box<T>) -> Result<(), CudaError>
where T: FnOnce(Result<(), CudaError>) + Send,

Add a callback to a stream.

The callback will be executed after all previously queued items in the stream have been completed. Subsequently queued items will not execute until the callback is finished.

Callbacks must not make any CUDA API calls.

The callback will be passed a CudaResult<()> indicating the current state of the device with Ok(()) denoting normal operation.

§Examples
use rustacuda::stream::{Stream, StreamFlags};

let stream = Stream::new(StreamFlags::NON_BLOCKING, 1i32.into())?;

// ... queue up some work on the stream

stream.add_callback(Box::new(|status| {
    println!("Device status is {:?}", status);
}));

// ... queue up some more work on the stream
source

pub fn synchronize(&self) -> Result<(), CudaError>

Wait until a stream’s tasks are completed.

Waits until the device has completed all operations scheduled for this stream.

§Examples
use rustacuda::stream::{Stream, StreamFlags};

let stream = Stream::new(StreamFlags::NON_BLOCKING, 1i32.into())?;

// ... queue up some work on the stream

// Wait for the work to be completed.
stream.synchronize()?;
source

pub fn wait_event( &self, event: &Event, flags: StreamWaitEventFlags ) -> Result<(), CudaError>

Make the stream wait on an event.

All future work submitted to the stream will wait for the event to complete. Synchronization is performed on the device, if possible. The event may originate from different context or device than the stream.

§Example
use rustacuda::stream::{Stream, StreamFlags, StreamWaitEventFlags};
use rustacuda::event::{Event, EventFlags};

let stream_0 = Stream::new(StreamFlags::NON_BLOCKING, None)?;
let stream_1 = Stream::new(StreamFlags::NON_BLOCKING, None)?;
let event = Event::new(EventFlags::DEFAULT)?;

// do some work on stream_0 ...

// record an event
event.record(&stream_0)?;

// wait until the work on stream_0 is finished before continuing stream_1
stream_1.wait_event(event, StreamWaitEventFlags::DEFAULT)?;
}

Trait Implementations§

source§

impl<'stream> Clone for Stream<'stream>

source§

fn clone(&self) -> Stream<'stream>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'stream> Deref for Stream<'stream>

§

type Target = Stream

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<'stream> Copy for Stream<'stream>

Auto Trait Implementations§

§

impl<'stream> Freeze for Stream<'stream>

§

impl<'stream> !PortableBitSemantics for Stream<'stream>

§

impl<'stream> RefUnwindSafe for Stream<'stream>

§

impl<'stream> !Send for Stream<'stream>

§

impl<'stream> !StackOnly for Stream<'stream>

§

impl<'stream> !Sync for Stream<'stream>

§

impl<'stream> Unpin for Stream<'stream>

§

impl<'stream> UnwindSafe for Stream<'stream>

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> ExtractDiscriminant for T

§

type Discriminant = <T as ExtractDiscriminantSpec<<T as DiscriminantKind>::Discriminant>>::Ty

The type of the discriminant, which must satisfy the trait bounds required by core::mem::Discriminant. 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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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

§

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.
§

impl<T> Erased for T