Skip to content

Commit 3880313

Browse files
authored
Remove unnecessary Default constraint on DeviceBox::as_host_value. (#67)
1 parent e8ddcf5 commit 3880313

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

crates/cust/src/memory/device/device_box.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::memory::{cuda_free_async, cuda_malloc_async, DeviceCopy};
77
use crate::stream::Stream;
88
use crate::sys as cuda;
99
use std::fmt::{self, Pointer};
10-
use std::mem::{self, ManuallyDrop};
10+
use std::mem::{self, ManuallyDrop, MaybeUninit};
1111

1212
use std::os::raw::c_void;
1313

@@ -130,14 +130,15 @@ impl<T: DeviceCopy> DeviceBox<T> {
130130
// you keep around a pointer, but in that case, we cannot guarantee safety.
131131
unsafe { cuda_free_async(stream, me.ptr) }
132132
}
133-
}
134133

135-
impl<T: DeviceCopy + Default> DeviceBox<T> {
136134
/// Read the data back from the GPU into host memory.
137135
pub fn as_host_value(&self) -> CudaResult<T> {
138-
let mut val = T::default();
139-
self.copy_to(&mut val)?;
140-
Ok(val)
136+
let mut val = MaybeUninit::uninit();
137+
// SAFETY: We do not read from the uninitialized reference.
138+
unsafe {
139+
self.copy_to(val.assume_init_mut())?;
140+
Ok(val.assume_init())
141+
}
141142
}
142143
}
143144

0 commit comments

Comments
 (0)