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 to_dlpack/from_dlpack APIs to pylibcudf #17055

Open
wants to merge 6 commits into
base: branch-24.12
Choose a base branch
from

Conversation

mroeschke
Copy link
Contributor

@mroeschke mroeschke commented Oct 10, 2024

Description

Contributes to #15162

Could use some advice how to type the input of from_dlpack and outut of to_dlpack which are PyCapsule objects.
EDIT: I notice Cython just types them as object https://github.com/cython/cython/blob/master/Cython/Includes/cpython/pycapsule.pxd. Stylistically do we want add object var_name or just leave untyped?

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@mroeschke mroeschke added improvement Improvement / enhancement to an existing function non-breaking Non-breaking change pylibcudf Issues specific to the pylibcudf package labels Oct 10, 2024
@mroeschke mroeschke requested a review from a team as a code owner October 10, 2024 22:28
@github-actions github-actions bot added the Python Affects Python cuDF API. label Oct 10, 2024
Copy link
Contributor

@Matt711 Matt711 left a comment

Choose a reason for hiding this comment

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

It looks like PyCapsules are used to handle raw C pointers in Python? So it makes sense to me to type from_dlpack and to_dlpack withobject. I'd like to see what @vyasr thinks because I'm not sure.

python/pylibcudf/pylibcudf/interop.pyx Outdated Show resolved Hide resolved
python/pylibcudf/pylibcudf/interop.pyx Outdated Show resolved Hide resolved
python/pylibcudf/pylibcudf/tests/test_interop.py Outdated Show resolved Hide resolved
python/pylibcudf/pylibcudf/interop.pyx Outdated Show resolved Hide resolved
Table with a copy of the tensor data.
"""
cdef unique_ptr[table] c_result
cdef DLManagedTensor* dlpack_tensor = <DLManagedTensor*>PyCapsule_GetPointer(
Copy link
Contributor

Choose a reason for hiding this comment

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

We should add some of the safety checks from https://dmlc.github.io/dlpack/latest/python_spec.html#implementation to ensure that we don't try to consume an already deleted capsule or anything like that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Added one check, lmk if you were thinking of any others

python/pylibcudf/pylibcudf/interop.pyx Show resolved Hide resolved
python/pylibcudf/pylibcudf/interop.pyx Outdated Show resolved Hide resolved
python/pylibcudf/pylibcudf/interop.pyx Outdated Show resolved Hide resolved
python/pylibcudf/pylibcudf/interop.pxd Outdated Show resolved Hide resolved
python/pylibcudf/pylibcudf/interop.pxd Outdated Show resolved Hide resolved
python/cudf/cudf/_lib/interop.pyx Outdated Show resolved Hide resolved
@Matt711 Matt711 requested a review from a team as a code owner October 22, 2024 21:36
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 pylibcudf Issues specific to the pylibcudf package Python Affects Python cuDF API.
Projects
Status: In Progress
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants