Skip to content

Commit 96208a6

Browse files
committed
skip custom device lookup on all non-opencl platforms
only opencl supports custom devices; other backends may warn when asked for them. add a test that no output is printed, and document the behavior
1 parent b885d3d commit 96208a6

5 files changed

Lines changed: 30 additions & 6 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717

1818
### Fixed
1919
* 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)
20+
* `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)
2021

2122
### Maintenance
2223

‎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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,12 +304,12 @@ DPCTLPlatform_GetDevices(__dpctl_keep const DPCTLSyclPlatformRef PRef,
304304
return wrap<vecTy>(DevicesVectorPtr);
305305
}
306306

307-
DPCTLSyclBackendType BTy =
308-
DPCTL_SyclBackendToDPCTLBackendType(P->get_backend());
307+
// Only OpenCL supports custom devices; other backends may warn when asked
308+
// for them (e.g., the Unified Runtime Level Zero adapter)
309309
if (DTy == DPCTLSyclDeviceType::DPCTL_CUSTOM &&
310-
BTy == DPCTLSyclBackendType::DPCTL_LEVEL_ZERO)
310+
DPCTL_SyclBackendToDPCTLBackendType(P->get_backend()) !=
311+
DPCTLSyclBackendType::DPCTL_OPENCL)
311312
{
312-
// avoid ugly warnings from unified runtime
313313
return wrap<vecTy>(DevicesVectorPtr);
314314
}
315315

0 commit comments

Comments
 (0)