Skip to content

Commit 6f12497

Browse files
oleksandr-pavlykDiptorup Deb
authored and
Diptorup Deb
committed
SyclDevice performs validation when copying from _SyclDevice
1 parent 027555b commit 6f12497

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

dpctl/_sycl_device.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ cdef class SyclDevice(_SyclDevice):
5151
cdef SyclDevice _create(DPCTLSyclDeviceRef dref)
5252
@staticmethod
5353
cdef void _init_helper(SyclDevice device, DPCTLSyclDeviceRef DRef)
54-
cdef void _init_from__SyclDevice(self, _SyclDevice other)
54+
cdef int _init_from__SyclDevice(self, _SyclDevice other)
5555
cdef int _init_from_selector(self, DPCTLSyclDeviceSelectorRef DSRef)
5656
cdef DPCTLSyclDeviceRef get_device_ref(self)
5757
cpdef get_backend(self)

dpctl/_sycl_device.pyx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,10 @@ cdef class SyclDevice(_SyclDevice):
138138
SyclDevice._init_helper(ret, dref)
139139
return SyclDevice(ret)
140140

141-
cdef void _init_from__SyclDevice(self, _SyclDevice other):
141+
cdef int _init_from__SyclDevice(self, _SyclDevice other):
142142
self._device_ref = DPCTLDevice_Copy(other._device_ref)
143+
if (self._device_ref is NULL):
144+
return -1
143145
self._device_name = DPCTLDevice_GetName(self._device_ref)
144146
self._driver_version = DPCTLDevice_GetDriverInfo(self._device_ref)
145147
self._max_compute_units = other._max_compute_units
@@ -183,15 +185,20 @@ cdef class SyclDevice(_SyclDevice):
183185
string = bytes(<unicode>unicode(arg), "utf-8")
184186
filter_c_str = string
185187
DSRef = DPCTLFilterSelector_Create(filter_c_str)
188+
ret = self._init_from_selector(DSRef)
186189
if ret == -1:
187190
raise ValueError("Could not create a Device with the selector")
188191
# Free up the device selector
189192
DPCTLDeviceSelector_Delete(DSRef)
190193
elif isinstance(arg, _SyclDevice):
191-
self._init_from__SyclDevice(arg)
194+
ret = self._init_from__SyclDevice(arg)
195+
if ret == -1:
196+
raise ValueError("Could not create a Device from _SyclDevice instance")
192197
elif arg is None:
193198
DSRef = DPCTLDefaultSelector_Create()
194-
self._init_from_selector(DSRef)
199+
ret = self._init_from_selector(DSRef)
200+
if ret == -1:
201+
raise ValueError("Could not create a Device from default selector")
195202
else:
196203
raise ValueError(
197204
"Invalid argument. Argument should be a str object specifying "

0 commit comments

Comments
 (0)