AdriBat1 commited on
Commit
9454b45
·
1 Parent(s): 2d1b6e6

Add GPU benchmark script, Julia set generator, and updated docs

Browse files
remote-gpu-client/bench_gpu.py ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import time
3
+ import matplotlib
4
+ matplotlib.use('Agg')
5
+ import matplotlib.pyplot as plt
6
+ import os
7
+ import sys
8
+ import numpy as np
9
+
10
+ def run_benchmark():
11
+ print("=" * 60)
12
+ print(f"🚀 SYSTEM BENCHMARK on {os.uname().nodename}")
13
+ print("=" * 60)
14
+
15
+ print(f"Python: {sys.version.split()[0]}")
16
+ print(f"PyTorch: {torch.__version__}")
17
+
18
+ cuda_available = torch.cuda.is_available()
19
+ if cuda_available:
20
+ gpu_name = torch.cuda.get_device_name(0)
21
+ print(f"✅ GPU DETECTED: {gpu_name}")
22
+ print(f" Memory: {torch.cuda.get_device_properties(0).total_memory / 1024**3:.2f} GB")
23
+ else:
24
+ print("⚠️ NO GPU DETECTED. Running on CPU.")
25
+ print(" (To enable GPU, switch Hardware in HF Space settings)")
26
+
27
+ print("-" * 60)
28
+
29
+ times = {}
30
+
31
+ # MATRIX SIZE
32
+ N = 4000
33
+
34
+ # CPU TEST
35
+ print(f"1️⃣ CPU Test ({N}x{N} Matrix Mul)...")
36
+ start_time = time.time()
37
+ a_cpu = torch.randn(N, N)
38
+ b_cpu = torch.randn(N, N)
39
+ c_cpu = torch.matmul(a_cpu, b_cpu)
40
+ cpu_time = time.time() - start_time
41
+ times['CPU'] = cpu_time
42
+ print(f" ⏱️ Time: {cpu_time:.4f} seconds")
43
+
44
+ # GPU TEST
45
+ if cuda_available:
46
+ print(f"2️⃣ GPU Test ({N}x{N} Matrix Mul)...")
47
+ # Warmup
48
+ torch.matmul(torch.randn(100,100).cuda(), torch.randn(100,100).cuda())
49
+
50
+ start_time = time.time()
51
+ a_gpu = torch.randn(N, N).cuda()
52
+ b_gpu = torch.randn(N, N).cuda()
53
+ # Synchronize for accurate timing
54
+ torch.cuda.synchronize()
55
+ start_computation = time.time()
56
+ c_gpu = torch.matmul(a_gpu, b_gpu)
57
+ torch.cuda.synchronize()
58
+ gpu_time = time.time() - start_computation
59
+ times['GPU'] = gpu_time
60
+ print(f" ⏱️ Time: {gpu_time:.4f} seconds")
61
+
62
+ speedup = cpu_time / gpu_time
63
+ print(f" 🚀 SPEEDUP: {speedup:.2f}x")
64
+ else:
65
+ print("2️⃣ GPU Test SKIPPED (No CUDA)")
66
+ times['GPU'] = 0
67
+
68
+ # PLOT
69
+ print("-" * 60)
70
+ print("Creating comparison chart...")
71
+ plt.figure(figsize=(10, 6))
72
+
73
+ models = list(times.keys())
74
+ durations = list(times.values())
75
+ colors = ['gray', 'green'] if cuda_available else ['gray', 'red']
76
+
77
+ bars = plt.bar(models, durations, color=colors)
78
+ plt.ylabel('Secons (Lower is better)')
79
+ plt.title(f'Benchmark CPU vs GPU ({N}x{N} Matrix Mul)\n{gpu_name if cuda_available else "CPU Only"}')
80
+
81
+ for bar in bars:
82
+ yval = bar.get_height()
83
+ if yval > 0:
84
+ plt.text(bar.get_x() + bar.get_width()/2, yval, f'{yval:.4f}s', ha='center', va='bottom')
85
+
86
+ filename = "gpu_benchmark.png"
87
+ plt.savefig(filename)
88
+ print(f"💾 Saved to {filename}")
89
+
90
+ if __name__ == "__main__":
91
+ run_benchmark()
remote-gpu-client/julia.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import matplotlib
2
+ matplotlib.use('Agg')
3
+ import matplotlib.pyplot as plt
4
+ import numpy as np
5
+ import time
6
+ import os
7
+
8
+ print(f"🚀 Starting Julia Set Generation on {os.uname().nodename}...")
9
+
10
+ def julia_set(h, w, c, max_iter=100):
11
+ """Generate Julia set for a given complex parameter c."""
12
+ y, x = np.ogrid[-1.5:1.5:h*1j, -1.5:1.5:w*1j]
13
+ z = x + y*1j
14
+ divtime = max_iter + np.zeros(z.shape, dtype=int)
15
+
16
+ for i in range(max_iter):
17
+ z = z**2 + c
18
+ diverge = z*np.conj(z) > 2**2
19
+ div_now = diverge & (divtime == max_iter)
20
+ divtime[div_now] = i
21
+ z[diverge] = 2
22
+
23
+ return divtime
24
+
25
+ # Configuration
26
+ H, W = 1000, 1500
27
+ MAX_ITER = 200
28
+ # Interesting Julia set parameter
29
+ C = complex(-0.7, 0.27015)
30
+
31
+ print(f"Computing Julia set ({W}x{H}) for c={C}...")
32
+ start_time = time.time()
33
+
34
+ divtime = julia_set(H, W, C, MAX_ITER)
35
+
36
+ compute_time = time.time() - start_time
37
+ print(f"✅ Computation done in {compute_time:.4f}s")
38
+
39
+ # Plot
40
+ print("Rendering image...")
41
+ plt.figure(figsize=(15, 10))
42
+ plt.imshow(divtime, cmap='twilight', extent=[-1.5, 1.5, -1.5, 1.5])
43
+ plt.axis('off')
44
+ plt.title(f'Julia Set c={C} (Compute: {compute_time:.2f}s)')
45
+
46
+ filename = "julia_gpu.png"
47
+ plt.savefig(filename, bbox_inches='tight', pad_inches=0, dpi=150)
48
+ print(f"💾 Saved to {filename}")