4
4
from urllib .parse import parse_qs , urlparse
5
5
from typing import Any , Callable , TypedDict , Generator
6
6
from tinygrad .helpers import colored , getenv , tqdm , unwrap , word_wrap
7
- from tinygrad .ops import TrackedGraphRewrite , UOp , Ops , lines , GroupOp
7
+ from tinygrad .ops import TrackedGraphRewrite , UOp , Ops , lines , GroupOp , srender , sint
8
8
from tinygrad .codegen .kernel import Kernel
9
9
from tinygrad .device import ProfileEvent , ProfileDeviceEvent , ProfileRangeEvent , ProfileGraphEvent
10
10
from tinygrad .dtype import dtypes
@@ -51,6 +51,8 @@ class GraphRewriteDetails(TypedDict):
51
51
changed_nodes : list [int ]| None # the changed UOp id + all its parents ids
52
52
upat : tuple [tuple [str , int ], str ]| None # [loc, source_code] of the matched UPat
53
53
54
+ def shape_to_str (s :tuple [sint , ...]): return "(" + ',' .join (srender (x ) for x in s ) + ")"
55
+
54
56
def uop_to_json (x :UOp ) -> dict [int , dict ]:
55
57
assert isinstance (x , UOp )
56
58
graph : dict [int , dict ] = {}
@@ -65,8 +67,8 @@ def uop_to_json(x:UOp) -> dict[int, dict]:
65
67
if u in excluded : continue
66
68
argst = str (u .arg )
67
69
if u .op is Ops .VIEW :
68
- argst = ("\n " .join ([f"{ v .shape } / { v .strides } " + (f"\n MASK { v .mask } " if v .mask is not None else "" )+
69
- ("" if v .offset == 0 else f" / { v .offset } " ) for v in unwrap (u .st ).views ]))
70
+ argst = ("\n " .join ([f"{ shape_to_str ( v .shape ) } / { shape_to_str ( v .strides ) } " + (f"\n MASK { v .mask } " if v .mask is not None else "" )+
71
+ ("" if v .offset == 0 else f" / { srender ( v .offset ) } " ) for v in unwrap (u .st ).views ]))
70
72
label = f"{ str (u .op ).split ('.' )[1 ]} { (chr (10 )+ word_wrap (argst .replace (':' , '' ))) if u .arg is not None else '' } "
71
73
if u .dtype != dtypes .void : label += f"\n { u .dtype } "
72
74
for idx ,x in enumerate (u .src ):
@@ -75,7 +77,7 @@ def uop_to_json(x:UOp) -> dict[int, dict]:
75
77
else : label += f"\n { x .op .name } { idx } { x .arg } "
76
78
try :
77
79
if u .op not in {Ops .VIEW , Ops .BUFFER , Ops .KERNEL , Ops .ASSIGN , Ops .COPY , Ops .SINK , * GroupOp .Buffer } and u .st is not None :
78
- label += f"\n { repr (u .shape )} "
80
+ label += f"\n { shape_to_str (u .shape )} "
79
81
except Exception :
80
82
label += "\n <ISSUE GETTING SHAPE>"
81
83
graph [id (u )] = {"label" :label , "src" :[id (x ) for x in u .src if x not in excluded ], "color" :uops_colors .get (u .op , "#ffffff" )}
0 commit comments