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 from_raw_parts #198

Closed
wants to merge 6 commits into from
Closed

Implement Tensor from_raw_parts #198

wants to merge 6 commits into from

Conversation

edgarriba
Copy link
Member

No description provided.

// Safety:
// TensorStorage is thread safe if the allocator is thread safe.
unsafe impl<T, A: TensorAllocator> Send for TensorStorage<T, A> {}
unsafe impl<T, A: TensorAllocator> Sync for TensorStorage<T, A> {}

impl<T, A: TensorAllocator> Drop for TensorStorage<T, A> {
fn drop(&mut self) {
self.alloc
.dealloc(self.ptr.as_ptr() as *mut u8, self.layout);
if !self.managed_by_external {
Copy link
Member Author

@edgarriba edgarriba Dec 28, 2024

Choose a reason for hiding this comment

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

@gbin had to add this flag here to prevent double deallocation as I couldn't find a way to prevent gstreamer deallocating the memory

return Ok(None);
};

let frame_buffer = std::mem::ManuallyDrop::new(frame_buffer);
Copy link
Member Author

Choose a reason for hiding this comment

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

@gbin having a bit of trouble by trying to prevent gstreamer to deallocate the buffer. Do you have any insights here ?


// Check for null pointer
if !ptr.is_null() {
//unsafe { alloc::dealloc(ptr, layout) }
Copy link
Member Author

Choose a reason for hiding this comment

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

@gbin by commenting this line seems to do the job but i don't think it's correct. The behavior I'm seeing is that I never enter in this branch statement but gstreamer tries to allocate an invalid pointer. A bit weird -- might be missing something fundamental ?

@edgarriba edgarriba closed this Jan 9, 2025
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