Commit eda845b
committed
Return Python array API compatible device objects from inspection namespace (#2979)
The array API inspection namespace (`__array_namespace_info__()`)
returned raw `dpctl.SyclDevice` objects from `devices()` and
`default_device()`, while an array's `.device` attribute is a
`dpnp.tensor.Device` wrapper.
Because `Device.__eq__` does not consider a bare `SyclDevice` equal, the
objects returned by the inspection API did **not** compare equal to
`x.device`, which the Python array API standard requires:
```python
import dpnp as np
devices = np.__array_namespace_info__().devices()
devices
# Out:
# (<dpctl.SyclDevice [backend_type.level_zero, device_type.gpu, Intel(R) Graphics [0x7d41]] at 0x74bb28198030>,
# <dpctl.SyclDevice [backend_type.opencl, device_type.cpu, Intel(R) Core(TM) Ultra 7 265U] at 0x74bb28198d30>,
# <dpctl.SyclDevice [backend_type.opencl, device_type.gpu, Intel(R) Graphics [0x7d41]] at 0x74bb2a117870>)
x = np.ones(10)
y = np.from_dlpack(x, device=devices[1])
y.device == devices[1]
# Out: False
y.device.sycl_device == devices[1]
# Out: True
```
## Changes
This PR updates `Info.devices()` to return a **tuple** of
`dpnp.tensor.Device` wrappers (built via `Device.create_device`),
instead of a list of raw `dpctl.SyclDevice` objects. The wrappers carry
the default cached queues for each root device, which is sufficient for
the common cases.
Additionally `Info.default_device()` likewise now returns a `Device`
wrapper for consistency, so `x.device`, `default_device()`, and the
elements of `devices()` all compare equal for the default device. 576a07b1 parent b876fd6 commit eda845b
2 files changed
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1040 | 1040 | | |
1041 | 1041 | | |
1042 | 1042 | | |
1043 | | - | |
| 1043 | + | |
1044 | 1044 | | |
1045 | 1045 | | |
1046 | 1046 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments