Spaces:
Running
Running
Edward J. Schwartz commited on
Commit ·
c229485
1
Parent(s): 1909c69
Use long option names; split nvdisasm into outputs and display options
Browse files
app.py
CHANGED
|
@@ -13,10 +13,17 @@ def find_tool(name):
|
|
| 13 |
|
| 14 |
|
| 15 |
TOOLS = {name: find_tool(name) for name in ("cuobjdump", "nvdisasm")}
|
| 16 |
-
|
| 17 |
-
"cuobjdump": ["-sass", "-ptx", "-elf", "-
|
| 18 |
-
|
|
|
|
| 19 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
EXAMPLES = sorted(str(p) for p in Path(__file__).with_name("examples").glob("*.cubin"))
|
| 21 |
|
| 22 |
|
|
@@ -32,12 +39,18 @@ def run_one(tool, args, file):
|
|
| 32 |
return (r.stdout + r.stderr or "(no output)") + (f"\n[exit code {r.returncode}]" if r.returncode else "")
|
| 33 |
|
| 34 |
|
| 35 |
-
def run(file, tool,
|
| 36 |
if file is None:
|
| 37 |
return {"error": "Upload a cubin first."}
|
| 38 |
-
|
| 39 |
-
return {" ".join(
|
| 40 |
-
{" ".join(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
|
| 43 |
with gr.Blocks(title="cuobjdump / nvdisasm") as demo:
|
|
@@ -49,9 +62,10 @@ with gr.Blocks(title="cuobjdump / nvdisasm") as demo:
|
|
| 49 |
file = gr.File(label="cubin / fatbin / CUDA ELF", type="filepath")
|
| 50 |
with gr.Column(scale=2):
|
| 51 |
tool = gr.Radio(list(TOOLS), value="cuobjdump", label="Tool")
|
| 52 |
-
|
|
|
|
| 53 |
with gr.Row(equal_height=True):
|
| 54 |
-
extra = gr.Textbox(label="Extra arguments", placeholder="
|
| 55 |
btn = gr.Button("Run", variant="primary", scale=1)
|
| 56 |
gr.Examples(EXAMPLES, file)
|
| 57 |
results = gr.State({})
|
|
@@ -61,8 +75,8 @@ with gr.Blocks(title="cuobjdump / nvdisasm") as demo:
|
|
| 61 |
for label, output in results.items():
|
| 62 |
gr.Code(output, label=label, max_lines=60)
|
| 63 |
|
| 64 |
-
tool.change(
|
| 65 |
-
btn.click(run, [file, tool,
|
| 66 |
|
| 67 |
if __name__ == "__main__":
|
| 68 |
demo.launch()
|
|
|
|
| 13 |
|
| 14 |
|
| 15 |
TOOLS = {name: find_tool(name) for name in ("cuobjdump", "nvdisasm")}
|
| 16 |
+
OUTPUTS = {
|
| 17 |
+
"cuobjdump": ["--dump-sass", "--dump-ptx", "--dump-elf", "--dump-resource-usage", "--dump-elf-symbols",
|
| 18 |
+
"--list-elf", "--list-ptx"],
|
| 19 |
+
"nvdisasm": ["--print-code", "--output-control-flow-graph", "--output-control-flow-graph-with-basic-blocks"],
|
| 20 |
}
|
| 21 |
+
MODIFIERS = {
|
| 22 |
+
"cuobjdump": [],
|
| 23 |
+
"nvdisasm": ["--print-instruction-encoding", "--print-life-ranges", "--print-raw", "--print-line-info",
|
| 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 |
|
|
|
|
| 39 |
return (r.stdout + r.stderr or "(no output)") + (f"\n[exit code {r.returncode}]" if r.returncode else "")
|
| 40 |
|
| 41 |
|
| 42 |
+
def run(file, tool, outputs, modifiers, extra):
|
| 43 |
if file is None:
|
| 44 |
return {"error": "Upload a cubin first."}
|
| 45 |
+
common = [*modifiers, *shlex.split(extra or "")]
|
| 46 |
+
return {" ".join(args): run_one(tool, args, file) for args in ([o, *common] for o in outputs)} or \
|
| 47 |
+
{" ".join(common) or tool: run_one(tool, common, file)}
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def select_tool(tool):
|
| 51 |
+
return (gr.CheckboxGroup(OUTPUTS[tool], value=OUTPUTS[tool]),
|
| 52 |
+
gr.CheckboxGroup(MODIFIERS[tool], value=[], visible=bool(MODIFIERS[tool])),
|
| 53 |
+
gr.Textbox(placeholder=EXTRA_EXAMPLE[tool]))
|
| 54 |
|
| 55 |
|
| 56 |
with gr.Blocks(title="cuobjdump / nvdisasm") as demo:
|
|
|
|
| 62 |
file = gr.File(label="cubin / fatbin / CUDA ELF", type="filepath")
|
| 63 |
with gr.Column(scale=2):
|
| 64 |
tool = gr.Radio(list(TOOLS), value="cuobjdump", label="Tool")
|
| 65 |
+
outputs = gr.CheckboxGroup(OUTPUTS["cuobjdump"], value=OUTPUTS["cuobjdump"], label="Outputs (each runs separately)")
|
| 66 |
+
modifiers = gr.CheckboxGroup(MODIFIERS["cuobjdump"], label="Display options (applied to every run)", visible=False)
|
| 67 |
with gr.Row(equal_height=True):
|
| 68 |
+
extra = gr.Textbox(label="Extra arguments", placeholder=EXTRA_EXAMPLE["cuobjdump"], scale=4)
|
| 69 |
btn = gr.Button("Run", variant="primary", scale=1)
|
| 70 |
gr.Examples(EXAMPLES, file)
|
| 71 |
results = gr.State({})
|
|
|
|
| 75 |
for label, output in results.items():
|
| 76 |
gr.Code(output, label=label, max_lines=60)
|
| 77 |
|
| 78 |
+
tool.change(select_tool, tool, [outputs, modifiers, extra])
|
| 79 |
+
btn.click(run, [file, tool, outputs, modifiers, extra], results)
|
| 80 |
|
| 81 |
if __name__ == "__main__":
|
| 82 |
demo.launch()
|