diff --git a/CHANGELOG.md b/CHANGELOG.md index f660fa239b..6ecef415e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,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) * 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) +* `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 * 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) 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 d19d9844bb..b76c703f42 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); } + // 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 && + DPCTL_SyclBackendToDPCTLBackendType(P->get_backend()) != + DPCTLSyclBackendType::DPCTL_OPENCL) + { + return wrap(DevicesVectorPtr); + } + try { auto SyclDTy = DPCTL_DPCTLDeviceTypeToSyclDeviceType(DTy); auto Devices = P->get_devices(SyclDTy);