pub struct Future<'closure, T> { /* private fields */ }
Expand description
Future for CUDA operations.
Note that this future abstracts over two different asynchronousprimitives: dedicated-thread semantics, and stream asynchrony.
§Dedicated-thread semantics
In this crate, all operations that use CUDA internally are off-loaded to a dedicated thread (the runtime). This improves CUDA’s ability to parallelize without being interrupted by the OS scheduler or being affected by starvation when under load.
§Stream asynchrony
CUDA has internal asynchrony as well. Lots of CUDA operations are asynchronous with respect to the host with regards to the stream they are bound to.
It is important to understand that most of the operations in this crate do NOT actually wait for the CUDA asynchronous operation to complete. Instead, the operation is started and then the future becomes ready. This means that if the caller must still synchronize the underlying CUDA stream.
§Usage
To create a Future
, move the closure into with Future::new
:
let future = Future::new(move || {
()
});
let return_value = future.await;
assert_eq!(return_value, ());
Implementations§
Source§impl<'closure, T> Future<'closure, T>
impl<'closure, T> Future<'closure, T>
Sourcepub fn new<F>(call: F) -> Self
pub fn new<F>(call: F) -> Self
Wrap the provided function in this future. It will be sent to the runtime thread and executed there. The future resolves once the call on the runtime completes.
§Arguments
call
- Closure that contains relevant function call.
§Example
let return_value = Future::new(|| ()).await;
assert_eq!(return_value, ());
})