Skip to content
Merged
Prev Previous commit
Next Next commit
Add dpctl.SyclPlatform tests for get_devices method
Also removes some remaining, sporadic references to the deprecated sycl::info::device_type::host
  • Loading branch information
ndgrigorian committed Mar 1, 2025
commit 034f7cd000b9ccd43cf2a386227a5a01cf53a520
4 changes: 2 additions & 2 deletions dpctl/_sycl_device_factory.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ cpdef list get_devices(backend=backend_type.all, device_type=device_type_t.all):
device_type (optional):
Comment thread
ndgrigorian marked this conversation as resolved.
Outdated
A :class:`dpctl.device_type` enum value or a string that
specifies a SYCL device type. Currently, accepted values are:
"gpu", "cpu", "accelerator", "host", or "all".
"gpu", "cpu", "accelerator", or "all".
Default: ``dpctl.device_type.all``.
Returns:
list:
Expand Down Expand Up @@ -218,7 +218,7 @@ cpdef int get_num_devices(
device_type (optional):
Comment thread
ndgrigorian marked this conversation as resolved.
Outdated
A :class:`dpctl.device_type` enum value or a string that
specifies a SYCL device type. Currently, accepted values are:
"gpu", "cpu", "accelerator", "host", or "all".
"gpu", "cpu", "accelerator", or "all".
Default: ``dpctl.device_type.all``.
Returns:
int:
Expand Down
2 changes: 1 addition & 1 deletion dpctl/_sycl_platform.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ cdef class SyclPlatform(_SyclPlatform):
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", "host", or "all".
"gpu", "cpu", "accelerator", or "all".
Default: ``dpctl.device_type.all``.

Returns:
Expand Down
4 changes: 0 additions & 4 deletions dpctl/tests/test_sycl_device_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ def string_to_device_type(dty_str):
return dty.accelerator
elif dty_str == "cpu":
return dty.cpu
Comment thread
ndgrigorian marked this conversation as resolved.
elif dty_str == "host":
return dty.host
elif dty_str == "gpu":
return dty.gpu

Expand All @@ -62,8 +60,6 @@ def string_to_backend_type(bty_str):
return bty.cuda
elif bty_str == "hip":
return bty.hip
elif bty_str == "host":
return bty.host
elif bty_str == "level_zero":
return bty.level_zero
elif bty_str == "opencl":
Expand Down
47 changes: 47 additions & 0 deletions dpctl/tests/test_sycl_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import pytest

import dpctl
from dpctl import device_type

from .helper import has_sycl_platforms

Expand Down Expand Up @@ -212,3 +213,49 @@ def test_get_platforms():
assert has_sycl_platforms()
except Exception:
pytest.fail("Encountered an exception inside get_platforms().")


def test_platform_get_devices():
platforms = dpctl.get_platforms()
if platforms:
for p in platforms:
assert len(p.get_devices())
else:
pytest.skip("No platforms available")
Comment thread
ndgrigorian marked this conversation as resolved.


def _str_device_type_to_enum(dty):
if dty == "accelerator":
return device_type.accelerator
elif dty == "cpu":
return device_type.cpu
elif dty == "gpu":
return device_type.gpu


def test_platform_get_devices_str_device_type():
platforms = dpctl.get_platforms()
dtys = ["accelerator", "all", "cpu", "gpu"]
if platforms:
for p in platforms:
for dty in dtys:
devices = p.get_devices(device_type=dty)
if len(devices):
dty_enum = _str_device_type_to_enum(dty)
assert (d.device_type == dty_enum for d in devices)


def test_platform_get_devices_enum_device_type():
platforms = dpctl.get_platforms()
dtys = [
device_type.accelerator,
device_type.all,
device_type.cpu,
device_type.gpu,
]
if platforms:
for p in platforms:
for dty in dtys:
devices = p.get_devices(device_type=dty)
if len(devices):
assert (d.device_type == dty for d in devices)
3 changes: 0 additions & 3 deletions libsyclinterface/helper/source/dpctl_utils_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ info::device_type DPCTL_StrToDeviceType(const std::string &devTyStr)
else if (devTyStr == "custom") {
devTy = info::device_type::custom;
}
else if (devTyStr == "host") {
devTy = info::device_type::host;
}
else {
// \todo handle the error
throw std::runtime_error("Unknown device type.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,7 @@ INSTANTIATE_TEST_SUITE_P(FilterSelectorCreation,
"gpu:0",
"gpu:1",
"1",
"0",
"host"));
"0"));

INSTANTIATE_TEST_SUITE_P(NegativeFilterSelectorCreation,
TestUnsupportedFilters,
Expand Down