Skip to content

Commit 5ecbce4

Browse files
leofangkgryte
andauthored
Address device related issues (#259)
* add to_device * clarify device object * clarify library-specific stream can be used * move -> copy * apply review comments * Apply suggestions from code review Co-authored-by: Athan <[email protected]> * Update copy * Add linebreak. Co-authored-by: Athan <[email protected]>
1 parent 44ccd65 commit 5ecbce4

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

spec/API_specification/array_object.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,10 @@ Exports the array for consumption by {ref}`function-from_dlpack` as a DLPack cap
458458

459459
For other device types which do have a stream, queue or similar synchronization mechanism, the most appropriate type to use for `stream` is not yet determined. E.g., for SYCL one may want to use an object containing an in-order `cl::sycl::queue`. This is allowed when libraries agree on such a convention, and may be standardized in a future version of this API standard.
460460

461+
```{note}
462+
Support for a `stream` value other than `None` is optional and implementation-dependent.
463+
```
464+
461465
Device-specific notes:
462466
463467
:::{admonition} CUDA
@@ -1213,9 +1217,9 @@ Element-wise results must equal the results returned by the equivalent element-w
12131217
```
12141218

12151219
(method-to_device)=
1216-
### to\_device(self, device, /)
1220+
### to\_device(self, device, /, *, stream=None)
12171221

1218-
Move the array to the given device.
1222+
Copy the array from the device on which it currently resides to the specified `device`.
12191223

12201224
#### Parameters
12211225

@@ -1227,8 +1231,16 @@ Move the array to the given device.
12271231

12281232
- a `device` object (see {ref}`device-support`).
12291233

1234+
- **stream**: _Optional\[ Union\[ int, Any ]]_
1235+
1236+
- stream object to use during copy. In addition to the types supported in {ref}`method-__dlpack__`, implementations may choose to support any library-specific stream object with the caveat that any code using such an object would not be portable.
1237+
12301238
#### Returns
12311239

12321240
- **out**: _&lt;array&gt;_
12331241

1234-
- an array with the same data and dtype, located on the specified device.
1242+
- an array with the same data and data type as `self` and located on the specified `device`.
1243+
1244+
```{note}
1245+
If `stream` is given, the copy operation should be enqueued on the provided `stream`; otherwise, the copy operation should be enqueued on the default stream/queue. Whether the copy is performed synchronously or asynchronously is implementation-dependent. Accordingly, if synchronization is required to guarantee data safety, this must be clearly explained in a conforming library's documentation.
1246+
```

spec/design_topics/device_support.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,22 @@ cross-device data transfer:
4848
libraries is out of scope).
4949
2. A `device=None` keyword for array creation functions, which takes an
5050
instance of a `Device` object.
51-
3. A `.to_device(device)` method on the array object, with `device` again being
52-
a `Device` object, to move an array to a different device.
51+
3. A `.to_device` method on the array object to copy an array to a different device.
5352

5453
```{note}
55-
The only way to obtain a `Device` object is from the `.device` property on
56-
the array object, hence there is no `Device` object in the array API itself
57-
that can be instantiated to point to a specific physical or logical device.
54+
In the current API standard, the only way to obtain a `Device` object is from the
55+
`.device` property on the array object. The standard does **not** include a universal
56+
`Device` object recognized by all compliant libraries. Accordingly, the standard does
57+
not provide a means of instantiating a `Device` object to point to a specific physical or
58+
logical device.
59+
60+
The choice to not include a standardized `Device` object may be revisited in a future revision of this standard.
61+
62+
For array libraries which concern themselves with multi-device support, including CPU and GPU,
63+
they are free to expose a library-specific device object (e.g., for creating an
64+
array on a particular device). While a library-specific device object can be used as input to
65+
`to_device`, beware that this will mean non-portability as code will be specific to
66+
that library.
5867
```
5968

6069

0 commit comments

Comments
 (0)