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

HF Space: run cuobjdump/nvdisasm on uploaded cubins

Browse files
.gitattributes ADDED
@@ -0,0 +1 @@
 
 
1
+ *.cubin filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ __pycache__/
README.md ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: cuobjdump / nvdisasm
3
+ emoji: 🔍
4
+ colorFrom: green
5
+ colorTo: gray
6
+ sdk: gradio
7
+ sdk_version: 6.29.1
8
+ app_file: app.py
9
+ pinned: false
10
+ short_description: Disassemble CUDA cubins with cuobjdump and nvdisasm
11
+ ---
12
+
13
+ Upload a CUDA cubin, fatbin or ELF object and run NVIDIA's `cuobjdump` or `nvdisasm` on it.
14
+ Both tools are installed from PyPI (`nvidia-cuda-cuobjdump`, `nvidia-cuda-nvdisasm`); no GPU required.
15
+
16
+ `examples/` holds two cubins assembled with `ptxas` from the included PTX sources.
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import shlex
2
+ import subprocess
3
+ from pathlib import Path
4
+
5
+ import gradio as gr
6
+ import nvidia
7
+
8
+
9
+ def find_tool(name):
10
+ path = next(p for d in nvidia.__path__ if (p := Path(d) / "cu13/bin" / name).exists())
11
+ path.chmod(0o755)
12
+ return str(path)
13
+
14
+
15
+ TOOLS = {name: find_tool(name) for name in ("cuobjdump", "nvdisasm")}
16
+ 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
+
24
+ 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"
42
+ + "\n".join(f"- `{t}`: {version(t)}" for t in TOOLS))
43
+ with gr.Row():
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()
examples/saxpy.ptx ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .version 8.0
2
+ .target sm_90
3
+ .address_size 64
4
+
5
+ .visible .entry saxpy(
6
+ .param .f32 alpha,
7
+ .param .u64 x,
8
+ .param .u64 y,
9
+ .param .u32 n
10
+ )
11
+ {
12
+ .reg .pred %p;
13
+ .reg .b32 %r<6>;
14
+ .reg .f32 %f<5>;
15
+ .reg .b64 %rd<8>;
16
+
17
+ ld.param.f32 %f1, [alpha];
18
+ ld.param.u64 %rd1, [x];
19
+ ld.param.u64 %rd2, [y];
20
+ ld.param.u32 %r1, [n];
21
+ mov.u32 %r2, %ctaid.x;
22
+ mov.u32 %r3, %ntid.x;
23
+ mov.u32 %r4, %tid.x;
24
+ mad.lo.s32 %r5, %r2, %r3, %r4;
25
+ setp.ge.s32 %p, %r5, %r1;
26
+ @%p bra DONE;
27
+ cvta.to.global.u64 %rd3, %rd1;
28
+ cvta.to.global.u64 %rd4, %rd2;
29
+ mul.wide.s32 %rd5, %r5, 4;
30
+ add.s64 %rd6, %rd3, %rd5;
31
+ add.s64 %rd7, %rd4, %rd5;
32
+ ld.global.f32 %f2, [%rd6];
33
+ ld.global.f32 %f3, [%rd7];
34
+ fma.rn.f32 %f4, %f1, %f2, %f3;
35
+ st.global.f32 [%rd7], %f4;
36
+ DONE:
37
+ ret;
38
+ }
examples/saxpy_sm90.cubin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9020ab700f01f18e53ab948267b26a34b86ea3ac5952879e3c840bb703898ebe
3
+ size 3848
examples/vecadd.ptx ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .version 8.0
2
+ .target sm_80
3
+ .address_size 64
4
+
5
+ .visible .entry vecadd(
6
+ .param .u64 a,
7
+ .param .u64 b,
8
+ .param .u64 c,
9
+ .param .u32 n
10
+ )
11
+ {
12
+ .reg .pred %p;
13
+ .reg .b32 %r<6>;
14
+ .reg .f32 %f<4>;
15
+ .reg .b64 %rd<10>;
16
+
17
+ ld.param.u64 %rd1, [a];
18
+ ld.param.u64 %rd2, [b];
19
+ ld.param.u64 %rd3, [c];
20
+ ld.param.u32 %r1, [n];
21
+ mov.u32 %r2, %ctaid.x;
22
+ mov.u32 %r3, %ntid.x;
23
+ mov.u32 %r4, %tid.x;
24
+ mad.lo.s32 %r5, %r2, %r3, %r4;
25
+ setp.ge.s32 %p, %r5, %r1;
26
+ @%p bra DONE;
27
+ cvta.to.global.u64 %rd4, %rd1;
28
+ cvta.to.global.u64 %rd5, %rd2;
29
+ cvta.to.global.u64 %rd6, %rd3;
30
+ mul.wide.s32 %rd7, %r5, 4;
31
+ add.s64 %rd8, %rd4, %rd7;
32
+ ld.global.f32 %f1, [%rd8];
33
+ add.s64 %rd8, %rd5, %rd7;
34
+ ld.global.f32 %f2, [%rd8];
35
+ add.f32 %f3, %f1, %f2;
36
+ add.s64 %rd9, %rd6, %rd7;
37
+ st.global.f32 [%rd9], %f3;
38
+ DONE:
39
+ ret;
40
+ }
examples/vecadd_sm80.cubin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f1d8c85fb66f436d80ed32bfbd16809226361377520f64ea675dac791622f0f7
3
+ size 3368
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ nvidia-cuda-cuobjdump
2
+ nvidia-cuda-nvdisasm