Rust-GPU / Rust-CUDA

Ecosystem of libraries and tools for writing and executing fast GPU code fully in Rust.
Apache License 2.0
3.02k stars 115 forks source link

Derive DeviceCopy invariants? #46

Closed thedodd closed 2 years ago

thedodd commented 2 years ago

I see that there is no impl DeviceCopy for core/alloc Vec, but I do see the impls for the vek::* types. Is there any particular concern with slapping on an unsafe impl DeviceCopy for the core/alloc Vec type?

I have some data structures which are pure data, no references, nothing like that, but there are vector fields. Would it be sounds to impl DeviceCopy for such a type? I’m wondering what the actual requirements are. Just no references and no_std?

RDambrosio016 commented 2 years ago

vek types are linear algebra types, they are stored on the stack so can be passed by value just fine and they hold no references to cpu data. Vec on the other hand stores its data on the heap, and that data is not readable by the GPU, you need to alloc a separate unified/device buffer and copy the data over. It would not be sound to pass a Vec to the gpu, you would get a segfault

thedodd commented 2 years ago

Thank you for the quick response and great explanation.