Executes a given closure in a specific CUDA [`Stream`], specifically, it sets the current cublas stream for the context, runs the closure, then unsets the stream back to NULL.
(
&mut self,
stream: &Stream,
func: F,
)
| 126 | /// Executes a given closure in a specific CUDA [`Stream`], specifically, it sets the current cublas stream |
| 127 | /// for the context, runs the closure, then unsets the stream back to NULL. |
| 128 | pub fn with_stream<T, F: FnOnce(&mut Self) -> Result<T>>( |
| 129 | &mut self, |
| 130 | stream: &Stream, |
| 131 | func: F, |
| 132 | ) -> Result<T> { |
| 133 | unsafe { |
| 134 | // cudaStream_t is the same as CUstream |
| 135 | sys::v2::cublasSetStream_v2(self.raw, mem::transmute(stream.as_inner())).to_result()?; |
| 136 | let res = func(self)?; |
| 137 | // reset the stream back to NULL just in case someone calls with_stream, then drops the stream, and tries to |
| 138 | // execute a raw sys function with the context's handle. |
| 139 | sys::v2::cublasSetStream_v2(self.raw, ptr::null_mut()).to_result()?; |
| 140 | Ok(res) |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | /// Sets whether the cuBLAS library is allowed to use atomics for certain routines such as `symv` or `hemv`. |
| 145 | /// |
no test coverage detected