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

Moving TestDeviceBuffer to pylibraft.common.device_ndarray #1008

Merged
merged 14 commits into from
Nov 14, 2022

Conversation

cjnolet
Copy link
Member

@cjnolet cjnolet commented Nov 10, 2022

This allows the pylibraft APIs to process outputs in place or allocate and return new device memory for outputs in a way which benefits from __cuda_array_interface__ compliance. Ultimatley, it allows us to stay decoupled from libraries like cupy while still affording the user the benefits of not having to explicitly allocate outputs up front.

Closes #1002

@cjnolet cjnolet added improvement Improvement / enhancement to an existing function non-breaking Non-breaking change labels Nov 10, 2022
@cjnolet cjnolet requested review from a team as code owners November 10, 2022 22:13
Copy link
Member

@benfred benfred left a comment

Choose a reason for hiding this comment

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

I really like this change - I think its a solid improvement to the usability of the python bindings, while still not requiring cupy

@cjnolet
Copy link
Member Author

cjnolet commented Nov 12, 2022

Thanks @benfred!

I'm thinking we should also provide a factory function that accepts the shape, order, and dtype and creates an empty numpy array (internally) to construct the device_ndarray(). Maybe something the caller can invoke like this:

dev_ndarr = device_ndarray.empty((50, 10), dtype=np.float32, order="C")

Obviously, there's a drawback to using the device_ndarray since it requires a host/device copy. However, I think that's okay because we are giving the option of ease of use (eg have the function automatically return results) and speed (eg users can still explicitly pass in the outputs to keep everything on device and avoid using the device_ndarray)

@cjnolet cjnolet mentioned this pull request Nov 12, 2022
@cjnolet
Copy link
Member Author

cjnolet commented Nov 14, 2022

JFYI, I added the pylibraft.device_ndarray.empty() staticmethod and updated its use in pairwise_distance.

@github-actions github-actions bot removed the CMake label Nov 14, 2022
Copy link
Member

@benfred benfred left a comment

Choose a reason for hiding this comment

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

this looks good! I see your point about the extra h2d memory copy w/ device_ndarray.empty - but I agree that users can always provide pre-allocated arrays to get around this

python/pylibraft/pylibraft/common/device_ndarray.py Outdated Show resolved Hide resolved
@cjnolet
Copy link
Member Author

cjnolet commented Nov 14, 2022

@gpucibot merge

@rapids-bot rapids-bot bot merged commit a5cce11 into rapidsai:branch-22.12 Nov 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Improvement / enhancement to an existing function non-breaking Non-breaking change python
Projects
Development

Successfully merging this pull request may close these issues.

[FEA] Promote TestDeviceBuffer to user-facing APIs
3 participants