-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_gpu_benchmark_suite.sh
More file actions
executable file
Β·186 lines (149 loc) Β· 5.95 KB
/
Copy pathrun_gpu_benchmark_suite.sh
File metadata and controls
executable file
Β·186 lines (149 loc) Β· 5.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/bin/bash
# Complete GPU-Only Deep Learning Benchmark Script: Python vs Rust
# This script runs all working combinations systematically on GPU only
set -e
echo "π Starting COMPLETE GPU-ONLY Deep Learning Benchmark Suite"
echo "==========================================================="
echo "π― Target: All datasets + architectures on GPU for maximum performance"
echo ""
# Setup environment variables
export CUBLAS_WORKSPACE_CONFIG=:4096:8
export CUDA_VISIBLE_DEVICES=0
export LD_LIBRARY_PATH=/usr/lib/wsl/lib:$LD_LIBRARY_PATH
export LIBTORCH=/home/$USER/miniforge3/envs/cpp-torch
export PYTHONPATH=/home/shiro/Projects/Paper1
# Check CUDA availability
echo "π Checking CUDA availability..."
if nvidia-smi > /dev/null 2>&1; then
echo "β
CUDA GPU detected and ready"
nvidia-smi --query-gpu=name,memory.total --format=csv,noheader,nounits
else
echo "β No CUDA GPU found! This script requires GPU."
exit 1
fi
echo ""
# Function to run Python GPU benchmark
run_python_gpu_benchmark() {
local dataset=$1
local architecture=$2
local run_id="python_${dataset}_${architecture}_gpu_fixed"
echo "π Running Python GPU: $dataset + $architecture"
source .venv/bin/activate
python src/python/deep_learning/cnn_benchmark.py \
--dataset $dataset \
--architecture $architecture \
--mode training \
--run-id $run_id \
--device cuda
echo "β
Completed: $run_id"
echo ""
}
# Function to run Rust GPU benchmark
run_rust_gpu_benchmark() {
local dataset=$1
local architecture=$2
local run_id="rust_${dataset}_${architecture}_gpu_fixed"
echo "π¦ Running Rust GPU: $dataset + $architecture"
cd src/rust/deep_learning/cnn_benchmark
# Set proper library path for Rust + CUDA
export LD_LIBRARY_PATH=/home/$USER/miniforge3/envs/cpp-torch/lib:/usr/lib/wsl/lib:$LD_LIBRARY_PATH
cargo run --release -- \
--dataset $dataset \
--architecture $architecture \
--mode training \
--run-id $run_id \
--device cuda \
--epochs 10
cd ../../../../
echo "β
Completed: $run_id"
echo ""
}
# Function to run both Python and Rust for a combination
run_benchmark_pair() {
local dataset=$1
local architecture=$2
echo "π₯ BENCHMARKING: $dataset + $architecture (GPU)"
echo "------------------------------------------------"
# Run Python first
run_python_gpu_benchmark $dataset $architecture
# Run Rust second
run_rust_gpu_benchmark $dataset $architecture
echo "π Completed pair: $dataset + $architecture"
echo ""
}
# Function to copy results
copy_results() {
echo "π Copying all GPU benchmark results to project root..."
cp src/rust/deep_learning/cnn_benchmark/*_gpu_fixed_training_results.json . 2>/dev/null || true
echo "β
Results copied"
echo ""
}
# Main benchmark execution
echo "π― PHASE 1: SYNTHETIC DATASET - GPU BENCHMARKS"
echo "=============================================="
echo "--- Simple CNN on Synthetic Dataset (GPU) ---"
run_benchmark_pair synthetic simple_cnn
echo "--- ResNet18 on Synthetic Dataset (GPU) ---"
echo "π Running Python synthetic + resnet18 (GPU)..."
run_python_gpu_benchmark synthetic resnet18
echo "β οΈ Skipping Rust synthetic + resnet18 (channel mismatch: expects 3-ch, gets 1-ch)"
echo ""
echo ""
echo "π― PHASE 2: MNIST DATASET - GPU BENCHMARKS"
echo "=========================================="
echo "--- Simple CNN on MNIST Dataset (GPU) ---"
run_benchmark_pair mnist simple_cnn
echo "--- LeNet on MNIST Dataset (GPU) ---"
run_benchmark_pair mnist lenet
echo ""
echo "π― PHASE 3: CIFAR-10 DATASET - GPU BENCHMARKS"
echo "============================================="
echo "--- ResNet18 on CIFAR-10 Dataset (GPU) ---"
run_benchmark_pair cifar10 resnet18
echo "--- VGG16 on CIFAR-10 Dataset (GPU) ---"
echo "π Testing Python CIFAR-10 + VGG16..."
run_python_gpu_benchmark cifar10 vgg16 || echo "β οΈ Python VGG16 failed"
echo "π¦ Testing Rust CIFAR-10 + VGG16..."
run_rust_gpu_benchmark cifar10 vgg16 || echo "β οΈ Rust VGG16 failed"
echo ""
echo "π― PHASE 4: CIFAR-100 DATASET - GPU BENCHMARKS"
echo "==============================================="
echo "--- ResNet18 on CIFAR-100 Dataset (GPU) ---"
run_benchmark_pair cifar100 resnet18
echo ""
echo "π― PHASE 5: COLLECTING RESULTS"
echo "=============================="
copy_results
echo "π Listing all GPU benchmark result files:"
ls -la *_gpu_fixed_training_results.json 2>/dev/null || echo "No GPU fixed results found yet"
echo ""
echo "π GPU BENCHMARK SUITE COMPLETED!"
echo "================================="
echo ""
echo "π SUMMARY:"
total_benchmarks=$(ls -1 *_gpu_fixed_training_results.json 2>/dev/null | wc -l)
python_benchmarks=$(ls -1 python_*_gpu_fixed_training_results.json 2>/dev/null | wc -l)
rust_benchmarks=$(ls -1 rust_*_gpu_fixed_training_results.json 2>/dev/null | wc -l)
echo " π Total GPU benchmarks completed: $total_benchmarks"
echo " π Python GPU benchmarks: $python_benchmarks"
echo " π¦ Rust GPU benchmarks: $rust_benchmarks"
echo ""
echo "π Result files pattern: *_gpu_fixed_training_results.json"
echo "π Each file contains:"
echo " - Training time (seconds) - should be MUCH faster on GPU"
echo " - Memory usage (peak/average MB)"
echo " - Model accuracy (%) - Rust should be MUCH better now!"
echo " - GPU memory usage (MB)"
echo " - Loss values - Rust should have much lower loss now"
echo ""
echo "π EXPECTED IMPROVEMENTS with FIXED Rust:"
echo " β‘ Rust still 100x+ faster than Python"
echo " π― Rust accuracy should now be competitive (20-90%+)"
echo " π Rust loss should be much lower (~0.5-2.0 range)"
echo " πΎ Rust memory efficiency maintained"
echo ""
echo "π Next steps:"
echo " 1. Run: python3 analyze_results_simple.py"
echo " 2. Check the dramatic improvement in Rust accuracy/loss"
echo " 3. Celebrate the TRUE Python vs Rust showdown! π"
echo ""