Space

GPU smoke

wdtest-a/g9-gpu-smoke

G9 GPU smoke

wdtest-a committed on October 25, 2026

fc164c6961ab89c1f9f54586d8683b5d7a3bfc6cParent 9b91fe8Browse files

3 files changed+80 -0

Dockerfile

Added+7 -0
Lines 0 to 0 become lines 1 to 7
@@ -0,0 +1,7 @@
1Added: FROM python:3.12-slim-bookworm
2Added: # The ADR-0041 trap: an image that asks for every GPU itself. The proxy must force it empty.
3Added: ENV NVIDIA_VISIBLE_DEVICES=all PIP_NO_CACHE_DIR=1
4Added: RUN pip install --only-binary=:all: torch==2.14.1
5Added: COPY app.py /app/app.py
6Added: USER 1000
7Added: CMD ["python", "/app/app.py"]

README.md

Modified+2 -0
Lines 1 to 4 become lines 1 to 6
@@ -1,4 +1,6 @@
11---
2Added: title: GPU smoke
23sdk: docker
34app_port: 7860
45---
6Added: G9 live proof: torch on CUDA inside runsc-gpu.

app.py

Added+71 -0
Lines 0 to 0 become lines 1 to 71
@@ -0,0 +1,71 @@
1Added: """G9 GPU smoke Space: reports torch-on-CUDA, measures TFLOPS, allocates on demand."""
2Added: import json, os, time
3Added: from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
4Added: from urllib.parse import parse_qs, urlparse
5Added:
6Added: import torch
7Added:
8Added: HELD = []
9Added:
10Added:
11Added: def info():
12Added: ok = torch.cuda.is_available()
13Added: out = {"cuda": ok, "torch": torch.__version__, "visible": os.environ.get("NVIDIA_VISIBLE_DEVICES")}
14Added: if ok:
15Added: out["device"] = torch.cuda.get_device_name(0)
16Added: out["capability"] = torch.cuda.get_device_capability(0)
17Added: a = torch.ones(512, 512, device="cuda")
18Added: out["matmul_sum"] = float((a @ a).sum()) # 512**3 = 134217728
19Added: return out
20Added:
21Added:
22Added: def tflops():
23Added: n = 4096
24Added: a = torch.randn(n, n, device="cuda", dtype=torch.float32)
25Added: b = torch.randn(n, n, device="cuda", dtype=torch.float32)
26Added: for _ in range(3):
27Added: a @ b
28Added: torch.cuda.synchronize()
29Added: t = time.perf_counter(); reps = 20
30Added: for _ in range(reps):
31Added: a @ b
32Added: torch.cuda.synchronize()
33Added: return {"tflops_fp32": round(2 * n**3 * reps / (time.perf_counter() - t) / 1e12, 2)}
34Added:
35Added:
36Added: def alloc(gib, managed=False):
37Added: t = time.time()
38Added: if managed:
39Added: from cuda.bindings import runtime as rt
40Added: err, ptr = rt.cudaMallocManaged(int(gib * 2**30), rt.cudaMemAttachGlobal)
41Added: rt.cudaMemset(ptr, 1, int(gib * 2**30)); rt.cudaDeviceSynchronize()
42Added: HELD.append(("managed", ptr))
43Added: else:
44Added: HELD.append(("tensor", torch.ones(int(gib * 2**28), device="cuda"))) # float32: 4 bytes
45Added: torch.cuda.synchronize()
46Added: return {"held_blocks": len(HELD), "took_s": round(time.time() - t, 2)}
47Added:
48Added:
49Added: class H(BaseHTTPRequestHandler):
50Added: def do_GET(self):
51Added: u = urlparse(self.path); q = parse_qs(u.query)
52Added: try:
53Added: if u.path == "/":
54Added: body = info()
55Added: elif u.path == "/tflops":
56Added: body = tflops()
57Added: elif u.path in ("/alloc", "/managed"):
58Added: body = alloc(float(q.get("gib", ["1"])[0]), managed=u.path == "/managed")
59Added: elif u.path == "/free":
60Added: HELD.clear(); torch.cuda.empty_cache(); body = {"freed": True}
61Added: else:
62Added: self.send_error(404); return
63Added: code = 200
64Added: except Exception as e: # report, don't crash the probe target
65Added: body, code = {"error": repr(e)}, 500
66Added: data = json.dumps(body).encode()
67Added: self.send_response(code); self.send_header("Content-Type", "application/json")
68Added: self.send_header("Content-Length", str(len(data))); self.end_headers(); self.wfile.write(data)
69Added:
70Added:
71Added: ThreadingHTTPServer(("0.0.0.0", 7860), H).serve_forever()