Skip to content

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

Open
antonwolfy wants to merge 4 commits into
masterfrom
return-device-objs-to-comply-with-array-api
Open

Return Python array API compatible device objects from inspection namespace#2979
antonwolfy wants to merge 4 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

Copy link
Copy Markdown
Contributor

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

@github-actions

Copy link
Copy Markdown
Contributor

Array API standard conformance tests for dpnp=0.21.0dev2=py313h509198e_8 ran successfully.
Passed: 1355
Failed: 5
Skipped: 16

@antonwolfy antonwolfy marked this pull request as ready for review June 29, 2026 15:58
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.

1 participant