From 88060b976f89488dfa9759f1325ca0f5c5b78eed Mon Sep 17 00:00:00 2001 From: Eric Lunderberg Date: Fri, 5 May 2023 10:34:33 -0500 Subject: [PATCH] [Runtime] Added __str__ for tvm._ffi.runtime_ctypes.TVMArray This utility was useful during debugging that resulted in the changes made in https://github.com/apache/tvm/pull/14771, but is not otherwise related to that PR. --- python/tvm/_ffi/runtime_ctypes.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/python/tvm/_ffi/runtime_ctypes.py b/python/tvm/_ffi/runtime_ctypes.py index fa12bf9ce37a..999f69bc34c0 100644 --- a/python/tvm/_ffi/runtime_ctypes.py +++ b/python/tvm/_ffi/runtime_ctypes.py @@ -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.