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

Add CudaSlice::split_at_mut and CudaViewMut::split_at_mut #235

Merged
merged 8 commits into from
Jun 5, 2024

Conversation

dkales
Copy link
Contributor

@dkales dkales commented May 21, 2024

This is an attempt to address #233.

Since this is code that touches some aspects of the lifetimes of CudaView and CudaViewMut, this could use some extra scrutiny to check if the safety invariants of the involved types are still ok.

I removed the root field of both CudaView and CudaViewMut, since it's only purpose was AFAIK, to keep track of the lifetimes of the respective structs. I have moved this into a PhantomData which should serve the same purpose.

Furthermore, I have now added the split_at_mut methods to CudaSlice and CudaViewMut, which mimic the behavior of split_at_mut of the standard library.

The old method of storing a &mut to the cuda device pointer does not work for splitting, since it would mean that there exist two mutable references to the same value (the u64 device ptr value) at the same time, which AFAIK is always unsound. Therefore the removal and moving the lifetimes into PhantomData as discussed above.

@coreylowman
Copy link
Owner

Since this is code that touches some aspects of the lifetimes of CudaView and CudaViewMut, this could use some extra scrutiny to check if the safety invariants of the involved types are still ok.

Yeah we could probably add some doctests that should fail to each of these methods. The main thing we have to make sure still works properly is the ownership/borrow semantics. We need to check if moving the references from the root variable to PhantomData changes these. Ideally would want CudaSlice/CudaViewMut to have the same behavior as a Vec<T>/&mut [T].

@dkales dkales changed the title Redesing CudaView and CudaViewMut to allow for splitting of mutable views. Redesign CudaView and CudaViewMut to allow for splitting of mutable views. May 29, 2024
@dkales dkales force-pushed the main branch 2 times, most recently from 07e50ac to 4a96aac Compare June 3, 2024 08:55
@dkales
Copy link
Contributor Author

dkales commented Jun 3, 2024

I have added some doc-tests to show the borrowing behavior of CudaView and CudaViewMut, and also rebased on main

src/driver/safe/core.rs Outdated Show resolved Hide resolved
@dkales
Copy link
Contributor Author

dkales commented Jun 5, 2024

As a sidenote the no-std feature is incompatible with the tests, since they use Vec.
I have added 3 more commits addressing this using the no-std-compat dependency already used.
Let me know if you want these or if they should be split into a separate PR.

@coreylowman
Copy link
Owner

It's fine to include here, will merge after piplines pass. Thanks for adding this feature!

@coreylowman coreylowman linked an issue Jun 5, 2024 that may be closed by this pull request
@coreylowman coreylowman changed the title Redesign CudaView and CudaViewMut to allow for splitting of mutable views. Add CudaSlice::split_at_mut and CudaViewMut::split_at_mut Jun 5, 2024
@coreylowman coreylowman merged commit 6fa8132 into coreylowman:main Jun 5, 2024
3 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.

CudaSlice equivalent of Slice::split_at_mut
2 participants