-
Notifications
You must be signed in to change notification settings - Fork 789
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How does Buffer::from_custom_allocation
work ?
#6362
Comments
At a glance, this looks correct. I use it like the following, where let len = v.len() * std::mem::size_of::<T>();
let buffer = unsafe {
let ptr = NonNull::new_unchecked(v.as_ptr() as *mut u8);
Buffer::from_custom_allocation(ptr, len, v)
}; I'm being careful here to not use any references to the vector while a mutable pointer exists, as that could lead to undefined behavior. But that does not seem to be the problem here. Maybe the issue is with the |
this is the implementation of pub fn into_vec(self) -> Vec<T> {
match self.data.into_inner().into_vec() {
Ok(vec) => vec,
Err(buf) => unsafe {
std::slice::from_raw_parts(
buf.as_ptr() as *const T,
buf.len() / std::mem::size_of::<T>(),
)
.to_vec()
},
}
} |
arrow-rs/arrow-buffer/src/buffer/immutable.rs Line 318 in 704f90b
This usecase might get supported by #6336 or a followup of that. |
hi, I have the kornia-rs crate where I implemented a custom
TensorStorage
struct out ofScalarBuffer
and I have some issues while extending a methodTensorStorage::from_vec
. This struct has the particularity that holds an Allocator which the intention is that the user can specify, e.g for CpuTensor or CudaTensor (or more advanced devices/backends).Initally, I had implemented this using the
Buffer::from_custom_allocation
method aiming to create the storage with a zero-copy cost. However, I recently discovered after adding some tests that something fishy is going on with the memory pointers of the vector.I can quickly illustrate what I have and what I'm trying to figure out. From kornia/kornia-rs#125
Then the crashing test
Thanks in advance!
The text was updated successfully, but these errors were encountered: