Skip to content
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

implement Tensor into_vec #125

Merged
merged 3 commits into from
Sep 5, 2024
Merged

implement Tensor into_vec #125

merged 3 commits into from
Sep 5, 2024

Conversation

edgarriba
Copy link
Member

@edgarriba edgarriba commented Sep 5, 2024

  • implement Tensor / TensorStorage -- into_vec() to accomplish zero-copies between other libraries e.g ort @decahedron1


// check NO copy
assert_eq!(result_vec.capacity(), original_vec_capacity);
assert!(std::ptr::eq(result_vec.as_ptr(), original_vec_ptr));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@decahedron1 this test seems to fail, which means that we enter in the Err(buf) case

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe there's something wrong with the TensorStorage::from_vec which underneath uses Buffer::from_custom_allocation

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UPDATE: i think i fixed ... but I'm missing something around how to tie with the provided allocator. My idea here was that the user can provider custom allocators. eg. CudaAllocator to hold CudaImages to interop easily with other frameworks like ort, vpi, etc to not move memory forth and back

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, what was causing the test failure? The fix in 1642803 doesn't seem obvious to me, but again, I know nothing about arrow_buffer 🤔

Integration with CUDA buffers would have to go through a different API, TensorRefMut::from_raw. It just needs a pointer and shape, so Kornia's existing APIs suffice. TensorRefMuts can be used zero-copy in session inputs just like a Value, but since the memory is user-managed, it does have a lifetime bound. See ort's cudarc example: https://github.com/pykeio/ort/blob/60f6ecae9064a75a474678998af42ea87067b1b1/examples/cudarc/src/main.rs#L35-L43

Copy link
Member Author

@edgarriba edgarriba Sep 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, what was causing the test failure?

I might need to investigate a bit more the Buffer::from_custom_allocation, maybe is doing copy because later the test checking ptrs is failing.

Integration with CUDA buffers would have to go through a different API,

I'll play with it , thanks for the pointers.

@edgarriba edgarriba merged commit dd35ed0 into main Sep 5, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants