MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / print_small_tensor

Function print_small_tensor

scripts/gdb/pretty_printers.py:99–125  ·  view source on GitHub ↗
(device_nd)

Source from the content-addressed store, hash-verified

97
98
99def print_small_tensor(device_nd):
100 size = device_nd["m_storage"]["m_size"]
101 ndim = device_nd["m_layout"]["ndim"]
102 dim0 = device_nd["m_layout"]["shape"][0]
103 stride0 = device_nd["m_layout"]["stride"][0]
104 dtype = device_nd["m_layout"]["dtype"]
105 if size == 0:
106 return "<empty>"
107 if ndim > 1:
108 return "<ndim > 1>"
109 if dim0 > 64:
110 return "<size tool large>"
111 raw_ptr = device_nd["m_storage"]["m_data"]["_M_ptr"]
112 dtype_name = dtype["m_trait"]["name"].string()
113 dtype_map = {
114 "Float32": (gdb.lookup_type("float"), float),
115 "Int32": (gdb.lookup_type("int"), int),
116 }
117 if dtype_name not in dtype_map:
118 return "<dtype unsupported>"
119 else:
120 ctype, pytype = dtype_map[dtype_name]
121 ptr = raw_ptr.cast(ctype.pointer())
122 array = []
123 for i in range(dim0):
124 array.append((pytype)((ptr + i * int(stride0)).dereference()))
125 return str(array)
126
127
128class LogicalTensorDescPrinter:

Callers 1

childrenMethod · 0.85

Calls 3

strFunction · 0.85
castMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected