forked from tinygrad/tinygrad
Merge branch 'master' into prealloc_bufs
This commit is contained in:
+14
-16
@@ -237,7 +237,11 @@ function selectShape(key) {
|
||||
|
||||
const Modes = {0:'read', 1:'write', 2:'write+read'};
|
||||
|
||||
function getMetadata(key) {
|
||||
function setFocus(key) {
|
||||
if (key !== focusedShape) {
|
||||
saveToHistory({ shape:focusedShape });
|
||||
focusedShape = key; d3.select("#timeline").call(canvasZoom.transform, zoomLevel);
|
||||
}
|
||||
const { eventType, e } = selectShape(key);
|
||||
const html = d3.create("div").classed("info", true);
|
||||
if (eventType === EventTypes.EXEC) {
|
||||
@@ -249,14 +253,14 @@ function getMetadata(key) {
|
||||
for (const b of e.arg.bufs.sort((a, b) => a.num - b.num)) {
|
||||
group.append("p").text(`${Modes[b.mode]}@data${b.num} ${formatUnit(b.nbytes, 'B')}`).style("cursor", "pointer").on("click", () => {
|
||||
const row = document.getElementById(b.k); if (!isExpanded(row)) { row.click(); }
|
||||
focusShape(b.key);
|
||||
setFocus(b.key);
|
||||
});
|
||||
}
|
||||
if (e.arg.ctx != null) {
|
||||
const i = e.arg.ctx; s = e.arg.step;
|
||||
html.append("a").text(ctxs[i+1].steps[s].name).on("click", () => switchCtx(i, s));
|
||||
const prgSrc = ctxs[i+1].steps.findIndex(s => s.name === "View Program");
|
||||
if (prgSrc !== -1) html.append("a").text("View program").on("click", () => switchCtx(i, prgSrc));
|
||||
const prgSrc = ctxs[i+1].steps.findIndex(s => s.name === "View Source");
|
||||
if (prgSrc !== -1) html.append("a").text("View Source").on("click", () => switchCtx(i, prgSrc));
|
||||
}
|
||||
}
|
||||
if (eventType === EventTypes.BUF) {
|
||||
@@ -270,16 +274,10 @@ function getMetadata(key) {
|
||||
const p = kernels.append("p").append(() => colored(`[${u}] ${repr} ${Modes[mode]}@data${num}`));
|
||||
const shapeInfo = selectShape(shape).e?.arg?.tooltipText?.split("\n");
|
||||
if (shapeInfo?.length > 5) p.append("span").text(" "+shapeInfo[5]);
|
||||
if (shape != null) p.style("cursor", "pointer").on("click", () => focusShape(shape));
|
||||
if (shape != null) p.style("cursor", "pointer").on("click", () => setFocus(shape));
|
||||
}
|
||||
}
|
||||
return html.node();
|
||||
}
|
||||
|
||||
function focusShape(shape) {
|
||||
saveToHistory({ shape:focusedShape });
|
||||
focusedShape = shape; d3.select("#timeline").call(canvasZoom.transform, zoomLevel);
|
||||
return metadata.replaceChildren(getMetadata(focusedShape));
|
||||
return metadata.replaceChildren(html.node());
|
||||
}
|
||||
|
||||
const EventTypes = { EXEC:0, BUF:1 };
|
||||
@@ -289,7 +287,7 @@ async function renderProfiler(path, unit, opts) {
|
||||
// support non realtime x axis units
|
||||
formatTime = unit === "realtime" ? formatMicroseconds : formatCycles;
|
||||
if (data?.path !== path) { data = {tracks:new Map(), axes:{}, path, first:null}; focusedDevice = null; focusedShape = null; }
|
||||
metadata.replaceChildren(getMetadata(focusedShape));
|
||||
setFocus(focusedShape);
|
||||
// layout once!
|
||||
if (data.tracks.size !== 0) return updateProgress(Status.COMPLETE);
|
||||
const profiler = d3.select("#profiler").html("");
|
||||
@@ -608,7 +606,7 @@ async function renderProfiler(path, unit, opts) {
|
||||
e.preventDefault();
|
||||
const foundRect = findRectAtPosition(e.clientX, e.clientY);
|
||||
if (foundRect?.step != null && (foundRect?.key == null || e.type == "dblclick")) { return switchCtx(foundRect.ctx, foundRect.step); }
|
||||
if (foundRect?.key != focusedShape) { focusShape(foundRect?.key); }
|
||||
if (foundRect?.key != focusedShape) { setFocus(foundRect?.key); }
|
||||
}
|
||||
canvas.addEventListener("click", clickShape);
|
||||
canvas.addEventListener("dblclick", clickShape);
|
||||
@@ -741,7 +739,7 @@ function saveToHistory(ns) {
|
||||
const switchCtx = (newCtx, step) => setState({ expandSteps:true, currentCtx:newCtx+1, currentStep:step ?? 0, currentRewrite:0 });
|
||||
|
||||
window.addEventListener("popstate", (e) => {
|
||||
if (e.state?.shape != null) return focusShape(e.state?.shape);
|
||||
if (e.state?.shape != null) return setFocus(e.state?.shape);
|
||||
if (e.state != null) setState(e.state);
|
||||
});
|
||||
|
||||
@@ -874,7 +872,7 @@ async function main() {
|
||||
}
|
||||
if (ret.ref != null) {
|
||||
const disasmIdx = ctxs[ret.ref+1].steps.findIndex(s => s.name === "View Disassembly")
|
||||
metadata.appendChild(d3.create("a").text("View Program Graph").on("click", () => switchCtx(ret.ref, disasmIdx)).node());
|
||||
metadata.appendChild(d3.create("a").text("View Disassembly").on("click", () => switchCtx(ret.ref, disasmIdx)).node());
|
||||
}
|
||||
if (ret.cols != null) renderTable(root, ret);
|
||||
else if (ret.src != null) root.append(() => codeBlock(ret.src, ret.lang));
|
||||
|
||||
Reference in New Issue
Block a user