atomr_accel_cuda/completion/
sync.rs1use std::sync::Arc;
6
7use futures_util::future::BoxFuture;
8use futures_util::FutureExt;
9
10use crate::error::GpuError;
11
12use super::CompletionStrategy;
13
14#[derive(Clone, Default)]
15pub struct SyncCompletion;
16
17impl SyncCompletion {
18 pub fn new() -> Self {
19 Self
20 }
21}
22
23impl CompletionStrategy for SyncCompletion {
24 fn await_completion(
25 &self,
26 stream: &Arc<cudarc::driver::CudaStream>,
27 ) -> BoxFuture<'static, Result<(), GpuError>> {
28 let stream = stream.clone();
29 async move {
30 tokio::task::spawn_blocking(move || stream.synchronize())
34 .await
35 .map_err(|e| GpuError::Driver(format!("sync-completion task: {e}")))?
36 .map_err(|e| GpuError::Driver(format!("cudaStreamSynchronize: {e}")))
37 }
38 .boxed()
39 }
40}