pub struct Stream<'stream> { /* private fields */ }
host
only.Implementations§
source§impl<'stream> Stream<'stream>
impl<'stream> Stream<'stream>
sourcepub fn with<O>(
stream: &mut Stream,
inner: impl for<'new_stream> FnOnce(Stream<'new_stream>) -> O,
) -> O
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>§
sourcepub fn get_flags(&self) -> Result<StreamFlags, CudaError>
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());
sourcepub fn get_priority(&self) -> Result<i32, CudaError>
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()?);
sourcepub fn add_callback<T>(&self, callback: Box<T>) -> Result<(), CudaError>
pub fn add_callback<T>(&self, callback: Box<T>) -> Result<(), CudaError>
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
sourcepub fn synchronize(&self) -> Result<(), CudaError>
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()?;
sourcepub fn wait_event(
&self,
event: &Event,
flags: StreamWaitEventFlags,
) -> Result<(), CudaError>
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> ExtractDiscriminant for T
impl<T> ExtractDiscriminant for T
§type Discriminant = <T as ExtractDiscriminantSpec<<T as DiscriminantKind>::Discriminant>>::Ty
type Discriminant = <T as ExtractDiscriminantSpec<<T as DiscriminantKind>::Discriminant>>::Ty
core::mem::Discriminant
. Read more