From 0ae7844fea8991b3175a655e876cad814cb434c0 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Wed, 5 Jan 2022 12:50:42 -0600 Subject: [PATCH] USM alloc. fns declared nogil, used inside `with nogil` context Large USM allocations can be constly, so releasing GIL while invoking them may be a good idea. --- dpctl/_backend.pxd | 14 ++++++++------ dpctl/memory/_memory.pyx | 20 +++++++++++--------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/dpctl/_backend.pxd b/dpctl/_backend.pxd index 0ba086db79..b4788ab493 100644 --- a/dpctl/_backend.pxd +++ b/dpctl/_backend.pxd @@ -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) diff --git a/dpctl/memory/_memory.pyx b/dpctl/memory/_memory.pyx index 76d6255df3..741d72e22d 100644 --- a/dpctl/memory/_memory.pyx +++ b/dpctl/memory/_memory.pyx @@ -142,6 +142,7 @@ 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() @@ -149,27 +150,28 @@ cdef class _Memory: 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(