| 97 | |
| 98 | |
| 99 | def 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 | |
| 128 | class LogicalTensorDescPrinter: |