8000 Merge pull request #171 from rgommers/device-support-tweak · lezcano/array-api@e810a81 · GitHub
[go: up one dir, main page]

Skip to content

Commit e810a81

Browse files
authored
Merge pull request data-apis#171 from rgommers/device-support-tweak
Improve description of device handling, add `array.to_device`
2 parents 378255c + b8b2c91 commit e810a81

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

spec/API_specification/array_object.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,3 +1182,24 @@ Evaluates `self_i ^ other_i` for each element of an array instance with the resp
11821182
```{note}
11831183
Element-wise results must equal the results returned by the equivalent element-wise function [`bitwise_xor(x1, x2)`](elementwise_functions.md#bitwise_xorx1-x2-).
11841184
```
1185+
1186+
(method-to_device)=
1187+
### to\_device(self, device, /)
1188+
1189+
Move the array to the given device.
1190+
1191+
#### Parameters
1192+
1193+
- **self**: _<array>_
1194+
1195+
- array instance.
1196+
1197+
- **device**: _<device>_
1198+
1199+
- a `device` object (see {ref}`device-support`).
1200+
1201+
#### Returns
1202+
1203+
- **out**: _<array>_
1204+
1205+
- an array with the same data and dtype, located on the specified device.

spec/design_topics/device_support.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44

55
For libraries that support execution on more than a single hardware device - e.g. CPU and GPU, or multiple GPUs - it is important to be able to control on which device newly created arrays get placed and where execution happens. Attempting to be fully implicit doesn't always scale well to situations with multiple GPUs.
66

7-
Existing libraries employ one or more of these three methods to exert such control:
7+
Existing libraries employ one or more of these three methods to exert such control over data placement:
8+
89
1. A global default device, which may be fixed or user-switchable.
910
2. A context manager to control device assignment within its scope.
10-
3. Local control via explicit keywords and a method to transfer arrays to another device.
11+
3. Local control for data allocation target device via explicit keywords, and a method to transfer arrays to another device.
12+
13+
Libraries differ in how execution is controlled, via a context manager or with the convention that execution takes place on the same device where all argument arrays are allocated. And they may or may not allow mixing arrays on different devices via implicit data transfers.
1114

12-
This standard chooses to add support for method 3 (local control), because it's the most explicit and granular, with its only downside being verbosity. A context manager may be added in the future - see {ref}`device-out-of-scope` for details.
15+
This standard chooses to add support for method 3 (local control), with the convention that execution takes place on the same device where all argument arrays are allocated. The rationale for choosing method 3 is because it's the most explicit and granular, with its only downside being verbosity. A context manager may be added in the future - see {ref}`device-out-of-scope` for details.
1316

1417

1518
## Intended usage

0 commit comments

Comments
 (0)
0