Skip to content

Changed repr for Memory objects #442

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

Merged
merged 1 commit into from
May 13, 2021
Merged
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
33 changes: 31 additions & 2 deletions dpctl/memory/_memory.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -232,33 +232,62 @@ cdef class _Memory:
buffer.suboffsets = NULL # for pointer arrays only

property nbytes:
""" Extent of this USM buffer in bytes. """
def __get__(self):
return self.nbytes

property size:
""" Extent of this USM buffer in bytes. """
def __get__(self):
return self.nbytes

property _pointer:
"""
USM pointer at the start of this buffer
represented in Python integer.
"""
def __get__(self):
return <size_t>(self.memory_ptr)

property _context:
""" :class:`dpctl.SyclContext` the USM pointer is bound to. """
def __get__(self):
return self.queue.get_sycl_context()

property _queue:
"""
:class:`dpctl.SyclQueue` with :class:`dpctl.SyclContext` the
USM pointer is bound to and :class:`dpctl.SyclDevice` it was
allocated on.
"""
def __get__(self):
return self.queue

property reference_obj:
"""
Reference to the Python object owning this USM buffer.
"""
def __get__(self):
return self.refobj

property sycl_context:
""" :class:`dpctl.SyclContext` the USM pointer is bound to. """
def __get__(self):
return self.queue.get_sycl_context()

property sycl_device:
""" :class:`dpctl.SyclDevice` the USM pointer is bound to. """
def __get__(self):
return self.queue.get_sycl_device()

def __repr__(self):
return (
"<Intel(R) USM allocated memory block of {} bytes at {}>"
.format(self.nbytes, hex(<object>(<size_t>self.memory_ptr)))
"<SYCL(TM) USM-{} allocated memory block of {} bytes at {}>"
.format(
self.get_usm_type(),
self.nbytes,
hex(<object>(<size_t>self.memory_ptr))
)
)

def __len__(self):
Expand Down