-
Notifications
You must be signed in to change notification settings - Fork 53
Add data interchange section, using DLPack #34
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
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7d240c9
Add data interchange section, using DLPack
rgommers e65de27
Update the recommendation to raise on device transfers.
rgommers c92d27e
Add note on alternatives to DLPack (buffer protocol, `__cuda_array_in…
rgommers ea86043
Another small addition to clarify what `__array__` does
rgommers 9b4823f
Reflow text in data interchange file
rgommers 7f69239
minor cleanup
rgommers 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 hidden or 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 hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,41 @@ | ||
# Data interchange mechanisms | ||
|
||
This section discusses the mechanism to convert one type of array into another. | ||
As discussed in the :ref:`assumptions-dependencies <Assumptions>` section, | ||
_functions_ provided by an array library are not expected to operate on | ||
_array types_ implemented by another library. Instead, the array can be | ||
converted to a "native" array type. | ||
|
||
The interchange mechanism must offer the following: | ||
|
||
1. Data access via a protocol that describes the memory layout of the array | ||
in an implementation-independent manner. | ||
_Rationale: any number of libraries must be able to exchange data, and no | ||
particular package must be needed to do so._ | ||
2. Support for all dtypes in this API standard (see :ref:`data-types`). | ||
3. Device support. It must be possible to determine on what device the array | ||
that is to be converted lives. | ||
_Rationale: there are CPU-only, GPU-only, and multi-device array types; | ||
it's best to support these with a single protocol (with separate | ||
per-device protocols it's hard to figure out unambiguous rules for which | ||
protocol gets used, and the situation will get more complex over time | ||
as TPU's and other accelerators become more widely available)._ | ||
4. Moving data from one device to another must raise by default, and be | ||
explicitly enabled by the user. | ||
_Rationale: data transfer is typically very expensive, and hence must not | ||
happen silently._ | ||
5. Zero-copy semantics where possible, making a copy only if needed (e.g. | ||
when data is not contiguous in memory). | ||
_Rationale: performance._ | ||
6. A stable C ABI. | ||
_Rationale: all prominent existing array libraries are implemented in | ||
C/C++, and are released independently from each other. Hence a stable C | ||
ABI is required for packages to work well together._ | ||
|
||
The best candidate for this protocol is DLPack. See the | ||
[RFC to adopt DLPack](https://github.com/data-apis/consortium-feedback/issues/1) | ||
for details. | ||
|
||
TODO: design an appropriate Python API for DLPACK (`to_dlpack` followed by `from_dlpack` is a little clunky, we'd like it to work more like the buffer protocol does on CPU, with a single constructor function). | ||
|
||
TODO: specify the expected behaviour with copy/view/move/shared-memory semantics in detail. |
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.
Uh oh!
There was an error while loading. Please reload this page.