Skip to content

Commit 85b3a8e

Browse files
Since DPCTLDeviceVector_CreateFromArray makes copies of devices
references by opaque pointers in the given array, making these copies is removed from Cython.
1 parent a934b01 commit 85b3a8e

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

dpctl/_sycl_context.pyx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ cdef class SyclContext(_SyclContext):
8888
cdef int _init_from_one_device(self, SyclDevice device, int props):
8989
cdef DPCTLSyclDeviceRef DRef = device.get_device_ref()
9090
cdef DPCTLSyclContextRef CRef = NULL
91-
cdef error_handler_callback * eh_callback = \
92-
<error_handler_callback *>&default_async_error_handler
91+
cdef error_handler_callback * eh_callback = <error_handler_callback *>&default_async_error_handler
9392
# look up cached contexts for root devices first
9493
CRef = DPCTLDeviceMgr_GetCachedContext(DRef)
9594
if (CRef is NULL):
@@ -103,11 +102,10 @@ cdef class SyclContext(_SyclContext):
103102
cdef int _init_from_devices(self, object devices, int props):
104103
cdef int num_devices = len(devices)
105104
cdef int i = 0
106-
cdef int j
105+
cdef int j = 0
107106
cdef size_t num_bytes
108107
cdef DPCTLDeviceVectorRef DVRef = NULL
109-
cdef error_handler_callback * eh_callback = \
110-
<error_handler_callback *>&default_async_error_handler
108+
cdef error_handler_callback * eh_callback = <error_handler_callback *>&default_async_error_handler
111109
cdef DPCTLSyclContextRef CRef = NULL
112110
cdef DPCTLSyclDeviceRef *elems
113111

@@ -120,17 +118,14 @@ cdef class SyclContext(_SyclContext):
120118
if not isinstance(dev, SyclDevice):
121119
elems[i] = NULL
122120
else:
123-
elems[i] = DPCTLDevice_Copy((<SyclDevice>dev).get_device_ref())
121+
elems[i] = (<SyclDevice>dev).get_device_ref()
124122
if (elems[i] is NULL):
125-
for j in range(0, i):
126-
DPCTLDevice_Delete(elems[j])
127123
PyMem_Free(elems)
128124
return -4
129125
i = i + 1
126+
# CreateFromArray will make copies of devices referenced by elems
130127
DVRef = DPCTLDeviceVector_CreateFromArray(num_devices, elems)
131128
if (DVRef is NULL):
132-
for j in range(num_devices):
133-
DPCTLDevice_Delete(elems[j])
134129
PyMem_Free(elems)
135130
return -5
136131
PyMem_Free(elems)

0 commit comments

Comments
 (0)