-
Notifications
You must be signed in to change notification settings - Fork 45
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
Precedence of selecting from multiple exchange protocols? #142
Comments
I think it's up to the library implementors, however there are a lot of subtleties so it may be useful to give some pointers. Ideally people would use In For libraries that support multiple devices, implementing all these protocols is a little tricky. For example, you then have to implement |
Right, but AFAIK we allow
This is part of the reason I am asking about this. For both NumPy and mpi4py, the buffer protocol is already supported and DLPack will be too, and for mpi4py I am considering to check the protocols in the following order: if (buffer protocol is supported):
use buffer protocol
elif (__cuda_array_interface__ exists):
use __cuda_array_interface__
elif (__dlpack__ exists): # new
use __dlpack__ # new
else:
raise The pro on this order is that by the time |
Just a nit:
Python arbitrary precision integer comes to mind, but I do not think it affects your issue. |
That sounds reasonable. Although you may consider checking for
Not quite. Take a PyTorch tensor on CPU for example - it does not support the buffer protocol.
I agree, it will still be fine. |
@rgommers Do you know off top of your head which is tried first in NumPy, buffer protocol or |
The order is:
|
Thanks, Ralf! Note to self: it's done here https://github.com/numpy/numpy/blob/bb7a31a6a852ecc64d3f7cffb70121fc8bef20eb/numpy/core/src/multiarray/ctors.c#L1275 |
Given this doesn't seem to be an issue anymore, I'm closing it. Just FYI: In mpi4py we try in this order: buffer protocol -> DLPack -> CAI. |
I conceive that a few libraries may end up in a situation where more than one protocols are supported, for example,
__array_interface__
__cuda_array_interface__
Does it matter which protocol an array implementation should try first? Is it up to the library implementors?
The text was updated successfully, but these errors were encountered: