Edward J. Schwartz commited on
Commit
1909c69
·
1 Parent(s): ef58d40

Check all flags by default, full-width outputs, simpler examples

Browse files
Files changed (1) hide show
  1. app.py +19 -18
app.py CHANGED
@@ -17,7 +17,6 @@ FLAGS = {
17
  "cuobjdump": ["-sass", "-ptx", "-elf", "-res-usage", "-symbols", "-lelf", "-lptx"],
18
  "nvdisasm": ["-c", "-g", "-gi", "-hex", "-print-life-ranges", "-print-raw", "-print-line-info", "-cfg", "-bbcfg"],
19
  }
20
- DEFAULT_FLAGS = {"cuobjdump": ["-sass"], "nvdisasm": ["-c"]}
21
  EXAMPLES = sorted(str(p) for p in Path(__file__).with_name("examples").glob("*.cubin"))
22
 
23
 
@@ -30,7 +29,7 @@ def run_one(tool, args, file):
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):
@@ -43,24 +42,26 @@ def run(file, tool, flags, extra):
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"
47
- + "\n".join(f"- `{t}`: {version(t)}" for t in TOOLS))
48
- with gr.Row():
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 with its own output)")
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
- for label, output in results.items():
61
- gr.Code(output, label=label, max_lines=60)
62
- gr.Examples([[e, t] for e in EXAMPLES for t in TOOLS], [file, tool])
63
- tool.change(lambda t: gr.CheckboxGroup(FLAGS[t], value=DEFAULT_FLAGS[t]), tool, flags)
 
 
 
 
 
 
64
  btn.click(run, [file, tool, flags, extra], results)
65
 
66
  if __name__ == "__main__":
 
17
  "cuobjdump": ["-sass", "-ptx", "-elf", "-res-usage", "-symbols", "-lelf", "-lptx"],
18
  "nvdisasm": ["-c", "-g", "-gi", "-hex", "-print-life-ranges", "-print-raw", "-print-line-info", "-cfg", "-bbcfg"],
19
  }
 
20
  EXAMPLES = sorted(str(p) for p in Path(__file__).with_name("examples").glob("*.cubin"))
21
 
22
 
 
29
  r = subprocess.run([TOOLS[tool], *args, file], capture_output=True, text=True, timeout=60)
30
  except subprocess.TimeoutExpired:
31
  return "Timed out after 60s."
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, flags, extra):
 
42
 
43
  with gr.Blocks(title="cuobjdump / nvdisasm") as demo:
44
  gr.Markdown("# cuobjdump / nvdisasm\n"
45
+ "Disassemble CUDA cubins, fatbins and ELF objects with NVIDIA's tools from PyPI ("
46
+ + ", ".join(f"`{t}` {version(t)}" for t in TOOLS) + ").")
47
+ with gr.Row(equal_height=True):
48
+ with gr.Column(scale=1):
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
+ flags = gr.CheckboxGroup(FLAGS["cuobjdump"], value=FLAGS["cuobjdump"], label="Flags (each runs separately with its own output)")
53
+ with gr.Row(equal_height=True):
54
+ extra = gr.Textbox(label="Extra arguments", placeholder="-fun vecadd", scale=4)
55
+ btn = gr.Button("Run", variant="primary", scale=1)
56
+ gr.Examples(EXAMPLES, file)
57
+ results = gr.State({})
58
+
59
+ @gr.render(inputs=results)
60
+ def show(results):
61
+ for label, output in results.items():
62
+ gr.Code(output, label=label, max_lines=60)
63
+
64
+ tool.change(lambda t: gr.CheckboxGroup(FLAGS[t], value=FLAGS[t]), tool, flags)
65
  btn.click(run, [file, tool, flags, extra], results)
66
 
67
  if __name__ == "__main__":