use crate::error::{self, Result}; use crate::ffi; pub struct CudaStream { raw: ffi::CudaStream, } impl CudaStream { pub fn new() -> Result { let mut raw = std::ptr::null_mut(); error::check(unsafe { ffi::cudaStreamCreate(&mut raw) })?; Ok(Self { raw }) } pub fn synchronize(&self) -> Result<()> { error::check(unsafe { ffi::cudaStreamSynchronize(self.raw) }) } pub fn as_raw(&self) -> ffi::CudaStream { self.raw } } impl Drop for CudaStream { fn drop(&mut self) { if !self.raw.is_null() { unsafe { ffi::cudaStreamDestroy(self.raw) }; } } } // Can move across threads, but not shared without synchronization unsafe impl Send for CudaStream {}