pub struct StreamGuard { /* private fields */ }Expand description
RAII guard that sets a stream as the current CUDA stream and restores the previous stream on drop.
Nestable: inner guards restore the outer guard’s stream, not the
default stream. This is critical for DDP where sync_now_nccl
temporarily switches to comm_stream inside a compute_stream guard.
ⓘ
let compute = GpuStream::new(Device::CUDA(0), false)?;
let comm = GpuStream::new(Device::CUDA(0), false)?;
{
let _outer = StreamGuard::new(&compute);
// All CUDA ops on compute_stream.
{
let _inner = StreamGuard::new(&comm);
// CUDA ops on comm_stream.
}
// Restored to compute_stream (not default).
}
// Restored to whatever was current before _outer.Implementations§
Trait Implementations§
Source§impl Drop for StreamGuard
impl Drop for StreamGuard
Auto Trait Implementations§
impl !Send for StreamGuard
impl !Sync for StreamGuard
impl Freeze for StreamGuard
impl RefUnwindSafe for StreamGuard
impl Unpin for StreamGuard
impl UnsafeUnpin for StreamGuard
impl UnwindSafe for StreamGuard
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
Mutably borrows from an owned value. Read more