mirror of
https://github.com/tinygrad/tinygrad.git
synced 2026-01-09 15:08:02 -05:00
viz: infrastructure for basic block graphs (#13751)
This commit is contained in:
@@ -757,8 +757,8 @@ async function main() {
|
|||||||
if (ckey in cache) {
|
if (ckey in cache) {
|
||||||
ret = cache[ckey];
|
ret = cache[ckey];
|
||||||
}
|
}
|
||||||
// ** Disassembly view
|
// ** Text view
|
||||||
if (!ckey.startsWith("/rewrites")) {
|
if (!ckey.startsWith("/graph")) {
|
||||||
if (!(ckey in cache)) cache[ckey] = ret = await fetchValue(ckey);
|
if (!(ckey in cache)) cache[ckey] = ret = await fetchValue(ckey);
|
||||||
if (ret.steps?.length > 0) {
|
if (ret.steps?.length > 0) {
|
||||||
const el = select(state.currentCtx, state.currentStep);
|
const el = select(state.currentCtx, state.currentStep);
|
||||||
@@ -822,8 +822,8 @@ async function main() {
|
|||||||
});
|
});
|
||||||
return document.querySelector("#custom").replaceChildren(root.node());
|
return document.querySelector("#custom").replaceChildren(root.node());
|
||||||
}
|
}
|
||||||
// ** UOp view (default)
|
// ** Graph view
|
||||||
// if we don't have a complete cache yet we start streaming rewrites in this step
|
// if we don't have a complete cache yet we start streaming graphs in this step
|
||||||
if (!(ckey in cache) || (cache[ckey].length !== step.match_count+1 && activeSrc == null)) {
|
if (!(ckey in cache) || (cache[ckey].length !== step.match_count+1 && activeSrc == null)) {
|
||||||
ret = [];
|
ret = [];
|
||||||
cache[ckey] = ret;
|
cache[ckey] = ret;
|
||||||
@@ -847,7 +847,7 @@ async function main() {
|
|||||||
toggle.onchange = (e) => render({ showIndexing:e.target.checked });
|
toggle.onchange = (e) => render({ showIndexing:e.target.checked });
|
||||||
// ** right sidebar code blocks
|
// ** right sidebar code blocks
|
||||||
const codeElement = codeBlock(ret[currentRewrite].uop, "python", { wrap:false });
|
const codeElement = codeBlock(ret[currentRewrite].uop, "python", { wrap:false });
|
||||||
metadata.replaceChildren(toggleLabel, codeBlock(step.code_line, "python", { loc:step.loc, wrap:true }), codeElement);
|
if (step.code_line != null) metadata.replaceChildren(toggleLabel, codeBlock(step.code_line, "python", { loc:step.loc, wrap:true }), codeElement);
|
||||||
if (step.trace) {
|
if (step.trace) {
|
||||||
const trace = d3.create("pre").append("code").classed("hljs", true);
|
const trace = d3.create("pre").append("code").classed("hljs", true);
|
||||||
for (let i=step.trace.length-1; i>=0; i--) {
|
for (let i=step.trace.length-1; i>=0; i--) {
|
||||||
|
|||||||
@@ -37,8 +37,8 @@ ref_map:dict[Any, int] = {}
|
|||||||
def get_rewrites(t:RewriteTrace) -> list[dict]:
|
def get_rewrites(t:RewriteTrace) -> list[dict]:
|
||||||
ret = []
|
ret = []
|
||||||
for i,(k,v) in enumerate(zip(t.keys, t.rewrites)):
|
for i,(k,v) in enumerate(zip(t.keys, t.rewrites)):
|
||||||
steps = [create_step(s.name, ("/rewrites", i, j), loc=s.loc, match_count=len(s.matches), code_line=printable(s.loc), trace=k.tb if j==0 else None,
|
steps = [create_step(s.name, ("/graph-rewrites", i, j), loc=s.loc, match_count=len(s.matches), code_line=printable(s.loc),
|
||||||
depth=s.depth) for j,s in enumerate(v)]
|
trace=k.tb if j==0 else None, depth=s.depth) for j,s in enumerate(v)]
|
||||||
if isinstance(k.ret, ProgramSpec):
|
if isinstance(k.ret, ProgramSpec):
|
||||||
steps.append(create_step("View UOp List", ("/uops", i, len(steps)), k.ret))
|
steps.append(create_step("View UOp List", ("/uops", i, len(steps)), k.ret))
|
||||||
steps.append(create_step("View Program", ("/code", i, len(steps)), k.ret))
|
steps.append(create_step("View Program", ("/code", i, len(steps)), k.ret))
|
||||||
@@ -380,6 +380,7 @@ def amd_readelf(lib:bytes) -> list[dict]:
|
|||||||
|
|
||||||
def get_render(i:int, j:int, fmt:str) -> dict:
|
def get_render(i:int, j:int, fmt:str) -> dict:
|
||||||
data = ctxs[i]["steps"][j]["data"]
|
data = ctxs[i]["steps"][j]["data"]
|
||||||
|
if fmt == "graph-rewrites": return {"value":get_full_rewrite(trace.rewrites[i][j]), "content_type":"text/event-stream"}
|
||||||
if fmt == "uops": return {"src":get_stdout(lambda: print_uops(data.uops or [])), "lang":"txt"}
|
if fmt == "uops": return {"src":get_stdout(lambda: print_uops(data.uops or [])), "lang":"txt"}
|
||||||
if fmt == "code": return {"src":data.src, "lang":"cpp"}
|
if fmt == "code": return {"src":data.src, "lang":"cpp"}
|
||||||
if fmt == "asm":
|
if fmt == "asm":
|
||||||
@@ -462,14 +463,10 @@ class Handler(HTTPRequestHandler):
|
|||||||
if url.path.endswith(".css"): content_type = "text/css"
|
if url.path.endswith(".css"): content_type = "text/css"
|
||||||
except FileNotFoundError: status_code = 404
|
except FileNotFoundError: status_code = 404
|
||||||
elif (query:=parse_qs(url.query)):
|
elif (query:=parse_qs(url.query)):
|
||||||
i, j = get_int(query, "ctx"), get_int(query, "step")
|
render_src = get_render(get_int(query, "ctx"), get_int(query, "step"), url.path.lstrip("/"))
|
||||||
if (fmt:=url.path.lstrip("/")) == "rewrites":
|
if "content_type" in render_src: ret, content_type = render_src["value"], render_src["content_type"]
|
||||||
try: return self.stream_json(get_full_rewrite(trace.rewrites[i][j]))
|
else: ret, content_type = json.dumps(render_src).encode(), "application/json"
|
||||||
except (KeyError, IndexError): status_code = 404
|
if content_type == "text/event-stream": return self.stream_json(render_src["value"])
|
||||||
else:
|
|
||||||
render_src = get_render(i, j, fmt)
|
|
||||||
if "content_type" in render_src: ret, content_type = render_src["value"], render_src["content_type"]
|
|
||||||
else: ret, content_type = json.dumps(render_src).encode(), "application/json"
|
|
||||||
elif url.path == "/ctxs":
|
elif url.path == "/ctxs":
|
||||||
lst = [{**c, "steps":[{k:v for k, v in s.items() if k != "data"} for s in c["steps"]]} for c in ctxs]
|
lst = [{**c, "steps":[{k:v for k, v in s.items() if k != "data"} for s in c["steps"]]} for c in ctxs]
|
||||||
ret, content_type = json.dumps(lst).encode(), "application/json"
|
ret, content_type = json.dumps(lst).encode(), "application/json"
|
||||||
|
|||||||
Reference in New Issue
Block a user