Spaces:
Running
Running
Edward J. Schwartz commited on
Commit ·
bd11be5
1
Parent(s): c229485
Render nvdisasm CFGs in the browser with d3-graphviz
Browse files
app.py
CHANGED
|
@@ -24,6 +24,13 @@ MODIFIERS = {
|
|
| 24 |
"--print-line-info-inline"],
|
| 25 |
}
|
| 26 |
EXTRA_EXAMPLE = {"cuobjdump": "--function vecadd", "nvdisasm": "--emit-json"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
EXAMPLES = sorted(str(p) for p in Path(__file__).with_name("examples").glob("*.cubin"))
|
| 28 |
|
| 29 |
|
|
@@ -73,7 +80,15 @@ with gr.Blocks(title="cuobjdump / nvdisasm") as demo:
|
|
| 73 |
@gr.render(inputs=results)
|
| 74 |
def show(results):
|
| 75 |
for label, output in results.items():
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
tool.change(select_tool, tool, [outputs, modifiers, extra])
|
| 79 |
btn.click(run, [file, tool, outputs, modifiers, extra], results)
|
|
|
|
| 24 |
"--print-line-info-inline"],
|
| 25 |
}
|
| 26 |
EXTRA_EXAMPLE = {"cuobjdump": "--function vecadd", "nvdisasm": "--emit-json"}
|
| 27 |
+
GRAPHVIZ_HEAD = "".join(f'<script src="https://cdn.jsdelivr.net/npm/{lib}"></script>' for lib in (
|
| 28 |
+
"d3@7.9.0/dist/d3.min.js", "@hpcc-js/wasm@2.20.0/dist/graphviz.umd.js", "d3-graphviz@5.6.0/build/d3-graphviz.min.js"))
|
| 29 |
+
GRAPHVIZ_JS = """
|
| 30 |
+
const graph = element.querySelector('.graph');
|
| 31 |
+
d3.select(graph).graphviz({useWorker: false, zoom: true, fit: true})
|
| 32 |
+
.width(graph.clientWidth).height(graph.clientHeight).renderDot(props.value);
|
| 33 |
+
"""
|
| 34 |
EXAMPLES = sorted(str(p) for p in Path(__file__).with_name("examples").glob("*.cubin"))
|
| 35 |
|
| 36 |
|
|
|
|
| 80 |
@gr.render(inputs=results)
|
| 81 |
def show(results):
|
| 82 |
for label, output in results.items():
|
| 83 |
+
if output.startswith("digraph"):
|
| 84 |
+
gr.Markdown(f"`{label}` (scroll to zoom, drag to pan)")
|
| 85 |
+
gr.HTML(output.replace("\t", " "), head=GRAPHVIZ_HEAD, js_on_load=GRAPHVIZ_JS,
|
| 86 |
+
html_template='<div class="graph" style="height:70vh;background:white;'
|
| 87 |
+
'border:1px solid var(--border-color-primary)"></div>')
|
| 88 |
+
with gr.Accordion(f"{label} (DOT source)", open=False):
|
| 89 |
+
gr.Code(output, max_lines=60)
|
| 90 |
+
else:
|
| 91 |
+
gr.Code(output, label=label, max_lines=60)
|
| 92 |
|
| 93 |
tool.change(select_tool, tool, [outputs, modifiers, extra])
|
| 94 |
btn.click(run, [file, tool, outputs, modifiers, extra], results)
|