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 Cython/Python copy_to_host and to_device #268

Merged
merged 32 commits into from
Feb 3, 2020

Conversation

jakirkham
Copy link
Member

@jakirkham jakirkham commented Jan 30, 2020

Exposes Cython/Python functions for copy_to_host and to_device for copying from device to host taking only a pointer and a bytes-like` buffer. This should help users that have at least a device pointer and the number of bytes of their object to copy it over to host. Hopefully this will allow code constructing temporary device arrays to be removed. As a result this should cutdown on the performance penalty incurred by this construction.

Also adds a copy_to_host method to DeviceBuffer to match what Numba does with DeviceNDArrays. Further renames frombytes to to_device to match Numba. Should make it easier for Python users to leverage this functionality through duck-typing in Python. Thus avoiding handling DeviceBuffer and DeviceNDArray differently.

Due to changes in the Cython-level, the copy_to_host function at the C++ level became redundant and has been dropped.

Pad the size of the memoryview to workaround Cython issue creating size
0 memoryviews. Then trim the added length afterwards. Should allow us to
pass size 0 memoryviews to `copy_to_host`.
This should avoid raising unnecessarily when the host and/or device
pointers are `nullptr`.
Go ahead and pull these into Cython for simplicity. After all we are
basically just calling `cudaMemcpyAsync` at this point.
Creates an analogous method to `copy_to_host` on `DeviceNDArray`s.
python/rmm/_lib/device_buffer.pyx Outdated Show resolved Hide resolved
python/rmm/_lib/device_buffer.pyx Outdated Show resolved Hide resolved
@pentschev
Copy link
Member

Also adds a method of the same name to DeviceBuffer to match what Numba does with DeviceNDArrays.

Is that still not added or did I miss something?

Co-Authored-By: Peter Andreas Entschev <[email protected]>
@jakirkham jakirkham force-pushed the add_cy_copy_to_host branch from 049bba4 to 38c04b1 Compare January 30, 2020 18:35
To better align with how other libraries handle streams, skip the
synchronization step. This should happen anyways for the default stream
(if the user doesn't specify one). Also should give users who want to
manage their concurrency more control.
Add a `to_device` function that the static method uses.
@jakirkham jakirkham changed the title Add Cython/Python copy_to_host function Add Cython/Python copy_to_host and to_device functions Jan 31, 2020
@jakirkham jakirkham changed the title Add Cython/Python copy_to_host and to_device functions Add Cython/Python copy_to_host and to_device Jan 31, 2020
@jakirkham
Copy link
Member Author

Pushed some fixes. Please take a look and let me know your thoughts 🙂

Copy link
Contributor

@kkraus14 kkraus14 left a comment

Choose a reason for hiding this comment

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

One last change and the implementation looks good. Just needs some docstrings and this is ready to go.

@kkraus14 kkraus14 added 2 - In Progress Currently a work in progress Python Related to RMM Python API labels Jan 31, 2020
Also make sure we return the exact same input provided to us (as opposed
to a Cython memoryview).
@jakirkham
Copy link
Member Author

Added docstrings, merged with upstream, and did a little cleanup. Tests passed for me locally. Please let me know if there is anything else needed. Thanks all for the reviews! 😄

@jakirkham
Copy link
Member Author

rerun tests

@kkraus14 kkraus14 added 5 - Ready to Merge Testing and reviews complete, ready to merge and removed 2 - In Progress Currently a work in progress labels Feb 3, 2020
@kkraus14 kkraus14 merged commit 7b4487a into rapidsai:branch-0.13 Feb 3, 2020
@jakirkham jakirkham deleted the add_cy_copy_to_host branch February 3, 2020 23:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5 - Ready to Merge Testing and reviews complete, ready to merge Python Related to RMM Python API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants