Fixing unsafe slow load (memcpy).

- Without the annotation, I think the rust compiler assumes it's all u8.

It did segfault trying to load `Roberta`.
This commit is contained in:
Nicolas Patry
2023-07-06 13:14:33 +02:00
parent c297a50960
commit 054717e236

View File

@ -71,7 +71,7 @@ fn convert_<T: WithDType>(view: st::TensorView<'_>, device: &Device) -> Result<T
let data: &[T] = unsafe { std::slice::from_raw_parts(v.as_ptr() as *const T, elem_count) };
Tensor::from_slice(data, view.shape(), device)
} else {
let mut c = Vec::with_capacity(elem_count);
let mut c: Vec<T> = Vec::with_capacity(elem_count);
// SAFETY: We just created c, so the allocated memory is necessarily
// contiguous and non overlapping with the view's data.
// We're downgrading the `c` pointer from T to u8, which removes alignment