Skip to content

Synchronization functions and USM allocations functions release GIL #736

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions dpctl/_backend.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ cdef extern from "syclinterface/dpctl_sycl_device_selector_interface.h":
cdef extern from "syclinterface/dpctl_sycl_event_interface.h":
cdef DPCTLSyclEventRef DPCTLEvent_Create()
cdef DPCTLSyclEventRef DPCTLEvent_Copy(const DPCTLSyclEventRef ERef)
cdef void DPCTLEvent_Wait(DPCTLSyclEventRef ERef)
cdef void DPCTLEvent_WaitAndThrow(DPCTLSyclEventRef ERef)
cdef void DPCTLEvent_Wait(DPCTLSyclEventRef ERef) nogil
cdef void DPCTLEvent_WaitAndThrow(DPCTLSyclEventRef ERef) nogil
cdef void DPCTLEvent_Delete(DPCTLSyclEventRef ERef)
cdef _event_status_type DPCTLEvent_GetCommandExecutionStatus(DPCTLSyclEventRef ERef)
cdef _backend_type DPCTLEvent_GetBackend(DPCTLSyclEventRef ERef)
Expand Down Expand Up @@ -356,7 +356,7 @@ cdef extern from "syclinterface/dpctl_sycl_queue_interface.h":
size_t NDims,
const DPCTLSyclEventRef *DepEvents,
size_t NDepEvents)
cdef void DPCTLQueue_Wait(const DPCTLSyclQueueRef QRef)
cdef void DPCTLQueue_Wait(const DPCTLSyclQueueRef QRef) nogil
cdef DPCTLSyclEventRef DPCTLQueue_Memcpy(
const DPCTLSyclQueueRef Q,
void *Dest,
Expand Down Expand Up @@ -394,23 +394,25 @@ cdef extern from "syclinterface/dpctl_sycl_queue_manager.h":
cdef extern from "syclinterface/dpctl_sycl_usm_interface.h":
cdef DPCTLSyclUSMRef DPCTLmalloc_shared(
size_t size,
DPCTLSyclQueueRef QRef)
DPCTLSyclQueueRef QRef) nogil
cdef DPCTLSyclUSMRef DPCTLmalloc_host(
size_t size,
DPCTLSyclQueueRef QRef)
cdef DPCTLSyclUSMRef DPCTLmalloc_device(size_t size, DPCTLSyclQueueRef QRef)
DPCTLSyclQueueRef QRef) nogil
cdef DPCTLSyclUSMRef DPCTLmalloc_device(
size_t size,
DPCTLSyclQueueRef QRef) nogil
cdef DPCTLSyclUSMRef DPCTLaligned_alloc_shared(
size_t alignment,
size_t size,
DPCTLSyclQueueRef QRef)
DPCTLSyclQueueRef QRef) nogil
cdef DPCTLSyclUSMRef DPCTLaligned_alloc_host(
size_t alignment,
size_t size,
DPCTLSyclQueueRef QRef)
DPCTLSyclQueueRef QRef) nogil
cdef DPCTLSyclUSMRef DPCTLaligned_alloc_device(
size_t alignment,
size_t size,
DPCTLSyclQueueRef QRef)
DPCTLSyclQueueRef QRef) nogil
cdef void DPCTLfree_with_queue(
DPCTLSyclUSMRef MRef,
DPCTLSyclQueueRef QRef)
Expand Down
6 changes: 3 additions & 3 deletions dpctl/_sycl_event.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ cdef class _SyclEvent:

def __dealloc__(self):
if (self._event_ref):
DPCTLEvent_Wait(self._event_ref)
with nogil: DPCTLEvent_Wait(self._event_ref)
DPCTLEvent_Delete(self._event_ref)
self._event_ref = NULL
self.args = None
Expand Down Expand Up @@ -224,7 +224,7 @@ cdef class SyclEvent(_SyclEvent):

@staticmethod
cdef void _wait(SyclEvent event):
DPCTLEvent_WaitAndThrow(event._event_ref)
with nogil: DPCTLEvent_WaitAndThrow(event._event_ref)

@staticmethod
def wait_for(event):
Expand Down Expand Up @@ -370,4 +370,4 @@ cdef class SyclEvent(_SyclEvent):

cpdef void wait(self):
"Synchronously wait for completion of this event."
DPCTLEvent_Wait(self._event_ref)
with nogil: DPCTLEvent_Wait(self._event_ref)
8 changes: 4 additions & 4 deletions dpctl/_sycl_queue.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ cdef class SyclQueue(_SyclQueue):
return SyclEvent._create(Eref, args)

cpdef void wait(self):
DPCTLQueue_Wait(self._queue_ref)
with nogil: DPCTLQueue_Wait(self._queue_ref)

cpdef memcpy(self, dest, src, size_t count):
cdef void *c_dest
Expand All @@ -846,7 +846,7 @@ cdef class SyclQueue(_SyclQueue):
raise RuntimeError(
"SyclQueue.memcpy operation encountered an error"
)
DPCTLEvent_Wait(ERef)
with nogil: DPCTLEvent_Wait(ERef)
DPCTLEvent_Delete(ERef)

cpdef prefetch(self, mem, size_t count=0):
Expand All @@ -866,7 +866,7 @@ cdef class SyclQueue(_SyclQueue):
raise RuntimeError(
"SyclQueue.prefetch encountered an error"
)
DPCTLEvent_Wait(ERef)
with nogil: DPCTLEvent_Wait(ERef)
DPCTLEvent_Delete(ERef)

cpdef mem_advise(self, mem, size_t count, int advice):
Expand All @@ -886,7 +886,7 @@ cdef class SyclQueue(_SyclQueue):
raise RuntimeError(
"SyclQueue.mem_advise operation encountered an error"
)
DPCTLEvent_Wait(ERef)
with nogil: DPCTLEvent_Wait(ERef)
DPCTLEvent_Delete(ERef)

@property
Expand Down
30 changes: 16 additions & 14 deletions dpctl/memory/_memory.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ cdef void copy_via_host(void *dest_ptr, SyclQueue dest_queue,
src_ptr,
nbytes
)
DPCTLEvent_Wait(E1Ref)
with nogil: DPCTLEvent_Wait(E1Ref)

E2Ref = DPCTLQueue_Memcpy(
dest_queue.get_queue_ref(),
dest_ptr,
<void *>&host_buf[0],
nbytes
)
DPCTLEvent_Wait(E2Ref)
with nogil: DPCTLEvent_Wait(E2Ref)
DPCTLEvent_Delete(E1Ref)
DPCTLEvent_Delete(E2Ref)

Expand Down Expand Up @@ -142,34 +142,36 @@ cdef class _Memory:
cdef _cinit_alloc(self, Py_ssize_t alignment, Py_ssize_t nbytes,
bytes ptr_type, SyclQueue queue):
cdef DPCTLSyclUSMRef p = NULL
cdef DPCTLSyclQueueRef QRef = NULL

self._cinit_empty()

if (nbytes > 0):
if queue is None:
queue = dpctl.SyclQueue()

QRef = queue.get_queue_ref()
if (ptr_type == b"shared"):
if alignment > 0:
p = DPCTLaligned_alloc_shared(
alignment, nbytes, queue.get_queue_ref()
with nogil: p = DPCTLaligned_alloc_shared(
alignment, nbytes, QRef
)
else:
p = DPCTLmalloc_shared(nbytes, queue.get_queue_ref())
with nogil: p = DPCTLmalloc_shared(nbytes, QRef)
elif (ptr_type == b"host"):
if alignment > 0:
p = DPCTLaligned_alloc_host(
alignment, nbytes, queue.get_queue_ref()
with nogil: p = DPCTLaligned_alloc_host(
alignment, nbytes, QRef
)
else:
p = DPCTLmalloc_host(nbytes, queue.get_queue_ref())
with nogil: p = DPCTLmalloc_host(nbytes, QRef)
elif (ptr_type == b"device"):
if (alignment > 0):
p = DPCTLaligned_alloc_device(
alignment, nbytes, queue.get_queue_ref()
with nogil: p = DPCTLaligned_alloc_device(
alignment, nbytes, QRef
)
else:
p = DPCTLmalloc_device(nbytes, queue.get_queue_ref())
with nogil: p = DPCTLmalloc_device(nbytes, QRef)
else:
raise RuntimeError(
"Pointer type is unknown: {}".format(
Expand Down Expand Up @@ -398,7 +400,7 @@ cdef class _Memory:
<void *>self.memory_ptr, # source
<size_t>self.nbytes
)
DPCTLEvent_Wait(ERef)
with nogil: DPCTLEvent_Wait(ERef)
DPCTLEvent_Delete(ERef)

return obj
Expand All @@ -423,7 +425,7 @@ cdef class _Memory:
<void *>&host_buf[0], # source
<size_t>buf_len
)
DPCTLEvent_Wait(ERef)
with nogil: DPCTLEvent_Wait(ERef)
DPCTLEvent_Delete(ERef)

cpdef copy_from_device(self, object sycl_usm_ary):
Expand Down Expand Up @@ -465,7 +467,7 @@ cdef class _Memory:
<void *>src_buf.p,
<size_t>src_buf.nbytes
)
DPCTLEvent_Wait(ERef)
with nogil: DPCTLEvent_Wait(ERef)
DPCTLEvent_Delete(ERef)
else:
copy_via_host(
Expand Down