Skip to content

Commit 0ae7844

Browse files
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.
1 parent cd27728 commit 0ae7844

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

dpctl/_backend.pxd

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -394,23 +394,25 @@ cdef extern from "syclinterface/dpctl_sycl_queue_manager.h":
394394
cdef extern from "syclinterface/dpctl_sycl_usm_interface.h":
395395
cdef DPCTLSyclUSMRef DPCTLmalloc_shared(
396396
size_t size,
397-
DPCTLSyclQueueRef QRef)
397+
DPCTLSyclQueueRef QRef) nogil
398398
cdef DPCTLSyclUSMRef DPCTLmalloc_host(
399399
size_t size,
400-
DPCTLSyclQueueRef QRef)
401-
cdef DPCTLSyclUSMRef DPCTLmalloc_device(size_t size, DPCTLSyclQueueRef QRef)
400+
DPCTLSyclQueueRef QRef) nogil
401+
cdef DPCTLSyclUSMRef DPCTLmalloc_device(
402+
size_t size,
403+
DPCTLSyclQueueRef QRef) nogil
402404
cdef DPCTLSyclUSMRef DPCTLaligned_alloc_shared(
403405
size_t alignment,
404406
size_t size,
405-
DPCTLSyclQueueRef QRef)
407+
DPCTLSyclQueueRef QRef) nogil
406408
cdef DPCTLSyclUSMRef DPCTLaligned_alloc_host(
407409
size_t alignment,
408410
size_t size,
409-
DPCTLSyclQueueRef QRef)
411+
DPCTLSyclQueueRef QRef) nogil
410412
cdef DPCTLSyclUSMRef DPCTLaligned_alloc_device(
411413
size_t alignment,
412414
size_t size,
413-
DPCTLSyclQueueRef QRef)
415+
DPCTLSyclQueueRef QRef) nogil
414416
cdef void DPCTLfree_with_queue(
415417
DPCTLSyclUSMRef MRef,
416418
DPCTLSyclQueueRef QRef)

dpctl/memory/_memory.pyx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,34 +142,36 @@ cdef class _Memory:
142142
cdef _cinit_alloc(self, Py_ssize_t alignment, Py_ssize_t nbytes,
143143
bytes ptr_type, SyclQueue queue):
144144
cdef DPCTLSyclUSMRef p = NULL
145+
cdef DPCTLSyclQueueRef QRef = NULL
145146

146147
self._cinit_empty()
147148

148149
if (nbytes > 0):
149150
if queue is None:
150151
queue = dpctl.SyclQueue()
151152

153+
QRef = queue.get_queue_ref()
152154
if (ptr_type == b"shared"):
153155
if alignment > 0:
154-
p = DPCTLaligned_alloc_shared(
155-
alignment, nbytes, queue.get_queue_ref()
156+
with nogil: p = DPCTLaligned_alloc_shared(
157+
alignment, nbytes, QRef
156158
)
157159
else:
158-
p = DPCTLmalloc_shared(nbytes, queue.get_queue_ref())
160+
with nogil: p = DPCTLmalloc_shared(nbytes, QRef)
159161
elif (ptr_type == b"host"):
160162
if alignment > 0:
161-
p = DPCTLaligned_alloc_host(
162-
alignment, nbytes, queue.get_queue_ref()
163+
with nogil: p = DPCTLaligned_alloc_host(
164+
alignment, nbytes, QRef
163165
)
164166
else:
165-
p = DPCTLmalloc_host(nbytes, queue.get_queue_ref())
167+
with nogil: p = DPCTLmalloc_host(nbytes, QRef)
166168
elif (ptr_type == b"device"):
167169
if (alignment > 0):
168-
p = DPCTLaligned_alloc_device(
169-
alignment, nbytes, queue.get_queue_ref()
170+
with nogil: p = DPCTLaligned_alloc_device(
171+
alignment, nbytes, QRef
170172
)
171173
else:
172-
p = DPCTLmalloc_device(nbytes, queue.get_queue_ref())
174+
with nogil: p = DPCTLmalloc_device(nbytes, QRef)
173175
else:
174176
raise RuntimeError(
175177
"Pointer type is unknown: {}".format(

0 commit comments

Comments
 (0)