From b885d3db1e102c49053d94b09b999fd6fb0252da Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Wed, 29 Apr 2026 15:42:53 -0700 Subject: [PATCH 1/2] work around UR warnings from SyclPlatform.get_devices --- .../source/dpctl_sycl_platform_interface.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libsyclinterface/source/dpctl_sycl_platform_interface.cpp b/libsyclinterface/source/dpctl_sycl_platform_interface.cpp index d19d9844bb..e6c5bd56f4 100644 --- a/libsyclinterface/source/dpctl_sycl_platform_interface.cpp +++ b/libsyclinterface/source/dpctl_sycl_platform_interface.cpp @@ -304,6 +304,15 @@ DPCTLPlatform_GetDevices(__dpctl_keep const DPCTLSyclPlatformRef PRef, return wrap(DevicesVectorPtr); } + DPCTLSyclBackendType BTy = + DPCTL_SyclBackendToDPCTLBackendType(P->get_backend()); + if (DTy == DPCTLSyclDeviceType::DPCTL_CUSTOM && + BTy == DPCTLSyclBackendType::DPCTL_LEVEL_ZERO) + { + // avoid ugly warnings from unified runtime + return wrap(DevicesVectorPtr); + } + try { auto SyclDTy = DPCTL_DPCTLDeviceTypeToSyclDeviceType(DTy); auto Devices = P->get_devices(SyclDTy); From 96208a68743d59d9c8b7b8d2d9bb3ffc3f39a52f Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Tue, 3 Nov 2026 13:31:24 -0800 Subject: [PATCH 2/2] 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 --- CHANGELOG.md | 1 + dpctl/_sycl_platform.pyx | 6 ++++-- dpctl/tests/test_sycl_platform.py | 18 ++++++++++++++++++ .../dpctl_sycl_platform_interface.h | 3 +++ .../source/dpctl_sycl_platform_interface.cpp | 8 ++++---- 5 files changed, 30 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b3d0c90d1..d94ade6877 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed * 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) +* `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) ### Maintenance diff --git a/dpctl/_sycl_platform.pyx b/dpctl/_sycl_platform.pyx index d722e93b50..04af9bb86e 100644 --- a/dpctl/_sycl_platform.pyx +++ b/dpctl/_sycl_platform.pyx @@ -387,8 +387,10 @@ cdef class SyclPlatform(_SyclPlatform): device_type (str, :class:`dpctl.device_type`, optional): A :class:`dpctl.device_type` enum value or a string that specifies a SYCL device type. Currently, accepted values are: - "gpu", "cpu", "accelerator", or "all", and their equivalent - ``dpctl.device_type`` enumerators. + "gpu", "cpu", "accelerator", "automatic", "custom", or "all", + and their equivalent ``dpctl.device_type`` enumerators. + Only OpenCL platforms support custom devices; for other + platforms, "custom" returns an empty tuple. Default: ``dpctl.device_type.all``. Returns: diff --git a/dpctl/tests/test_sycl_platform.py b/dpctl/tests/test_sycl_platform.py index 0660617752..7364a5ea87 100644 --- a/dpctl/tests/test_sycl_platform.py +++ b/dpctl/tests/test_sycl_platform.py @@ -260,6 +260,24 @@ def test_platform_get_devices_enum_device_type(): assert (d.device_type == dty for d in devices) +@pytest.mark.parametrize("dty", ["custom", device_type.custom]) +def test_platform_get_devices_custom_non_opencl(dty, capfd): + platforms = [ + p + for p in dpctl.get_platforms() + if p.backend != dpctl.backend_type.opencl + ] + if not platforms: + pytest.skip("No non-OpenCL platforms available") + capfd.readouterr() + for p in platforms: + assert len(p.get_devices(device_type=dty)) == 0 + out, err = capfd.readouterr() + # e.g., the Level Zero adapter warns on device_type::custom + assert out == "" + assert err == "" + + def test_platform_get_composite_devices(): platforms = dpctl.get_platforms() if platforms: diff --git a/libsyclinterface/include/syclinterface/dpctl_sycl_platform_interface.h b/libsyclinterface/include/syclinterface/dpctl_sycl_platform_interface.h index 1cde75d710..affc16150e 100644 --- a/libsyclinterface/include/syclinterface/dpctl_sycl_platform_interface.h +++ b/libsyclinterface/include/syclinterface/dpctl_sycl_platform_interface.h @@ -183,6 +183,9 @@ size_t DPCTLPlatform_Hash(__dpctl_keep const DPCTLSyclPlatformRef PRef); * @brief Returns a vector of devices associated with sycl::platform referenced * by DPCTLSyclPlatformRef object. * + * Only OpenCL platforms support custom devices; for other platforms, + * DPCTL_CUSTOM returns an empty vector. + * * @param PRef The DPCTLSyclPlatformRef pointer. * @param DTy A DPCTLSyclDeviceType enum value. * @return A DPCTLDeviceVectorRef with devices associated with given PRef. diff --git a/libsyclinterface/source/dpctl_sycl_platform_interface.cpp b/libsyclinterface/source/dpctl_sycl_platform_interface.cpp index e6c5bd56f4..b76c703f42 100644 --- a/libsyclinterface/source/dpctl_sycl_platform_interface.cpp +++ b/libsyclinterface/source/dpctl_sycl_platform_interface.cpp @@ -304,12 +304,12 @@ DPCTLPlatform_GetDevices(__dpctl_keep const DPCTLSyclPlatformRef PRef, return wrap(DevicesVectorPtr); } - DPCTLSyclBackendType BTy = - DPCTL_SyclBackendToDPCTLBackendType(P->get_backend()); + // Only OpenCL supports custom devices; other backends may warn when asked + // for them (e.g., the Unified Runtime Level Zero adapter) if (DTy == DPCTLSyclDeviceType::DPCTL_CUSTOM && - BTy == DPCTLSyclBackendType::DPCTL_LEVEL_ZERO) + DPCTL_SyclBackendToDPCTLBackendType(P->get_backend()) != + DPCTLSyclBackendType::DPCTL_OPENCL) { - // avoid ugly warnings from unified runtime return wrap(DevicesVectorPtr); }