Skip to content

Commit 2f6a01c

Browse files
implemented cdef Memory.get_pointer_device
1 parent cebc064 commit 2f6a01c

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

dpctl/_memory.pxd

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# cython: language_level=3
2323

2424
from ._backend cimport DPPLSyclUSMRef
25-
from ._sycl_core cimport SyclQueue
25+
from ._sycl_core cimport SyclQueue, SyclDevice, SyclContext
2626

2727

2828
cdef class Memory:
@@ -43,6 +43,9 @@ cdef class Memory:
4343

4444
cpdef bytes tobytes(self)
4545

46+
@staticmethod
47+
cdef SyclDevice get_pointer_device(DPPLSyclUSMRef p, SyclContext ctx)
48+
4649

4750
cdef class MemoryUSMShared(Memory):
4851
pass

dpctl/_memory.pyx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
import dpctl
3232
from dpctl._backend cimport *
33-
from ._sycl_core cimport SyclContext, SyclQueue
33+
from ._sycl_core cimport SyclContext, SyclQueue, SyclDevice
3434
from ._sycl_core cimport get_current_queue
3535

3636
from cpython cimport Py_buffer
@@ -93,6 +93,7 @@ cdef class _BufferData:
9393
cdef object dt
9494
cdef _BufferData buf
9595
cdef Py_ssize_t arr_data_ptr
96+
cdef SyclDevice dev
9697

9798
if ary_version != 1:
9899
_throw_sycl_usm_ary_iface()
@@ -124,9 +125,10 @@ cdef class _BufferData:
124125
# FIXME: need a way to construct a queue from
125126
# context and device, which can be obtaine from the
126127
# pointer and the context.
127-
# cdef SyclDevice dev = DPPLget_pointer_device(arr_data_ptr, <SyclContext> ary_syclobj)
128+
#
128129
# cdef SyclQueue new_queue = SyclQueue._create_from_dev_context(dev, <SyclContext> ary_syclobj)
129130
# buf.queue = new_queue
131+
dev = Memory.get_pointer_device(buf.p, <SyclContext> ary_syclobj)
130132
buf.queue = get_current_queue()
131133

132134
return buf
@@ -314,7 +316,7 @@ cdef class Memory:
314316
ctx.get_context_ref())
315317
else:
316318
raise ValueError("syclobj keyword can be either None, "
317-
"or an instance of SyclConext or SyclQueue")
319+
"or an instance of SyclContext or SyclQueue")
318320
return kind.decode('UTF-8')
319321

320322
cpdef copy_to_host (self, obj=None):
@@ -402,6 +404,12 @@ cdef class Memory:
402404
self.copy_to_host(mv) # output is discarded
403405
return b
404406

407+
@staticmethod
408+
cdef SyclDevice get_pointer_device(DPPLSyclUSMRef p, SyclContext ctx):
409+
cdef DPPLSyclDeviceRef dref = DPPLUSM_GetPointerDevice(p, ctx.get_context_ref())
410+
411+
return SyclDevice._create(dref)
412+
405413

406414
cdef class MemoryUSMShared(Memory):
407415
"""

0 commit comments

Comments
 (0)