Skip to content

Commit 0629e08

Browse files
committed
Add dpctl.SyclPlatform tests for get_devices method
Also removes some remaining, sporadic references to the deprecated sycl::info::device_type::host
1 parent 4e54dde commit 0629e08

File tree

6 files changed

+51
-12
lines changed

6 files changed

+51
-12
lines changed

dpctl/_sycl_device_factory.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ cpdef list get_devices(backend=backend_type.all, device_type=device_type_t.all):
162162
device_type (optional):
163163
A :class:`dpctl.device_type` enum value or a string that
164164
specifies a SYCL device type. Currently, accepted values are:
165-
"gpu", "cpu", "accelerator", "host", or "all".
165+
"gpu", "cpu", "accelerator", or "all".
166166
Default: ``dpctl.device_type.all``.
167167
Returns:
168168
list:
@@ -218,7 +218,7 @@ cpdef int get_num_devices(
218218
device_type (optional):
219219
A :class:`dpctl.device_type` enum value or a string that
220220
specifies a SYCL device type. Currently, accepted values are:
221-
"gpu", "cpu", "accelerator", "host", or "all".
221+
"gpu", "cpu", "accelerator", or "all".
222222
Default: ``dpctl.device_type.all``.
223223
Returns:
224224
int:

dpctl/_sycl_platform.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ cdef class SyclPlatform(_SyclPlatform):
385385
device_type (optional):
386386
A :class:`dpctl.device_type` enum value or a string that
387387
specifies a SYCL device type. Currently, accepted values are:
388-
"gpu", "cpu", "accelerator", "host", or "all".
388+
"gpu", "cpu", "accelerator", or "all".
389389
Default: ``dpctl.device_type.all``.
390390
391391
Returns:

dpctl/tests/test_sycl_device_factory.py

-4
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ def string_to_device_type(dty_str):
5151
return dty.accelerator
5252
elif dty_str == "cpu":
5353
return dty.cpu
54-
elif dty_str == "host":
55-
return dty.host
5654
elif dty_str == "gpu":
5755
return dty.gpu
5856

@@ -62,8 +60,6 @@ def string_to_backend_type(bty_str):
6260
return bty.cuda
6361
elif bty_str == "hip":
6462
return bty.hip
65-
elif bty_str == "host":
66-
return bty.host
6763
elif bty_str == "level_zero":
6864
return bty.level_zero
6965
elif bty_str == "opencl":

dpctl/tests/test_sycl_platform.py

+47
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import pytest
2323

2424
import dpctl
25+
from dpctl import device_type
2526

2627
from .helper import has_sycl_platforms
2728

@@ -212,3 +213,49 @@ def test_get_platforms():
212213
assert has_sycl_platforms()
213214
except Exception:
214215
pytest.fail("Encountered an exception inside get_platforms().")
216+
217+
218+
def test_platform_get_devices():
219+
platforms = dpctl.get_platforms()
220+
if platforms:
221+
for p in platforms:
222+
assert len(p.get_devices())
223+
else:
224+
pytest.skip("No platforms available")
225+
226+
227+
def _str_device_type_to_enum(dty):
228+
if dty == "accelerator":
229+
return device_type.accelerator
230+
elif dty == "cpu":
231+
return device_type.cpu
232+
elif dty == "gpu":
233+
return device_type.gpu
234+
235+
236+
def test_platform_get_devices_str_device_type():
237+
platforms = dpctl.get_platforms()
238+
dtys = ["accelerator", "all", "cpu", "gpu"]
239+
if platforms:
240+
for p in platforms:
241+
for dty in dtys:
242+
devices = p.get_devices(device_type=dty)
243+
if len(devices):
244+
dty_enum = _str_device_type_to_enum(dty)
245+
assert (d.device_type == dty_enum for d in devices)
246+
247+
248+
def test_platform_get_devices_enum_device_type():
249+
platforms = dpctl.get_platforms()
250+
dtys = [
251+
device_type.accelerator,
252+
device_type.all,
253+
device_type.cpu,
254+
device_type.gpu,
255+
]
256+
if platforms:
257+
for p in platforms:
258+
for dty in dtys:
259+
devices = p.get_devices(device_type=dty)
260+
if len(devices):
261+
assert (d.device_type == dty for d in devices)

libsyclinterface/helper/source/dpctl_utils_helper.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@ info::device_type DPCTL_StrToDeviceType(const std::string &devTyStr)
7373
else if (devTyStr == "custom") {
7474
devTy = info::device_type::custom;
7575
}
76-
else if (devTyStr == "host") {
77-
devTy = info::device_type::host;
78-
}
7976
else {
8077
// \todo handle the error
8178
throw std::runtime_error("Unknown device type.");

libsyclinterface/tests/test_sycl_device_selector_interface.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,7 @@ INSTANTIATE_TEST_SUITE_P(FilterSelectorCreation,
220220
"gpu:0",
221221
"gpu:1",
222222
"1",
223-
"0",
224-
"host"));
223+
"0"));
225224

226225
INSTANTIATE_TEST_SUITE_P(NegativeFilterSelectorCreation,
227226
TestUnsupportedFilters,

0 commit comments

Comments
 (0)