MCPcopy
hub / github.com/tinygrad/tinygrad / line_rewrite

Function line_rewrite

tinygrad/codegen/__init__.py:122–130  ·  view source on GitHub ↗
(lst:list[UOp], pm:PatternMatcher, ctx=None)

Source from the content-addressed store, hash-verified

120
121# requires lst be toposorted. like graph rewrite, but for lines
122def line_rewrite(lst:list[UOp], pm:PatternMatcher, ctx=None) -> list[UOp]:
123 newlst = []
124 replaced: dict[UOp, UOp] = {}
125 for u in lst:
126 nu = u.replace(src=tuple([replaced.get(x, x) for x in u.src]))
127 ret: tuple[UOp, list[UOp]] = cast(tuple[UOp, list[UOp]]|None, pm.rewrite(nu, ctx)) or (nu, [nu])
128 replaced[u] = ret[0]
129 newlst.extend(ret[1])
130 return newlst
131
132def do_linearize(ctx:Renderer, prg:UOp, sink:UOp) -> UOp:
133 if DEBUG >= 3 and sink.arg.applied_opts: print(f"{sink.arg.function_name:<25} opts: {sink.arg.applied_opts}")

Callers 2

get_uopsFunction · 0.90
do_linearizeFunction · 0.85

Calls 4

castFunction · 0.85
replaceMethod · 0.45
getMethod · 0.45
rewriteMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…