Skip to content

Changes Implementation section of data-interchange to close #337 #338

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

Merged
merged 2 commits into from
Nov 22, 2021

Conversation

oleksandr-pavlyk
Copy link
Contributor

Changes to the implementation section of data_interchange.md per #337.

@fschlimb

…nagement of DLManagedTensor passed via Python capsule
@kgryte kgryte added the topic: DLPack DLPack. label Nov 16, 2021
@kgryte kgryte added this to the v2021 milestone Nov 16, 2021
Comment on lines +150 to +157
The consumer must transer ownership of the `DLManangedTensor` from the
capsule to its own object. It does so by renaming the capsule to
`"used_dltensor"` to ensure that `PyCapsule_Destructor` will not get
called (ensured if `PyCapsule_Destructor` calls `deleter` only for
capsules whose name is `"dltensor"`), but the `deleter` of the
`DLManagedTensor` will be called by the destructor of the consumer
library object created to own the `DLManagerTensor` obtained from the
capsule.

Choose a reason for hiding this comment

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

Why is the ref-count of the capsule not enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My understanding is because it is an interlibrary data exchange protocol, and if some libraries transfer ownership to their internal objects in their existing implementations, discrepancy in lifetime management approaches may result in double free.

Copy link
Contributor

@leofang leofang left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @oleksandr-pavlyk!

@kgryte
Copy link
Contributor

kgryte commented Nov 22, 2021

Thanks for reviewing @leofang!

Will merge. If anything further needs updating, we can address in a follow-up PR. Thanks, @oleksandr-pavlyk!

@kgryte kgryte merged commit e181da8 into data-apis:main Nov 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants