MCPcopy
hub / github.com/tinygrad/tinygrad / name_of

Function name_of

extra/export_model.py:24–35  ·  view source on GitHub ↗
(bu:UOp, is_out:bool)

Source from the content-addressed store, hash-verified

22 functions, bufs, bufs_to_save, statements, n = {}, {}, {}, [], 0
23
24 def name_of(bu:UOp, is_out:bool) -> str:
25 nonlocal n
26 if bu.op is Ops.PARAM: key, name, size = ("in", bu.arg), f"input{bu.arg}", prod(bu.shape)*bu.dtype.itemsize
27 else:
28 b = bu.buffer
29 key, size = (id(b.base), b.offset, b.size, b.dtype), b.size*b.dtype.itemsize
30 if key in bufs: return bufs[key][0]
31 if (name:=output_name.get(id(b))) is None:
32 name, n = f"buf_{n}", n+1
33 if not is_out: bufs_to_save[name] = b
34 bufs[key] = (name, size, bu.dtype, key)
35 return name
36
37 for call in iter_kernel_calls(linear):
38 arg_uops = [b for b in call.src[1:] if b.op is not Ops.BIND]

Callers 1

compile_netFunction · 0.85

Calls 3

prodFunction · 0.90
idFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…