Skip to content

Commit

Permalink
USM alloc. fns declared nogil, used inside with nogil context
Browse files Browse the repository at this point in the history
Large USM allocations can be constly, so releasing GIL while
invoking them may be a good idea.
  • Loading branch information
oleksandr-pavlyk committed Jan 5, 2022
1 parent cd27728 commit 0ae7844
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
14 changes: 8 additions & 6 deletions dpctl/_backend.pxd
Original file line number Diff line number Diff line change
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
20 changes: 11 additions & 9 deletions dpctl/memory/_memory.pyx
Original file line number Diff line number Diff line change
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

0 comments on commit 0ae7844

Please sign in to comment.