bheisler / RustaCUDA

Rusty wrapper for the CUDA Driver API
Apache License 2.0
765 stars 58 forks source link

DeviceBox for Vectors of data #42

Closed ChipsSpectre closed 4 years ago

ChipsSpectre commented 4 years ago

Hey,

I just discovered this project and it looks really interesting!

The way how data is allocated on the GPU device looks like this for a scalar value.

let mut factor1 = DeviceBox::new(&6.0f32)?;

How can we allocate a vector of values on the device? For example: If we want to increment all values in a vector [1,2,3], how can this vector be transferred to the device?

It would be great for me to to add this information to the API documentation in order to help future users.

Best regards Chips

LutzCle commented 4 years ago

Hi,

What you're looking for is DeviceBuffer. The examples in the documentation show how you can transfer data to and from the device with copy_to and copy_from. You can also perform the copies asynchronously with async_copy_to and async_copy_from, see the documentation for AsyncCopyDestination.

Hope that helps!

ChipsSpectre commented 4 years ago

Thank you really much, this helped a lot! grafik The device buffer is now used in a minimal version. Is it possible to add it to the examples section?

LutzCle commented 4 years ago

Looks almost exactly like the existing launch example to me.

ChipsSpectre commented 4 years ago

I am sorry, I did not look into the examples folder. Sometimes the solution is closer than one might think...

But nonetheless, thank you really much for mentioning the DeviceBuffer, I started to implement some kernels and RustaCUDA works great. :+1:

LutzCle commented 4 years ago

Great that it's working for you now! I guess the README could link to the examples folder to make the examples easier to find. Perhaps @bheisler would accept a pull request from you?

ChipsSpectre commented 4 years ago

:+1: Pull request created.

bheisler commented 4 years ago

Pull request has been merged.