-
Notifications
You must be signed in to change notification settings - Fork 133
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 a new bit mask for copy + Update Python array API spec #136
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, Leo! Needs the data-api commit to be full explanatory for the Python exchange. But that seems fine (it is linked at the top).
So this LGTM, modulo the "must". I would like if we can make it a must flag (also suggested brief mention earlier).
If anyone worries about it, adding the flag could be a minor version bump, but not sure it matters at this point.
My main comment is conceptual: the import numpy as np
import torch
# Here NumPy can know that the array created by `np.ones(3)` isn't used (same trick as for
# temporary elision), so it can simply return that memory rather than copy it first. For a
# library with more context (e.g., in a compute graph) there may be more ways to guarantee
# that the memory isn't used on the producer side.
torch.from_dlpack(np.ones(3), copy=True) This case could be either addressed in the text, or by changing |
Co-authored-by: Sebastian Berg <sebastian@sipsolutions.net>
Right this is about guaranteeing sole ownership (after hand-off nobody else will access the buffer ever again). Leo was menioning "unique" as a name (from unique pointer), not sure what is a better name/text though. EDIT: but I guess it is more than "exclusive" ownership, which might also mean that ownership is handed back after freeing the buffer. Tricky! |
@rgommers when @seberg and I discussed offline, we wanted something that makes the ownership clear by drawing analogy from C++ smart pointers, so
Currently, |
I think I would lean towards just sticking with the copy name. But if we can think of a note that in theory "copy" can also be flagged if unique ownership is passed off (and can never be returned) would seem fine.
I agree it's probably impossible to elide. But, adding a note that "copy" could have a slightly more broad meaning would seem fine (maybe someone can actually invalidate their object instead). Although, I would also be happy to defer that note at this point. |
The unique pointer analogy sounds good to me.
Sticking with the copy name seems fine to me as long as the note for uniqueness is added.
Even if that's true for the example I gave (which I'm not 100% sure about), with more context like when an array is created within a code block that's JIT-compiled ( |
Sounds good.
Will do.
I personally think it's a "foul" that |
Done in commit a1eecba. |
@tqchen this is ready 🙂 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. If anyone cares, we could flag the addition as 1.1 (rather than 1.0), but with __dlpack__
never being bumped to actual versioning, I doubt it matters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My one main comment was addressed, and everything else LGTM. So seems ready to go - thanks a lot!
Close #116. Close #134. Close #132.
This PR is an accompanying PR for data-apis/array-api#602 and data-apis/array-api#741. It does a few things to prepare for the release of Python array API standard v2023:
DLPACK_FLAG_BITMASK_IS_COPIED
bit mask to indicate if a copy has been made by the producer (Add view/copy informational flag #134)max_version
is added to__dlpack__
to support the transition from DLPack 0.x to 1.x (Next steps for the Python API? #116)copy
is added tofrom_dlpack
and__dlpack__
to allow explicit copy requests (Add view/copy informational flag #134)device
(dl_device
) is added tofrom_dlpack
(__dlpack__
) to allow cross-device copies (Question about expectation on cross-hardware #132). However, currently we only mandate the support of device-to-host copies.