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

Handle byte order markers at the beginning of format strings #179

Merged
merged 1 commit into from
Mar 1, 2022

Conversation

dalcinl
Copy link
Member

@dalcinl dalcinl commented Feb 27, 2022

Fixes #177.

@dalcinl dalcinl self-assigned this Feb 27, 2022
@dalcinl
Copy link
Member Author

dalcinl commented Feb 27, 2022

@anjakefala Please take a look.

Copy link
Member

@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 except two nitpicks

src/mpi4py/MPI/msgbuffer.pxi Show resolved Hide resolved
src/mpi4py/MPI/msgbuffer.pxi Show resolved Hide resolved
@leofang
Copy link
Member

leofang commented Feb 28, 2022

Note: I think this patch fixes the buffer protocol and the CAI protocol, but not the DLPack protocol because apparently DLPack forgot about endianness. Raised an issue to track it (dmlc/dlpack#97).

@leofang
Copy link
Member

leofang commented Feb 28, 2022

I think this patch fixes the buffer protocol and the CAI protocol

Sorry, I was wrong. It seems strictly speaking CAI could also have an issue, since we currently ignore the endianness there (typestr[0]):

typekind = <char>ord(typestr[1:2])
itemsize = <Py_ssize_t>int(typestr[2:])

Frankly this is an oversight not just on us but also on those who contributed to CAI (well, me included...) -- CUDA is little endian so it does not make sense to accept/exchange big endianness. What should we do here? No one complained yet so just ignore it (since in practice it doesn't matter)?

@dalcinl
Copy link
Member Author

dalcinl commented Feb 28, 2022

@leofang It would be rather trivial to add a check for native byte order to CAI, although I'm not sure whether it is worth it, DLPack takes precedence over CAI. So far I has been considering CAI as deprecated/legacy stuff. However, errors should never pass silently.

@dalcinl
Copy link
Member Author

dalcinl commented Feb 28, 2022

@leofang I implemented a few minor refactors. Afterwards, I added proper checks in CAI. Please take a new look.

@dalcinl dalcinl changed the title Support for byte order markers at the beginning of format strings Handle byte order markers at the beginning of format strings Feb 28, 2022
@anjakefala
Copy link

anjakefala commented Feb 28, 2022

@dalcinl This is great! Thank you so much! Once there is a tar, I happily offer to test it with my data.

f"__cuda_array_interface__: "
f"typestr {typestr!r} "
f"with non-native byte order")
elif byteorder == c'>': # little-endian
Copy link
Member

Choose a reason for hiding this comment

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

Big endian?

@leofang
Copy link
Member

leofang commented Mar 1, 2022

So far I has been considering CAI as deprecated/legacy stuff.

That's what I thought too, until after seeing some Python only libraries that can't use dlpack. Numba is one representative example 😄

@dalcinl
Copy link
Member Author

dalcinl commented Mar 1, 2022

until after seeing some Python only libraries that can't use dlpack

So DLPack cannot deal with complex quadruple precision numbers, no support for readonly, and no support for endianness. On top of that the standardized Python protocol cannot be implemented with Python-only code. Looks like issues are piling up...

@dalcinl
Copy link
Member Author

dalcinl commented Mar 1, 2022

This is great! Thank you so much! Once there is a tar, I happily offer to test it with my data.

I do not have an ETA for a new release tarball. However, installing mpi4py from git is trivial, just do:

python -m pip install https://github.com/mpi4py/mpi4py/tarball/master

I'm going to merge this PR right now. The tests I've added are all passing in our CI. I have not tested on an actual big endian machine yet, but if we ever do, the added tests will catch any issues.

@dalcinl dalcinl merged commit d4ae0e7 into master Mar 1, 2022
@dalcinl dalcinl deleted the feature/byteorder branch March 1, 2022 09:11
@leofang
Copy link
Member

leofang commented Mar 7, 2022

So DLPack cannot deal with complex double precision numbers, no support for readonly, and no support for endianness. On top of that the standardized Python protocol cannot be implemented with Python-only code. Looks like issues are piling up...

Complex numbers can be handled, but yeah the rest is being discussed.

@dalcinl
Copy link
Member Author

dalcinl commented Mar 8, 2022

Complex numbers can be handled

Sorry, I made I mistake in my comment, I edited it.

DLPack cannot handle quadruple precision complex numbers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

KeyError with mpi4py.MPI.message_basic with explicit little endianness set
3 participants