Skip to content

Feature/get devices ordering #451

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 19, 2021
Merged

Conversation

oleksandr-pavlyk
Copy link
Contributor

Closes #447

The root cause for 447 was that devices.get_devices relied on cached unordered map, which does not guarantee the ordering.

The fix was to change implementation of DPCLDeviceMgr_GetDevices to iterate over device::get_devices (which is also internally cached by SYCL runtime) which would guarantee the same ordering as used by filter selector.

Python tests were added.

In [1]: import dpctl

In [2]: d0 = dpctl.SyclDevice("gpu:0")

In [3]: d0.filter_string
Out[3]: 'opencl:gpu:0'

In [4]: [i for i, di in enumerate(dpctl.get_devices(dpctl.backend_type.all, dpctl.device_type.gpu)) if di == d0]
Out[4]: [0]

In [5]: d0 == dpctl.SyclDevice(d0.filter_string)
Out[5]: True

In [6]: d1 = dpctl.SyclDevice("gpu:1")

In [7]: d1.filter_string
Out[7]: 'level_zero:gpu:0'

In [8]: [i for i, di in enumerate(dpctl.get_devices(dpctl.backend_type.all, dpctl.device_type.gpu)) if di == d1]
Out[8]: [1]

In [9]: d1 == dpctl.SyclDevice(d1.filter_string)
Out[9]: True

DPCLTDeviceMgr_GetDevices should not rely of the cached unordered map
of root sycl devices to sycl contexts. Because unordered map can change
the ordering.

Changed implementation to iterate over device::get_devices instead.

Confirmation of the fix:

```
In [1]: import dpctl

In [2]: d0 = dpctl.SyclDevice("gpu:0")

In [3]: d0.filter_string
Out[3]: 'opencl:gpu:0'

In [4]: [i for i, di in enumerate(dpctl.get_devices(dpctl.backend_type.all, dpctl.device_type.gpu)) if di == d0]
Out[4]: [0]

In [5]: d0 == dpctl.SyclDevice(d0.filter_string)
Out[5]: True

In [6]: d1 = dpctl.SyclDevice("gpu:1")

In [7]: d1.filter_string
Out[7]: 'level_zero:gpu:0'

In [8]: [i for i, di in enumerate(dpctl.get_devices(dpctl.backend_type.all, dpctl.device_type.gpu)) if di == d1]
Out[8]: [1]

In [9]: d1 == dpctl.SyclDevice(d1.filter_string)
Out[9]: True
```
@oleksandr-pavlyk oleksandr-pavlyk force-pushed the feature/get-devices-ordering branch from 699e35e to 00cb985 Compare May 19, 2021 14:13
DeviceType enums now are [0, 8), BackendType enums have lower
16 bits zero, and span [1<<16, 1<<20)
@oleksandr-pavlyk oleksandr-pavlyk force-pushed the feature/get-devices-ordering branch from 3caf382 to e19e0f7 Compare May 19, 2021 18:18
@oleksandr-pavlyk
Copy link
Contributor Author

@diptorupd Ready to merge?

@oleksandr-pavlyk oleksandr-pavlyk merged commit a55ce01 into master May 19, 2021
@oleksandr-pavlyk oleksandr-pavlyk deleted the feature/get-devices-ordering branch May 19, 2021 19:55
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.

dpctl.get_devices does not return devices in the same order as sycl::device::get_devices
2 participants