Skip to main content

with_cuda_exec_session

Function with_cuda_exec_session 

Source
pub fn with_cuda_exec_session<B, R>(
    session: &mut B,
    f: impl for<'a> FnOnce(&'a mut CudaExecSession<'a>) -> R,
) -> Option<R>
where B: BackendSession + ?Sized,
Expand description

Visit a CUDA execution session through the erased backend-session surface.

This is the public entry point that borrows CUDA execution authority for the duration of the callback (issue #1597). The callback cannot return a borrow of the reconstructed session, so the authority cannot escape the scope.

Returns None when session is not a CUDA execution session.

ยงExamples

use tenferro_gpu::cuda::{with_cuda_exec_session, CudaExecSession};

// Call-check only: the visitor borrows CUDA execution authority for the
// duration of the callback.
fn check(session: &mut dyn tenferro_tensor::backend::BackendSession) {
    let _ = with_cuda_exec_session(session, |_session| 0usize);
}
let _ = check;