Skip to content

Commit 6c60acd

Browse files
Merge pull request #429 from IntelPython/test-filter-string-property
Added two tests for filter_string property
2 parents 5a60bd0 + 08a0cb4 commit 6c60acd

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

dpctl-capi/helper/source/dpctl_utils_helper.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,13 +433,15 @@ int64_t DPCTL_GetRelativeDeviceId(const device &Device)
433433
{
434434
auto relid = -1;
435435
auto p = Device.get_platform();
436+
auto be = p.get_backend();
436437
auto dt = Device.get_info<sycl::info::device::device_type>();
437-
auto dev_vec = p.get_devices(dt);
438+
auto dev_vec = device::get_devices(dt);
438439
int64_t id = 0;
439440
for (const auto &d_i : dev_vec) {
440441
if (Device == d_i)
441442
relid = id;
442-
++id;
443+
if (d_i.get_platform().get_backend() == be)
444+
++id;
443445
}
444446
return relid;
445447
}

dpctl/tests/test_sycl_device.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,3 +572,32 @@ def test_invalid_filter_selectors(invalid_filter):
572572
"""
573573
with pytest.raises(ValueError):
574574
dpctl.SyclDevice(invalid_filter)
575+
576+
577+
def test_filter_string(valid_filter):
578+
"""
579+
Test that filter_string reconstructs the same device.
580+
"""
581+
device = None
582+
try:
583+
device = dpctl.SyclDevice(valid_filter)
584+
except ValueError:
585+
pytest.skip("Failed to create device with supported filter")
586+
dev_id = device.filter_string
587+
assert (
588+
dpctl.SyclDevice(dev_id) == device
589+
), "Reconstructed device is different, ({}, {})".format(
590+
valid_filter, dev_id
591+
)
592+
593+
594+
def test_filter_string2():
595+
"""
596+
Test that filter_string reconstructs the same device.
597+
"""
598+
devices = dpctl.get_devices()
599+
for d in devices:
600+
if d.default_selector_score > 0:
601+
dev_id = d.filter_string
602+
d_r = dpctl.SyclDevice(dev_id)
603+
assert d == d_r

0 commit comments

Comments
 (0)