Skip to content

Commit f5846cf

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 fdfbe1b commit f5846cf

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

dpctl/_sycl_context.pyx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ 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 = (
92+
<error_handler_callback *>&default_async_error_handler)
9393
# look up cached contexts for root devices first
9494
CRef = DPCTLDeviceMgr_GetCachedContext(DRef)
9595
if (CRef is NULL):
@@ -103,11 +103,11 @@ cdef class SyclContext(_SyclContext):
103103
cdef int _init_from_devices(self, object devices, int props):
104104
cdef int num_devices = len(devices)
105105
cdef int i = 0
106-
cdef int j
106+
cdef int j = 0
107107
cdef size_t num_bytes
108108
cdef DPCTLDeviceVectorRef DVRef = NULL
109-
cdef error_handler_callback * eh_callback = \
110-
<error_handler_callback *>&default_async_error_handler
109+
cdef error_handler_callback * eh_callback = (
110+
<error_handler_callback *>&default_async_error_handler)
111111
cdef DPCTLSyclContextRef CRef = NULL
112112
cdef DPCTLSyclDeviceRef *elems
113113

@@ -120,17 +120,14 @@ cdef class SyclContext(_SyclContext):
120120
if not isinstance(dev, SyclDevice):
121121
elems[i] = NULL
122122
else:
123-
elems[i] = DPCTLDevice_Copy((<SyclDevice>dev).get_device_ref())
123+
elems[i] = (<SyclDevice>dev).get_device_ref()
124124
if (elems[i] is NULL):
125-
for j in range(0, i):
126-
DPCTLDevice_Delete(elems[j])
127125
PyMem_Free(elems)
128126
return -4
129127
i = i + 1
128+
# CreateFromArray will make copies of devices referenced by elems
130129
DVRef = DPCTLDeviceVector_CreateFromArray(num_devices, elems)
131130
if (DVRef is NULL):
132-
for j in range(num_devices):
133-
DPCTLDevice_Delete(elems[j])
134131
PyMem_Free(elems)
135132
return -5
136133
PyMem_Free(elems)

0 commit comments

Comments
 (0)