Skip to content

Commit b647cca

Browse files
Simplified arg parsing in SyclDevice constructor
Since Cython is compiled with language_level=3 working with unicode type is obsolete (we should work with str type instead). Removed the dead branch of code. Added test to exercise repr method
1 parent 16bdf5b commit b647cca

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

dpctl/_sycl_device.pyx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -253,17 +253,8 @@ cdef class SyclDevice(_SyclDevice):
253253
cdef const char *filter_c_str = NULL
254254
cdef int ret = 0
255255

256-
if type(arg) is unicode:
257-
string = bytes(<unicode>arg, "utf-8")
258-
filter_c_str = string
259-
DSRef = DPCTLFilterSelector_Create(filter_c_str)
260-
ret = self._init_from_selector(DSRef)
261-
if ret == -1:
262-
raise ValueError(
263-
"Could not create a SyclDevice with the selector string"
264-
)
265-
elif isinstance(arg, unicode):
266-
string = bytes(<unicode>unicode(arg), "utf-8")
256+
if type(arg) is str:
257+
string = bytes(<str>arg, "utf-8")
267258
filter_c_str = string
268259
DSRef = DPCTLFilterSelector_Create(filter_c_str)
269260
ret = self._init_from_selector(DSRef)

dpctl/tests/test_sycl_device.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"opencl:gpu:-1",
5252
"cuda:cpu:0",
5353
"abc",
54+
1,
5455
]
5556

5657

@@ -470,6 +471,10 @@ def check_print_device_info(device):
470471
pytest.fail("Encountered an exception inside print_device_info().")
471472

472473

474+
def check_repr(device):
475+
assert type(repr(device)) is str
476+
477+
473478
list_of_checks = [
474479
check_get_max_compute_units,
475480
check_get_max_work_item_dims,
@@ -523,6 +528,7 @@ def check_print_device_info(device):
523528
check_create_sub_devices_by_affinity_L1_cache,
524529
check_create_sub_devices_by_affinity_next_partitionable,
525530
check_print_device_info,
531+
check_repr,
526532
]
527533

528534

0 commit comments

Comments
 (0)