Skip to content

Commit 6d9edf2

Browse files
authored
Merge pull request #2306 from IntelPython/work-around-custom-devices-level-zero
Avoid warnings from Unified Runtime Level Zero adapter
2 parents ea89d1b + 91e597c commit 6d9edf2

5 files changed

Lines changed: 35 additions & 2 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2727
### Fixed
2828
* Removed stale `select_host_device` and `has_host_device` names from `dpctl.__all__`, which made `from dpctl import *` fail with `AttributeError` [gh-2410](https://github.com/IntelPython/dpctl/pull/2410)
2929
* A USM allocation that fails now drops the references held for offloaded tasks that have completed, and is attempted once more if that released anything, so that memory only waiting to be given up is not reported as unavailable [gh-2359](https://github.com/IntelPython/dpctl/pull/2359)
30+
* `dpctl.SyclPlatform.get_devices` no longer prints Unified Runtime warnings for `device_type="custom"` on non-OpenCL platforms, where custom devices are not supported [gh-2306](https://github.com/IntelPython/dpctl/pull/2306)
3031

3132
### Maintenance
3233
* Removed the `-fno-sycl-id-queries-fit-in-int` compile option, which none of the `dpctl` extensions need since `dpctl.tensor` moved to `dpnp` [gh-2413](https://github.com/IntelPython/dpctl/pull/2413)

‎dpctl/_sycl_platform.pyx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,10 @@ cdef class SyclPlatform(_SyclPlatform):
387387
device_type (str, :class:`dpctl.device_type`, optional):
388388
A :class:`dpctl.device_type` enum value or a string that
389389
specifies a SYCL device type. Currently, accepted values are:
390-
"gpu", "cpu", "accelerator", or "all", and their equivalent
391-
``dpctl.device_type`` enumerators.
390+
"gpu", "cpu", "accelerator", "automatic", "custom", or "all",
391+
and their equivalent ``dpctl.device_type`` enumerators.
392+
Only OpenCL platforms support custom devices; for other
393+
platforms, "custom" returns an empty tuple.
392394
Default: ``dpctl.device_type.all``.
393395
394396
Returns:

‎dpctl/tests/test_sycl_platform.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,24 @@ def test_platform_get_devices_enum_device_type():
260260
assert (d.device_type == dty for d in devices)
261261

262262

263+
@pytest.mark.parametrize("dty", ["custom", device_type.custom])
264+
def test_platform_get_devices_custom_non_opencl(dty, capfd):
265+
platforms = [
266+
p
267+
for p in dpctl.get_platforms()
268+
if p.backend != dpctl.backend_type.opencl
269+
]
270+
if not platforms:
271+
pytest.skip("No non-OpenCL platforms available")
272+
capfd.readouterr()
273+
for p in platforms:
274+
assert len(p.get_devices(device_type=dty)) == 0
275+
out, err = capfd.readouterr()
276+
# e.g., the Level Zero adapter warns on device_type::custom
277+
assert out == ""
278+
assert err == ""
279+
280+
263281
def test_platform_get_composite_devices():
264282
platforms = dpctl.get_platforms()
265283
if platforms:

‎libsyclinterface/include/syclinterface/dpctl_sycl_platform_interface.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ size_t DPCTLPlatform_Hash(__dpctl_keep const DPCTLSyclPlatformRef PRef);
183183
* @brief Returns a vector of devices associated with sycl::platform referenced
184184
* by DPCTLSyclPlatformRef object.
185185
*
186+
* Only OpenCL platforms support custom devices; for other platforms,
187+
* DPCTL_CUSTOM returns an empty vector.
188+
*
186189
* @param PRef The DPCTLSyclPlatformRef pointer.
187190
* @param DTy A DPCTLSyclDeviceType enum value.
188191
* @return A DPCTLDeviceVectorRef with devices associated with given PRef.

‎libsyclinterface/source/dpctl_sycl_platform_interface.cpp‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,15 @@ DPCTLPlatform_GetDevices(__dpctl_keep const DPCTLSyclPlatformRef PRef,
304304
return wrap<vecTy>(DevicesVectorPtr);
305305
}
306306

307+
// Only OpenCL supports custom devices; other backends may warn when asked
308+
// for them (e.g., the Unified Runtime Level Zero adapter)
309+
if (DTy == DPCTLSyclDeviceType::DPCTL_CUSTOM &&
310+
DPCTL_SyclBackendToDPCTLBackendType(P->get_backend()) !=
311+
DPCTLSyclBackendType::DPCTL_OPENCL)
312+
{
313+
return wrap<vecTy>(DevicesVectorPtr);
314+
}
315+
307316
try {
308317
auto SyclDTy = DPCTL_DPCTLDeviceTypeToSyclDeviceType(DTy);
309318
auto Devices = P->get_devices(SyclDTy);

0 commit comments

Comments
 (0)