Skip to content
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

Fix issue 189 #392

Merged
merged 1 commit into from
Apr 20, 2021
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
18 changes: 11 additions & 7 deletions dpctl/memory/_memory.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ from cpython.bytes cimport PyBytes_AS_STRING, PyBytes_FromStringAndSize
from cpython cimport pycapsule

import numpy as np
oleksandr-pavlyk marked this conversation as resolved.
Show resolved Hide resolved
import numbers

__all__ = [
"MemoryUSMShared",
Expand All @@ -51,21 +52,21 @@ cdef DPCTLSyclQueueRef _queue_ref_copy_from_SyclQueue(SyclQueue q):

cdef DPCTLSyclQueueRef _queue_ref_copy_from_USMRef_and_SyclContext(
DPCTLSyclUSMRef ptr, SyclContext ctx):
""" Obtain device from pointer and sycl context, use
""" Obtain device from pointer and sycl context, use
context and device to create a queue from which this memory
can be accessible.
"""
cdef SyclDevice dev = _Memory.get_pointer_device(ptr, ctx)
cdef DPCTLSyclContextRef CRef = NULL
cdef DPCTLSyclDeviceRef DRef = NULL
cdef DPCTLSyclDeviceRef DRef = NULL
CRef = ctx.get_context_ref()
DRef = dev.get_device_ref()
return DPCTLQueue_Create(CRef, DRef, NULL, 0)


cdef DPCTLSyclQueueRef get_queue_ref_from_ptr_and_syclobj(
DPCTLSyclUSMRef ptr, object syclobj):
""" Constructs queue from pointer and syclobject from
""" Constructs queue from pointer and syclobject from
__sycl_usm_array_interface__
"""
cdef DPCTLSyclQueueRef QRef = NULL
Expand Down Expand Up @@ -96,7 +97,7 @@ cdef DPCTLSyclQueueRef get_queue_ref_from_ptr_and_syclobj(
return QRef
else:
return QRef


cdef void copy_via_host(void *dest_ptr, SyclQueue dest_queue,
void *src_ptr, SyclQueue src_queue, size_t nbytes):
Expand Down Expand Up @@ -207,6 +208,9 @@ def _to_memory(unsigned char [::1] b, str usm_kind):


cdef class _Memory:
""" Internal class implementing methods common to
MemoryUSMShared, MemoryUSMDevice, MemoryUSMHost
"""
cdef _cinit_empty(self):
self.memory_ptr = NULL
self.nbytes = 0
Expand Down Expand Up @@ -500,7 +504,7 @@ cdef class MemoryUSMShared(_Memory):
than 'shared'.
"""
def __cinit__(self, other, *, Py_ssize_t alignment=0, SyclQueue queue=None, int copy=False):
if (isinstance(other, int)):
if (isinstance(other, numbers.Integral)):
self._cinit_alloc(alignment, <Py_ssize_t>other, b"shared", queue)
else:
self._cinit_other(other)
Expand Down Expand Up @@ -532,7 +536,7 @@ cdef class MemoryUSMHost(_Memory):
than 'host'.
"""
def __cinit__(self, other, *, Py_ssize_t alignment=0, SyclQueue queue=None, int copy=False):
if (isinstance(other, int)):
if (isinstance(other, numbers.Integral)):
self._cinit_alloc(alignment, <Py_ssize_t>other, b"host", queue)
else:
self._cinit_other(other)
Expand Down Expand Up @@ -564,7 +568,7 @@ cdef class MemoryUSMDevice(_Memory):
than 'device'.
"""
def __cinit__(self, other, *, Py_ssize_t alignment=0, SyclQueue queue=None, int copy=False):
if (isinstance(other, int)):
if (isinstance(other, numbers.Integral)):
self._cinit_alloc(alignment, <Py_ssize_t>other, b"device", queue)
else:
self._cinit_other(other)
Expand Down
5 changes: 3 additions & 2 deletions dpctl/tests/test_sycl_usm.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ def test_memory_create(self):
self.assertEqual(mobj.nbytes, nbytes)
self.assertTrue(hasattr(mobj, "__sycl_usm_array_interface__"))

@unittest.expectedFailure
@unittest.skipUnless(
has_sycl_platforms(), "No SYCL devices except the default host device."
)
def test_memory_create_with_np(self):
mobj = dpctl.memory.MemoryUSMShared(np.int64(16384))
nbytes = 16384
mobj = dpctl.memory.MemoryUSMShared(np.int64(nbytes))
self.assertEqual(mobj.nbytes, nbytes)
self.assertTrue(hasattr(mobj, "__sycl_usm_array_interface__"))

def _create_memory(self):
Expand Down