-
Notifications
You must be signed in to change notification settings - Fork 200
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 frombytes
to convert bytes
-like to DeviceBuffer
#253
Merged
kkraus14
merged 14 commits into
rapidsai:branch-0.13
from
jakirkham:add_devbuf_frombytes
Jan 27, 2020
Merged
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f547a81
Move `c_stream` after `bytes` definitions
jakirkham 5038dde
Assign `c_stream` in `nogil` section
jakirkham 1c3de40
Add static method `frombytes` to `DeviceBuffer`
jakirkham a56c4a2
Add C and Python APIs to convert bytes
jakirkham e51c8d6
Test converting `bytes` to a `DeviceBuffer`
jakirkham bf1e662
Test `frombytes`/`tobytes` round trip
jakirkham 78e0f21
Make `black` happy
jakirkham 1d7a04a
Support `bytes`-like data in `frombytes`
jakirkham dea47a7
Make `flake8-cython` happy
jakirkham 4d54bba
Test `frombytes` with other `bytes`-like data
jakirkham fa38277
Make `black` happy
jakirkham 6eeaad8
Note converting `bytes` to `DeviceBuffer`
jakirkham eef69f8
Merge branch 'branch-0.13' into add_devbuf_frombytes
2234e5a
Add read-only `uint8` NumPy array test
jakirkham File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Does this handle
memoryview
objects in general? If so it would be nice if we could have an overloaded non-const version to handle things likebytearray
or other non-readonly objects.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.
It handles
memoryview
objects as long as they are 1-D, contiguous, and of typeunsigned char
.The
const
just means that we won't modify the underlying buffer (much like if we tookconst char*
and were givenchar*
). So any mutable object meeting the constraints above could be passed in as well. This just promises we won't modify the underlying data. IOWbytearray
is permissible and we test for this below.As to other memory types and layouts that don't meet these requirements, users could coerce them into something that meets these requirements (with a minimal amount of copying to ensure contiguous data). Decided not to do that for the user as I wanted them to know we are not preserving the type or layout of their data. Though they could take the resulting
DeviceBuffer
and layer this information back on top by constructing some other array (like CuPy or Numba) and adding this info to that object.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.
Agreed with not implicitly making things contiguous at this level. I'm surprised that a bytearray is allowed for a
const unsigned char[::1]
. We previously ran into issues with using const vs non-const in handling numpy arrays that were marked read-only which is what prompted me to questioning an overload.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.
Ok cool.
Yeah I recall some cases where Cython didn't work as well with
const
memoryviews. Issue ( cython/cython#1772 ) comes to mind (though that's with fused types). Not sure if there were issues withconst
memoryviews on a specific type. Was this what you were thinking about?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.
Note: After discussion offline, we decided to add one more test using a read-only NumPy array, which has been included in commit ( 2234e5a ).