bheisler / RustaCUDA

Rusty wrapper for the CUDA Driver API
Apache License 2.0
758 stars 60 forks source link

How to do device-to-device memory allocations? #36

Closed saona-raimundo closed 5 years ago

saona-raimundo commented 5 years ago

I am sorry if it is in the documentation, I can't find it in the DeviceBuffer section.

I would like to do something similar to the following instruction in CUDA:

cudaMemcpy(d_vec2, d_vec1, sizeof(d_vec1), cudaMemcpyDeviceToDevice);

which copies d_vec1 (on device) to d_vec2 (on device too).

rusch95 commented 5 years ago

I think there should be some DeviceBuffer unit tests that do the thing you're looking for.

On Sat, May 4, 2019, 18:29 rasa200 notifications@github.com wrote:

I am sorry if it is in the documentation, I can't find it in the DeviceBuffer section.

I would like to do something similar to the following instruction in CUDA:

cudaMemcpy(d_vec2, d_vec1, sizeof(d_vec1), cudaMemcpyDeviceToDevice);

which copies d_vec1 (on device) to d_vec2 (on device too).

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/bheisler/RustaCUDA/issues/36, or mute the thread https://github.com/notifications/unsubscribe-auth/ACSQ2KA752SQKDYVI5Z5UZTPTYE2DANCNFSM4HKZ4KIQ .

rusch95 commented 5 years ago

I can give you a specific code snippet later today.

On Sat, May 4, 2019, 20:38 Robert Rusch rusch95@gmail.com wrote:

I think there should be some DeviceBuffer unit tests that do the thing you're looking for.

On Sat, May 4, 2019, 18:29 rasa200 notifications@github.com wrote:

I am sorry if it is in the documentation, I can't find it in the DeviceBuffer section.

I would like to do something similar to the following instruction in CUDA:

cudaMemcpy(d_vec2, d_vec1, sizeof(d_vec1), cudaMemcpyDeviceToDevice);

which copies d_vec1 (on device) to d_vec2 (on device too).

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/bheisler/RustaCUDA/issues/36, or mute the thread https://github.com/notifications/unsubscribe-auth/ACSQ2KA752SQKDYVI5Z5UZTPTYE2DANCNFSM4HKZ4KIQ .

saona-raimundo commented 5 years ago

Hey!! The answer is pretty straight forward: just use copy_to(), so

cudaMemcpy(d_vec2, d_vec1, sizeof(d_vec1), cudaMemcpyDeviceToDevice);

... is "equivalent" to ...

d_vec1.copy_to(&mut d_vec2); or d_vec2.copy_from(&mut d_vec1);

when d_vec1 and d_vec2 are DeviceBuffers of the same size