Skip to content

Return Python array API compatible device objects from inspection namespace#2979

Merged
antonwolfy merged 6 commits into
masterfrom
return-device-objs-to-comply-with-array-api
Jul 6, 2026
Merged

Return Python array API compatible device objects from inspection namespace#2979
antonwolfy merged 6 commits into
masterfrom
return-device-objs-to-comply-with-array-api

Conversation

@antonwolfy

@antonwolfy antonwolfy commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

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:

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.

  • Have you provided a meaningful PR description?
  • Have you added a test, reproducer or referred to an issue with a reproducer?
  • Have you tested your changes locally for CPU and GPU devices?
  • Have you made sure that new changes do not introduce compiler warnings?
  • Have you checked performance impact of proposed changes?
  • Have you added documentation for your changes, if necessary?
  • Have you added your changes to the changelog?

@antonwolfy antonwolfy added this to the 0.21.0 release milestone Jun 29, 2026
@antonwolfy antonwolfy self-assigned this Jun 29, 2026
@github-actions

github-actions Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

View rendered docs @ https://intelpython.github.io/dpnp/index.html

@github-actions

github-actions Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Array API standard conformance tests for dpnp=0.21.0dev2=py313h509198e_20 ran successfully.
Passed: 1373
Failed: 2
Skipped: 5

@antonwolfy antonwolfy marked this pull request as ready for review June 29, 2026 15:58
@coveralls

coveralls commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Coverage Status

No base build to compare — return-device-objs-to-comply-with-array-api into master

@antonwolfy antonwolfy merged commit 576a07b into master Jul 6, 2026
94 of 106 checks passed
@antonwolfy antonwolfy deleted the return-device-objs-to-comply-with-array-api branch July 6, 2026 18:02
github-actions Bot added a commit that referenced this pull request Jul 6, 2026
…espace (#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. 576a07b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants