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
Dockerfile
Added+7 -0
| @@ -0,0 +1,7 @@ | |||
| 1 | Added: FROM python:3.12-slim-bookworm | ||
| 2 | Added: # The ADR-0041 trap: an image that asks for every GPU itself. The proxy must force it empty. | ||
| 3 | Added: ENV NVIDIA_VISIBLE_DEVICES=all PIP_NO_CACHE_DIR=1 | ||
| 4 | Added: RUN pip install --only-binary=:all: torch==2.14.1 | ||
| 5 | Added: COPY app.py /app/app.py | ||
| 6 | Added: USER 1000 | ||
| 7 | Added: CMD ["python", "/app/app.py"] | ||
README.md
Modified+2 -0
README.md
Modified+2 -0
| @@ -1,4 +1,6 @@ | |||
| 1 | 1 | --- | |
| 2 | Added: title: GPU smoke | ||
| 2 | 3 | sdk: docker | |
| 3 | 4 | app_port: 7860 | |
| 4 | 5 | --- | |
| 6 | Added: G9 live proof: torch on CUDA inside runsc-gpu. | ||
app.py
Added+71 -0
app.py
Added+71 -0
| @@ -0,0 +1,71 @@ | |||
| 1 | Added: """G9 GPU smoke Space: reports torch-on-CUDA, measures TFLOPS, allocates on demand.""" | ||
| 2 | Added: import json, os, time | ||
| 3 | Added: from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer | ||
| 4 | Added: from urllib.parse import parse_qs, urlparse | ||
| 5 | Added: | ||
| 6 | Added: import torch | ||
| 7 | Added: | ||
| 8 | Added: HELD = [] | ||
| 9 | Added: | ||
| 10 | Added: | ||
| 11 | Added: def info(): | ||
| 12 | Added: ok = torch.cuda.is_available() | ||
| 13 | Added: out = {"cuda": ok, "torch": torch.__version__, "visible": os.environ.get("NVIDIA_VISIBLE_DEVICES")} | ||
| 14 | Added: if ok: | ||
| 15 | Added: out["device"] = torch.cuda.get_device_name(0) | ||
| 16 | Added: out["capability"] = torch.cuda.get_device_capability(0) | ||
| 17 | Added: a = torch.ones(512, 512, device="cuda") | ||
| 18 | Added: out["matmul_sum"] = float((a @ a).sum()) # 512**3 = 134217728 | ||
| 19 | Added: return out | ||
| 20 | Added: | ||
| 21 | Added: | ||
| 22 | Added: def tflops(): | ||
| 23 | Added: n = 4096 | ||
| 24 | Added: a = torch.randn(n, n, device="cuda", dtype=torch.float32) | ||
| 25 | Added: b = torch.randn(n, n, device="cuda", dtype=torch.float32) | ||
| 26 | Added: for _ in range(3): | ||
| 27 | Added: a @ b | ||
| 28 | Added: torch.cuda.synchronize() | ||
| 29 | Added: t = time.perf_counter(); reps = 20 | ||
| 30 | Added: for _ in range(reps): | ||
| 31 | Added: a @ b | ||
| 32 | Added: torch.cuda.synchronize() | ||
| 33 | Added: return {"tflops_fp32": round(2 * n**3 * reps / (time.perf_counter() - t) / 1e12, 2)} | ||
| 34 | Added: | ||
| 35 | Added: | ||
| 36 | Added: def alloc(gib, managed=False): | ||
| 37 | Added: t = time.time() | ||
| 38 | Added: if managed: | ||
| 39 | Added: from cuda.bindings import runtime as rt | ||
| 40 | Added: err, ptr = rt.cudaMallocManaged(int(gib * 2**30), rt.cudaMemAttachGlobal) | ||
| 41 | Added: rt.cudaMemset(ptr, 1, int(gib * 2**30)); rt.cudaDeviceSynchronize() | ||
| 42 | Added: HELD.append(("managed", ptr)) | ||
| 43 | Added: else: | ||
| 44 | Added: HELD.append(("tensor", torch.ones(int(gib * 2**28), device="cuda"))) # float32: 4 bytes | ||
| 45 | Added: torch.cuda.synchronize() | ||
| 46 | Added: return {"held_blocks": len(HELD), "took_s": round(time.time() - t, 2)} | ||
| 47 | Added: | ||
| 48 | Added: | ||
| 49 | Added: class H(BaseHTTPRequestHandler): | ||
| 50 | Added: def do_GET(self): | ||
| 51 | Added: u = urlparse(self.path); q = parse_qs(u.query) | ||
| 52 | Added: try: | ||
| 53 | Added: if u.path == "/": | ||
| 54 | Added: body = info() | ||
| 55 | Added: elif u.path == "/tflops": | ||
| 56 | Added: body = tflops() | ||
| 57 | Added: elif u.path in ("/alloc", "/managed"): | ||
| 58 | Added: body = alloc(float(q.get("gib", ["1"])[0]), managed=u.path == "/managed") | ||
| 59 | Added: elif u.path == "/free": | ||
| 60 | Added: HELD.clear(); torch.cuda.empty_cache(); body = {"freed": True} | ||
| 61 | Added: else: | ||
| 62 | Added: self.send_error(404); return | ||
| 63 | Added: code = 200 | ||
| 64 | Added: except Exception as e: # report, don't crash the probe target | ||
| 65 | Added: body, code = {"error": repr(e)}, 500 | ||
| 66 | Added: data = json.dumps(body).encode() | ||
| 67 | Added: self.send_response(code); self.send_header("Content-Type", "application/json") | ||
| 68 | Added: self.send_header("Content-Length", str(len(data))); self.end_headers(); self.wfile.write(data) | ||
| 69 | Added: | ||
| 70 | Added: | ||
| 71 | Added: ThreadingHTTPServer(("0.0.0.0", 7860), H).serve_forever() | ||