MCPcopy Create free account
hub / github.com/Rust-GPU/rust-cuda / with_stream

Method with_stream

crates/blastoff/src/context.rs:128–142  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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

Callers 9

amin_stridedMethod · 0.80
amax_stridedMethod · 0.80
axpy_stridedMethod · 0.80
copy_stridedMethod · 0.80
dot_stridedMethod · 0.80
dotu_stridedMethod · 0.80
dotc_stridedMethod · 0.80
nrm2_stridedMethod · 0.80
rot_stridedMethod · 0.80

Calls 2

to_resultMethod · 0.45
as_innerMethod · 0.45

Tested by

no test coverage detected