Skip to content
This repository was archived by the owner on Sep 18, 2025. It is now read-only.

Use full shape in buffer protocol#120

Merged
quasiben merged 1 commit intorapidsai:develfrom
mrocklin:buffer-shape
Aug 13, 2019
Merged

Use full shape in buffer protocol#120
quasiben merged 1 commit intorapidsai:develfrom
mrocklin:buffer-shape

Conversation

@mrocklin
Copy link
Copy Markdown
Collaborator

@mrocklin mrocklin commented Jun 7, 2019

Previously we would only use the first dimension in a Message shape
in the getbuffer method. This would result in poorly formed memoryview
objects.

Fixes #119

Previously we would only use the first dimension in a Message shape
in the __getbuffer__ method.  This would result in poorly formed memoryview
objects.

Fixes rapidsai#119
mrocklin added a commit to mrocklin/distributed that referenced this pull request Jun 7, 2019
@mrocklin
Copy link
Copy Markdown
Collaborator Author

mrocklin commented Jun 7, 2019

FYI @Akshay-Venkatesh this was the cause of the zero-byte messages that I was seeing.

mrocklin added a commit to dask/distributed that referenced this pull request Jun 7, 2019
buffer.ndim = len(self.shape)
buffer.obj = self
buffer.readonly = 0 # TODO
buffer.shape = shape2
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not part of the change here, but this line is a little concerning to me. It seems to be taking a pointer to memory allocated on the stack. Meaning this pointer won't be valid when we leave this function. I wouldn't be surprised if this causes segfaults somewhere else.

One alternative would be to dynamically allocate memory for buffer.shape to point to and fill in the content from shape2 and then clean up this memory in __releasebuffer__. Another alternative would be to make shape2 part of self.

Thoughts?

@Akshay-Venkatesh
Copy link
Copy Markdown
Contributor

Akshay-Venkatesh commented Jun 7, 2019

@mrocklin Your changes seem to be flattening the shape. Doesn't that result in shape knowledge being lost?

buffer.shape = shape2

I'm likely missing the full picture here. @TomAugspurger

@TomAugspurger
Copy link
Copy Markdown
Contributor

TomAugspurger commented Jun 7, 2019 via email

@jakirkham
Copy link
Copy Markdown
Member

@Akshay-Venkatesh, is the self.shape variable used elsewhere? I wonder if it couldn't be turned into the desired pointer (instead of an object as it is now) and used with the buffer protocol here. Maybe that even simplifies things a bit. 🙂

@jakirkham
Copy link
Copy Markdown
Member

If self.shape is useful (like for Python users to see), maybe we can use self._shape instead for the same purpose.

@mrocklin
Copy link
Copy Markdown
Collaborator Author

mrocklin commented Jun 7, 2019

No thoughts from me. I honestly don't know Cython that well and don't have a sense for what is handled automatically or not. @jakirkham if you see a good obvious solution here would you be interested in making a quick PR?

Doesn't that result in shape knowledge being lost?

Yes. This is less than ideal, but not terrible. We only really care about this thing as a byte buffer, not as a full array. We send shape and dtype information as part of a separate header.

@jakirkham
Copy link
Copy Markdown
Member

Yes, happily. One sec...

@jakirkham
Copy link
Copy Markdown
Member

Have started this with PR ( #121 ). There is a bunch of code that is assigning to .shape, which would need to change as a consequence. Though need input from others to understand how that should change.

@mrocklin
Copy link
Copy Markdown
Collaborator Author

If no one objects I'm going to merge this in for now. I think that this is a strict improvement. We can still continue with #121 afterwards. OK with you @jakirkham ?

@quasiben
Copy link
Copy Markdown
Member

I am +1 for merging

@quasiben
Copy link
Copy Markdown
Member

Wait, running tests with this PR and things are failing

@quasiben
Copy link
Copy Markdown
Member

Nevermind -- tests are passing merging

@quasiben quasiben merged commit c58b2ac into rapidsai:devel Aug 13, 2019
@jakirkham
Copy link
Copy Markdown
Member

Sorry I let this one slip off my radar. In general anything that gets us closer to complying with the buffer protocol is a good thing. This is certainly a step in that direction.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

We create poorly formed memoryview objects

5 participants