Skip to content

Feature/producing filter selector#453

Merged
diptorupd merged 2 commits intomasterfrom
feature/producing-filter-selector
May 20, 2021
Merged

Feature/producing filter selector#453
diptorupd merged 2 commits intomasterfrom
feature/producing-filter-selector

Conversation

@oleksandr-pavlyk
Copy link
Copy Markdown
Contributor

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

Comment thread dpctl-capi/source/dpctl_sycl_device_manager.cpp Outdated
@diptorupd
Copy link
Copy Markdown
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