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/producing filter selector #453

Merged
merged 2 commits into from
May 20, 2021

Conversation

oleksandr-pavlyk
Copy link
Collaborator

dpctl-capi/:

  • Added DPCTLDeviceMgr_GetPositionInDevices(DRef, device_mask) that returns ordinal of the given DRef in the filtered vector returned by sycl::device::get_devices(), or -1 if not found (e.g. DRef points to a sub-device).
  • Added tests, and docstring

dpctl/:

  • Added DPCTLDeviceMgr_GetPositionInDevices to _backend.pxd
  • Implemented 4 cdef methods of dpctl.SyclDevice:
    • get_overall_ordinal(self) - index in unfiltered vector returned by get_devices().
    • get_backend_ordinal(self) - index in vector filtered to only contain devices with the backend of this device
    • get_device_type_ordinal(self) - index in vector filtered to only contain devices with device_type as in this device
    • get_backend_and_device_type_ordinal(self) - indexed in vector filtered to only contain devices with device_type and backend of this device
      * Added Python visible method get_filter_string(self, include_backend=True, include_device_type=True) which producer filter selector string selecting this device that would include or omit backend/device_type as requested.
      * Test added

Example:

In [1]: import dpctl

In [2]: default_dev = dpctl.SyclDevice()

In [3]: default_dev.get_filter_string() # same as default_dev.filter_string
Out[3]: 'level_zero:gpu:0'

In [4]: default_dev.get_filter_string(include_backend=False)
Out[4]: 'gpu:1'

In [5]: default_dev == dpctl.SyclDevice(_)
Out[5]: True

In [6]: default_dev.get_filter_string(include_device_type=False)
Out[6]: 'level_zero:0'

In [7]: default_dev == dpctl.SyclDevice(_)
Out[7]: True

In [8]: default_dev.get_filter_string(include_device_type=False, include_backend=False)
Out[8]: '4'

In [9]: default_dev == dpctl.SyclDevice(_)
Out[9]: True

@diptorupd
Copy link
Contributor

LGTM bar the minor naming nitpick.

This function is more general that DPCTL_GetRelativeId(DRef).
The latter corresponds to DPCTLDeviceMgr_GetPositionInDevices(DRef,
 DPCTLDevice_GetBackend(DRef) | DPCTLDevice_GetDeviceType(DRef));

The function can be used to generate filter selector based on a
pattern, expressed by device_mask (any backend, given type), or
(any backend, any type), or (given backend, given type).
@oleksandr-pavlyk oleksandr-pavlyk force-pushed the feature/producing-filter-selector branch 2 times, most recently from f4d93b4 to 92161ff Compare May 20, 2021 16:54
dpctl.SyclDevice.filter_string property gives fully specified
filter selector, which includes backend, device_type and relative id.

get_filter_string(include_backend, include_device_type) allows one
to construct filter strings which would omit either backend or device_type
or both, guaranteeing that dpctl.SyclDevice(obtained_selector_string)
will give back the same device.

```
In [1]: import dpctl

In [2]: default_dev = dpctl.SyclDevice()

In [3]: default_dev.get_filter_string(include_backend=False)
Out[3]: 'gpu:1'

In [4]: default_dev.get_filter_string(include_device_type=False)
Out[4]: 'level_zero:0'

In [5]: default_dev.get_filter_string(include_device_type=False, include_backend=False)
Out[5]: '4'
```
@oleksandr-pavlyk oleksandr-pavlyk force-pushed the feature/producing-filter-selector branch from 92161ff to c31be27 Compare May 20, 2021 16:54
@diptorupd diptorupd merged commit b3dac2f into master May 20, 2021
@diptorupd diptorupd deleted the feature/producing-filter-selector branch May 20, 2021 16: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.

2 participants