-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquick_benchmark.sh
More file actions
executable file
·119 lines (96 loc) · 4.11 KB
/
quick_benchmark.sh
File metadata and controls
executable file
·119 lines (96 loc) · 4.11 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
#!/bin/bash
# Quick Benchmark Runner Script for Rust vs Python Deep Learning
set -e # Exit on any error
PROJECT_ROOT="$(pwd)"
echo "🚀 Starting Rust vs Python Deep Learning Benchmarks"
echo "📍 Project root: $PROJECT_ROOT"
# Verify CUDA availability
echo "🔍 Checking CUDA availability..."
nvidia-smi > /dev/null || { echo "❌ NVIDIA drivers not available"; exit 1; }
echo "✅ CUDA available"
# Set common 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 LD_LIBRARY_PATH="$LIBTORCH/lib:$LD_LIBRARY_PATH"
# Function to run Python benchmark
run_python_benchmark() {
local device=$1
local run_id="python_cnn_${device}_quick"
echo "🐍 Running Python $device benchmark..."
source .venv/bin/activate
PYTHONPATH="$PROJECT_ROOT" python src/python/deep_learning/cnn_benchmark.py \
--dataset synthetic \
--architecture simple_cnn \
--mode training \
--run-id "$run_id" \
--device "$device"
echo "✅ Python $device benchmark completed"
}
# Function to run Rust benchmark
run_rust_benchmark() {
local device=$1
local run_id="rust_cnn_${device}_quick"
echo "🦀 Running Rust $device benchmark..."
cd "$PROJECT_ROOT/src/rust/deep_learning/cnn_benchmark"
cargo run --release -- \
--dataset synthetic \
--architecture simple_cnn \
--mode training \
--run-id "$run_id" \
--device "$device"
cd "$PROJECT_ROOT"
echo "✅ Rust $device benchmark completed"
}
# Function to show results summary
show_results() {
echo ""
echo "📊 BENCHMARK RESULTS SUMMARY"
echo "=================================================="
for result_file in synthetic_simple_cnn_*_quick_training_results.json; do
if [[ -f "$result_file" ]]; then
echo "📄 $result_file:"
# Extract key metrics using jq or fallback to grep
if command -v jq >/dev/null 2>&1; then
training_time=$(jq -r '.performance_metrics.training_time_seconds' "$result_file")
accuracy=$(jq -r '.quality_metrics.accuracy' "$result_file")
memory=$(jq -r '.resource_metrics.peak_memory_mb' "$result_file")
device=$(jq -r '.metadata.device' "$result_file")
printf " ⏱️ Training Time: %.2fs\n" "$training_time"
printf " 🎯 Accuracy: %.1f%%\n" "$(echo "$accuracy * 100" | bc -l)"
printf " 💾 Peak Memory: %.0fMB\n" "$memory"
printf " ⚙️ Device: %s\n" "$device"
else
echo " 📋 Raw results (install jq for formatted display):"
grep -E "(training_time_seconds|accuracy|peak_memory_mb|device)" "$result_file" | head -4
fi
echo ""
fi
done
# Find result files
python_gpu=$(find . -name "*python*gpu*quick*.json" | head -1)
python_cpu=$(find . -name "*python*cpu*quick*.json" | head -1)
rust_gpu=$(find . -name "*rust*gpu*quick*.json" | head -1)
rust_cpu=$(find . -name "*rust*cpu*quick*.json" | head -1)
if [[ -f "$python_gpu" && -f "$rust_gpu" && command -v jq >/dev/null 2>&1 ]]; then
py_gpu_time=$(jq -r '.performance_metrics.training_time_seconds' "$python_gpu")
rust_gpu_time=$(jq -r '.performance_metrics.training_time_seconds' "$rust_gpu")
speedup=$(echo "scale=1; $py_gpu_time / $rust_gpu_time" | bc -l)
echo "🏆 WINNER: Rust GPU is ${speedup}x faster than Python GPU!"
fi
}
# Main execution
echo "🏁 Starting benchmark suite..."
# Run all benchmarks
run_python_benchmark "gpu"
run_python_benchmark "cpu"
run_rust_benchmark "gpu"
run_rust_benchmark "cpu"
# Show results
show_results
echo ""
echo "🎉 All benchmarks completed successfully!"
echo "📁 Result files are in the current directory with suffix '_quick_training_results.json'"
echo ""
echo "🔗 For detailed setup instructions, see: DEEP_LEARNING_BENCHMARK_GUIDE.md"