Edward J. Schwartz commited on
Commit
fb223ca
·
1 Parent(s): 0f74380

Run each selected flag separately, one output tab per flag

Browse files
Files changed (1) hide show
  1. app.py +21 -8
app.py CHANGED
@@ -25,17 +25,22 @@ def version(tool):
25
  return subprocess.run([TOOLS[tool], "--version"], capture_output=True, text=True).stdout.split("release ")[-1].splitlines()[0]
26
 
27
 
28
- def run(file, tool, flags, extra):
29
- if file is None:
30
- return "Upload a cubin first."
31
  try:
32
- r = subprocess.run([TOOLS[tool], *flags, *shlex.split(extra or ""), file],
33
- capture_output=True, text=True, timeout=60)
34
  except subprocess.TimeoutExpired:
35
  return "Timed out after 60s."
36
  return r.stdout + r.stderr + (f"\n[exit code {r.returncode}]" if r.returncode else "")
37
 
38
 
 
 
 
 
 
 
 
 
39
  with gr.Blocks(title="cuobjdump / nvdisasm") as demo:
40
  gr.Markdown("# cuobjdump / nvdisasm\n"
41
  "Disassemble CUDA cubins, fatbins and ELF objects with NVIDIA's tools from PyPI.\n\n"
@@ -44,13 +49,21 @@ with gr.Blocks(title="cuobjdump / nvdisasm") as demo:
44
  with gr.Column():
45
  file = gr.File(label="cubin / fatbin / CUDA ELF", type="filepath")
46
  tool = gr.Radio(list(TOOLS), value="cuobjdump", label="Tool")
47
- flags = gr.CheckboxGroup(FLAGS["cuobjdump"], value=DEFAULT_FLAGS["cuobjdump"], label="Flags")
48
  extra = gr.Textbox(label="Extra arguments", placeholder="-fun vecadd")
49
  btn = gr.Button("Run", variant="primary")
50
- out = gr.Code(label="Output", lines=30, max_lines=60)
 
 
 
 
 
 
 
 
51
  gr.Examples([[e, t] for e in EXAMPLES for t in TOOLS], [file, tool])
52
  tool.change(lambda t: gr.CheckboxGroup(FLAGS[t], value=DEFAULT_FLAGS[t]), tool, flags)
53
- btn.click(run, [file, tool, flags, extra], out)
54
 
55
  if __name__ == "__main__":
56
  demo.launch()
 
25
  return subprocess.run([TOOLS[tool], "--version"], capture_output=True, text=True).stdout.split("release ")[-1].splitlines()[0]
26
 
27
 
28
+ def run_one(tool, args, file):
 
 
29
  try:
30
+ r = subprocess.run([TOOLS[tool], *args, file], capture_output=True, text=True, timeout=60)
 
31
  except subprocess.TimeoutExpired:
32
  return "Timed out after 60s."
33
  return r.stdout + r.stderr + (f"\n[exit code {r.returncode}]" if r.returncode else "")
34
 
35
 
36
+ def run(file, tool, flags, extra):
37
+ if file is None:
38
+ return {"error": "Upload a cubin first."}
39
+ extra = shlex.split(extra or "")
40
+ return {" ".join([f, *extra]): run_one(tool, [f, *extra], file) for f in flags} or \
41
+ {" ".join(extra) or tool: run_one(tool, extra, file)}
42
+
43
+
44
  with gr.Blocks(title="cuobjdump / nvdisasm") as demo:
45
  gr.Markdown("# cuobjdump / nvdisasm\n"
46
  "Disassemble CUDA cubins, fatbins and ELF objects with NVIDIA's tools from PyPI.\n\n"
 
49
  with gr.Column():
50
  file = gr.File(label="cubin / fatbin / CUDA ELF", type="filepath")
51
  tool = gr.Radio(list(TOOLS), value="cuobjdump", label="Tool")
52
+ flags = gr.CheckboxGroup(FLAGS["cuobjdump"], value=DEFAULT_FLAGS["cuobjdump"], label="Flags (each runs separately, one tab per flag)")
53
  extra = gr.Textbox(label="Extra arguments", placeholder="-fun vecadd")
54
  btn = gr.Button("Run", variant="primary")
55
+ with gr.Column(scale=2):
56
+ results = gr.State({})
57
+
58
+ @gr.render(inputs=results)
59
+ def show(results):
60
+ with gr.Tabs():
61
+ for label, output in results.items():
62
+ with gr.Tab(label):
63
+ gr.Code(output, label=label, lines=30, max_lines=60)
64
  gr.Examples([[e, t] for e in EXAMPLES for t in TOOLS], [file, tool])
65
  tool.change(lambda t: gr.CheckboxGroup(FLAGS[t], value=DEFAULT_FLAGS[t]), tool, flags)
66
+ btn.click(run, [file, tool, flags, extra], results)
67
 
68
  if __name__ == "__main__":
69
  demo.launch()