Skip to content

Commit ce554ac

Browse files
Special case of zero-copy from another Memory object
1. In that case we can avoid making change of reference objects very long. ``` In [1]: import dpctl, dpctl.memory as dpmem In [2]: m = dpmem.MemoryUSMShared(256) In [3]: m2 = dpmem.MemoryUSMShared(m) In [4]: m3 = dpmem.MemoryUSMShared(m2) In [5]: m3.reference_obj is m Out[5]: True In [6]: m2.reference_obj is m Out[6]: True In [7]: m2._pointer Out[7]: 94798596370432 In [8]: m3._pointer Out[8]: 94798596370432 In [9]: m._pointer Out[9]: 94798596370432 ```
1 parent 9dbe493 commit ce554ac

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

dpctl/_memory.pyx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,17 @@ cdef class Memory:
204204
raise ValueError("Non-positive number of bytes found.")
205205

206206
cdef _cinit_other(self, object other):
207-
if hasattr(other, '__sycl_usm_array_interface__'):
207+
cdef Memory other_mem
208+
if isinstance(other, Memory):
209+
other_mem = <Memory> other
210+
self.memory_ptr = other_mem.memory_ptr
211+
self.nbytes = other_mem.nbytes
212+
self.queue = other_mem.queue
213+
if other_mem.refobj is None:
214+
self.refobj = other
215+
else:
216+
self.refobj = other_mem.refobj
217+
elif hasattr(other, '__sycl_usm_array_interface__'):
208218
other_iface = other.__sycl_usm_array_interface__
209219
if isinstance(other_iface, dict):
210220
other_buf = _BufferData.from_sycl_usm_ary_iface(other_iface)

0 commit comments

Comments
 (0)