-
Notifications
You must be signed in to change notification settings - Fork 53
Add Python API, semantics and implementation details for DLPack #106
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
Changes from 7 commits
30276e6
79bb689
4e2c49d
0b701c4
a4549af
a719b18
693b15a
897ca2e
d3b9a79
75261cc
5cde9aa
603ad2e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -366,6 +366,60 @@ Evaluates `x1_i & x2_i` for each element `x1_i` of an array instance `x1` with t | |
Element-wise results must equal the results returned by the equivalent element-wise function [`bitwise_and(x1, x2)`](elementwise_functions.md#logical_andx1-x2-). | ||
``` | ||
|
||
(method-__dlpack__)= | ||
### \_\_dlpack\_\_(/, *, stream=None) | ||
|
||
Exports the array as a DLPack capsule, for consumption by {ref}`function-from_dlpack`. | ||
|
||
#### Parameters | ||
|
||
- **stream**: _Optional\[int\]_ | ||
|
||
- If given, the stream number the consumer will use on the device the array is present on, as a Python integer. Device-specific notes: | ||
|
||
:::{admonition} CUDA | ||
- `None`: producer must assume the legacy default stream (default), | ||
- `1`: the legacy default stream, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps it would be useful to remove 1 and 2, because they are CUDA specific for now(ROCm does not support 1 and 2. Just say stream number represented as a python integer(per platform convention) would work There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we still need to say that 0 is explicitly disallowed for CUDA since it's ambiguous though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, it would be great to point out that that fact. thanks @kkraus14 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe rather than remove things, add something? E.g. make the description: Stream number, as Python integer, for all device types that supports streams. Per-device notes:
and then refer to the DLPack docs (to be written/extended) for more details? Specs that are too terse are correct, but not all that useful. Given how complex it was to make this converge, I feel like we need to give implementers as much guidance as possible. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks @rgommers a per device guidance sounds good. i think it is safe to start with CUDA and ROCm and then expand later There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@kkraus14 This is what I kept saying above 🙂
@rgommers For ROCm, I think it's ok to keep 0, since this is the only way to use the legacy default stream (if so desired). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
- `2`: the per-thread default stream, | ||
- `> 2`: stream number represented as a Python integer. | ||
|
||
Note that `0` is disallowed (it's ambiguous, it could mean either `None`, `1` or `2`). | ||
::: | ||
|
||
:::{admonition} ROCm | ||
- `None`: producer must assume the legacy default stream (default), | ||
- `0`: the default stream, | ||
- `> 2`: stream number represented as a Python integer. | ||
|
||
Using `1` and `2` is not supported. | ||
::: | ||
|
||
```{tip} | ||
It is recommended that implementers explicitly handle streams. If | ||
they use the legacy default stream, specifying `1` (CUDA) or `0` | ||
(ROCm) is preferred. `None` is a safe default for developers who do | ||
not want to think about stream handling at all, potentially at the | ||
cost of more synchronization than necessary. | ||
``` | ||
|
||
#### Returns | ||
|
||
- **capsule**: _<PyCapsule>_ | ||
|
||
- A DLPack capsule for the array. See {ref}`data-interchange` for details. | ||
|
||
(method-__dlpack_device__)= | ||
### \_\_dlpack\_device\_\_() | ||
|
||
Returns device type and device ID in DLPack format. Meant for use within {ref}`function-from_dlpack`. | ||
|
||
#### Returns | ||
|
||
- **device**: _Tuple\[int, int\]_ | ||
|
||
- A tuple `(device_type, device_id)` in DLPack format. | ||
|
||
|
||
(method-__eq__)= | ||
### \_\_eq\_\_(x1, x2, /) | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.