Skip to content

Commit

Permalink
[Runtime] Added __str__ for tvm._ffi.runtime_ctypes.TVMArray (#14775)
Browse files Browse the repository at this point in the history
This utility was useful during debugging that resulted in the changes
made in #14771, but is not
otherwise related to that PR.
  • Loading branch information
Lunderberg authored May 6, 2023
1 parent 6c53d85 commit ca7c3d1
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions python/tvm/_ffi/runtime_ctypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,19 @@ class TVMArray(ctypes.Structure):
("byte_offset", ctypes.c_uint64),
]

def __str__(self):
shape = [self.shape[i] for i in range(self.ndim)]
if self.strides:
strides = [self.strides[i] for i in range(self.ndim)]
else:
strides = []

return (
f"TVMArray(data=0x{self.data:016x}, device={self.device}, "
f"dtype={self.dtype}, shape={shape}, "
f"strides={strides}, byte_offset={self.byte_offset})"
)


class ObjectRValueRef:
"""Represent an RValue ref to an object that can be moved.
Expand Down

0 comments on commit ca7c3d1

Please sign in to comment.