|
| 1 | +/** |
| 2 | + * V8-R06 CompileTracePanel — renders the compile.trace RPC output as |
| 3 | + * a per-op chip table with fused / dlpack-crossing / materialised |
| 4 | + * markers and an aggregate header line. |
| 5 | + */ |
| 6 | + |
| 7 | +import { useEffect, useState } from "react"; |
| 8 | +import type { RpcClient } from "@/lib/rpc"; |
| 9 | + |
| 10 | +interface CompileTraceOp { |
| 11 | + name: string; |
| 12 | + fused: boolean; |
| 13 | + group: string; |
| 14 | + materialised: boolean; |
| 15 | + dlpack_boundary: boolean; |
| 16 | + backend: string; |
| 17 | +} |
| 18 | + |
| 19 | +interface CompileTraceResult { |
| 20 | + ops: CompileTraceOp[]; |
| 21 | + fused_groups: string[]; |
| 22 | + dlpack_crossings: number; |
| 23 | + materialised_ops: string[]; |
| 24 | + compile_artifact_path: string | null; |
| 25 | + backend: string; |
| 26 | +} |
| 27 | + |
| 28 | +export interface CompileTracePanelProps { |
| 29 | + rpc: RpcClient; |
| 30 | + specPayload: unknown; |
| 31 | + backend?: "tilelang" | "torch_inductor" | "mlx"; |
| 32 | +} |
| 33 | + |
| 34 | +export function CompileTracePanel({ |
| 35 | + rpc, specPayload, backend = "mlx", |
| 36 | +}: CompileTracePanelProps): JSX.Element { |
| 37 | + const [trace, setTrace] = useState<CompileTraceResult | null>(null); |
| 38 | + const [err, setErr] = useState<string | null>(null); |
| 39 | + |
| 40 | + useEffect(() => { |
| 41 | + let cancelled = false; |
| 42 | + (async () => { |
| 43 | + setErr(null); |
| 44 | + try { |
| 45 | + const r = await rpc.call<CompileTraceResult>( |
| 46 | + "compile.trace", |
| 47 | + { spec: specPayload, backend }, |
| 48 | + ); |
| 49 | + if (!cancelled) setTrace(r); |
| 50 | + } catch (e) { |
| 51 | + if (!cancelled) { |
| 52 | + setErr(e instanceof Error ? e.message : String(e)); |
| 53 | + } |
| 54 | + } |
| 55 | + })(); |
| 56 | + return () => { cancelled = true; }; |
| 57 | + }, [rpc, specPayload, backend]); |
| 58 | + |
| 59 | + if (err) { |
| 60 | + return <div data-testid="compile-trace-error" |
| 61 | + style={{ color: "#b91c1c", padding: 12 }}>{err}</div>; |
| 62 | + } |
| 63 | + if (!trace) { |
| 64 | + return <div data-testid="compile-trace-loading" |
| 65 | + style={{ padding: 12, color: "#6b7280" }}>loading…</div>; |
| 66 | + } |
| 67 | + |
| 68 | + return ( |
| 69 | + <div data-testid="compile-trace" style={{ padding: 12, |
| 70 | + fontFamily: "system-ui, sans-serif", fontSize: 12 }}> |
| 71 | + <header style={{ display: "flex", gap: 12, marginBottom: 8 }}> |
| 72 | + <span>backend: <strong>{trace.backend}</strong></span> |
| 73 | + <span data-testid="compile-trace-fused-count"> |
| 74 | + fused groups: {trace.fused_groups.length} |
| 75 | + </span> |
| 76 | + <span data-testid="compile-trace-dlpack-crossings"> |
| 77 | + dlpack crossings: {trace.dlpack_crossings} |
| 78 | + </span> |
| 79 | + <span data-testid="compile-trace-materialised-count"> |
| 80 | + materialised: {trace.materialised_ops.length} |
| 81 | + </span> |
| 82 | + </header> |
| 83 | + {trace.fused_groups.map((g) => ( |
| 84 | + <span key={g} |
| 85 | + data-testid={`compile-trace-fused-group-${g}`} |
| 86 | + style={{ display: "inline-block", marginRight: 6, |
| 87 | + background: "#dbeafe", color: "#1e3a8a", |
| 88 | + borderRadius: 4, padding: "2px 6px" }}> |
| 89 | + {g} |
| 90 | + </span> |
| 91 | + ))} |
| 92 | + <table style={{ marginTop: 8, borderCollapse: "collapse", |
| 93 | + width: "100%" }}> |
| 94 | + <thead> |
| 95 | + <tr style={{ borderBottom: "1px solid #e5e7eb" }}> |
| 96 | + <th style={th}>op</th> |
| 97 | + <th style={th}>backend</th> |
| 98 | + <th style={th}>group</th> |
| 99 | + <th style={th}>chips</th> |
| 100 | + </tr> |
| 101 | + </thead> |
| 102 | + <tbody> |
| 103 | + {trace.ops.map((op, i) => ( |
| 104 | + <tr key={`${op.name}-${i}`} |
| 105 | + data-testid={`compile-trace-op-${i}`}> |
| 106 | + <td style={td}>{op.name}</td> |
| 107 | + <td style={td}>{op.backend}</td> |
| 108 | + <td style={td}>{op.group}</td> |
| 109 | + <td style={td}> |
| 110 | + {op.fused && ( |
| 111 | + <span style={chip("#dbeafe", "#1e3a8a")}>fused</span> |
| 112 | + )} |
| 113 | + {op.materialised && ( |
| 114 | + <span style={chip("#fef3c7", "#92400e")} |
| 115 | + data-testid={ |
| 116 | + `compile-trace-op-${i}-materialised`}> |
| 117 | + materialised |
| 118 | + </span> |
| 119 | + )} |
| 120 | + {op.dlpack_boundary && ( |
| 121 | + <span style={chip("#fee2e2", "#7f1d1d")} |
| 122 | + data-testid={ |
| 123 | + `compile-trace-op-${i}-dlpack`}> |
| 124 | + dlpack |
| 125 | + </span> |
| 126 | + )} |
| 127 | + </td> |
| 128 | + </tr> |
| 129 | + ))} |
| 130 | + </tbody> |
| 131 | + </table> |
| 132 | + </div> |
| 133 | + ); |
| 134 | +} |
| 135 | + |
| 136 | +const th: React.CSSProperties = { |
| 137 | + textAlign: "left", padding: "4px 6px", color: "#374151", |
| 138 | + fontWeight: 600, |
| 139 | +}; |
| 140 | + |
| 141 | +const td: React.CSSProperties = { |
| 142 | + padding: "4px 6px", color: "#1f2937", |
| 143 | + borderBottom: "1px solid #f3f4f6", |
| 144 | +}; |
| 145 | + |
| 146 | +function chip(bg: string, fg: string): React.CSSProperties { |
| 147 | + return { |
| 148 | + display: "inline-block", marginRight: 4, padding: "1px 6px", |
| 149 | + borderRadius: 4, background: bg, color: fg, fontSize: 10, |
| 150 | + }; |
| 151 | +} |
0 commit comments