Skip to content
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

Feature/sycl device parent #366

Merged
merged 6 commits into from
Apr 8, 2021
Merged

Conversation

oleksandr-pavlyk
Copy link
Collaborator

This PR adds two functions to C-API:

  • DPCTLDevice_GetParentDevice(const DPCTLSyclDeviceRef DRef) - gives opaque reference to parent sycl::device if DRef is associated with a root device, or a nullptr otherwise.
  • DPCTLDeviceMgr_GetRelativeId(const DPCTLSyclDeviceRef DRef) - gives index of sycl::device referenced by DRef in DRef_platform.get_device( DRef_device_type ), or -1 is the device was not found (expected for sub-devices).

Implemented parent_device property in SyclDevice as well as properties device_filter_tuple and device_filter_string.

In [1]: import dpctl

In [2]: dpctl.SyclDevice("cpu").device_filter_string
Out[2]: 'opencl:cpu:0'

In [3]: dpctl.SyclDevice("gpu").device_filter_string
Out[3]: 'level_zero:gpu:0'

In [4]: dpctl.SyclDevice("opencl:gpu").device_filter_string
Out[4]: 'opencl:gpu:0'

In [5]: dpctl.SyclDevice().device_filter_string
Out[5]: 'level_zero:gpu:0'

In [6]: dpctl.SyclDevice("0").device_filter_string
Out[6]: 'opencl:accelerator:0'

In [7]: dpctl.SyclDevice("1").device_filter_string
Out[7]: 'opencl:cpu:0'

In [8]: dpctl.SyclDevice("2").device_filter_string
Out[8]: 'opencl:cpu:0'

In [9]: dpctl.SyclDevice("3").device_filter_string
Out[9]: 'opencl:gpu:0'

In [10]: dpctl.SyclDevice("4").device_filter_string
Out[10]: 'level_zero:gpu:0'

@oleksandr-pavlyk
Copy link
Collaborator Author

Another example showcasing parent_device:

In [1]: import dpctl

In [2]: cpu_d = dpctl.SyclDevice("cpu")

In [3]: sd0, sd1 = cpu_d.create_sub_devices(partition=(6,6))

In [4]: sd0.parent_device == cpu_d
Out[4]: True

In [5]: sd1.parent_device == cpu_d
Out[5]: True

@oleksandr-pavlyk oleksandr-pavlyk force-pushed the feature/SyclDevice-parent branch 2 times, most recently from 85ec30d to b7284f5 Compare April 7, 2021 16:35
diptorupd
diptorupd previously approved these changes Apr 7, 2021
This returns None for root devices, but returns a SyclDevice for
a sub-device.

Added cpdef method equals, and Python method __eq__

```
Python 3.7.9 (default, Mar 10 2021, 05:18:00)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.22.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import dpctl

In [2]: cpu_device = dpctl.SyclDevice("cpu")

In [3]: cpu_device == cpu_device
Out[3]: True

In [4]: cpu_device2 = dpctl.SyclDevice("cpu")

In [5]: cpu_device == cpu_device2
Out[5]: True

In [6]: [d1, d2, d3 ] =cpu_device.create_sub_devices(partition=4)

In [7]: d1.parent_device == cpu_device
Out[7]: True

In [8]: d2.parent_device == cpu_device
Out[8]: True

In [9]: d3.parent_device == cpu_device
Out[9]: True
```
This computes the relative id (position in the vector) inside
p.get_devices( sycl_device_type(DRef) ).

Returns -1 is the device was not found (expected to happen for
sub-devices).
```
In [1]: import dpctl

In [2]: dpctl.SyclDevice("cpu").filter_string
Out[2]: 'opencl:cpu:0'

In [3]: dpctl.SyclDevice("gpu").filter_string
Out[3]: 'level_zero:gpu:0'

In [4]: dpctl.SyclDevice("opencl:gpu").filter_string
Out[4]: 'opencl:gpu:0'

In [5]: dpctl.SyclDevice().filter_string
Out[5]: 'level_zero:gpu:0'

In [6]: dpctl.SyclDevice("0").filter_string
Out[6]: 'opencl:accelerator:0'

In [7]: dpctl.SyclDevice("1").filter_string
Out[7]: 'opencl:cpu:0'

In [8]: dpctl.SyclDevice("2").filter_string
Out[8]: 'opencl:cpu:0'

In [9]: dpctl.SyclDevice("3").filter_string
Out[9]: 'opencl:gpu:0'

In [10]: dpctl.SyclDevice("4").filter_string
Out[10]: 'level_zero:gpu:0'
```
@oleksandr-pavlyk oleksandr-pavlyk force-pushed the feature/SyclDevice-parent branch from fb95799 to f2c900c Compare April 8, 2021 00:40
@oleksandr-pavlyk oleksandr-pavlyk merged commit 4f4adf5 into master Apr 8, 2021
@oleksandr-pavlyk oleksandr-pavlyk deleted the feature/SyclDevice-parent branch April 8, 2021 11:37
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.

2 participants