-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.sh
executable file
·288 lines (257 loc) · 9.48 KB
/
script.sh
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#!/bin/bash
set -e
usage() {
echo "Usage: $0 [-a | -c -A|-B|-C|-D|-E|-t | -l | -b | -d <3|5|7> <32|64|128|256> | -d -t]"
echo " -a Check accuracy"
echo " -c -A Run CNN network A"
echo " -c -B Run CNN network B"
echo " -c -C Run CNN network C"
echo " -c -D Run CNN network D"
echo " -c -E Run CNN network E"
echo " -c -t Run all CNN networks sequentially"
echo " -l Run LeNet Model"
echo " -b Run baby-step-giant-step algorithm to precompute the table"
echo " -d <3|5|7> <32|64|128|256> Run server and client with specified filter size and image size"
echo " -d -t Run all convolution experiments sequentially for all combinations of filter sizes (3,5,7) and image sizes (32,64,128,256)"
exit 1
}
if [ $# -lt 1 ]; then
usage
fi
# Set the project directory to the current working directory.
PROJECT_DIR=$(pwd)
# Default port numbers for different experiments.
DEFAULT_PORT_CNN_A=35000
DEFAULT_PORT_CNN_B=35001
DEFAULT_PORT_CNN_C=35002
DEFAULT_PORT_CNN_D=35003
DEFAULT_PORT_CNN_E=35004
DEFAULT_PORT_LENET=35005
DEFAULT_PORT_CONV=35006
# Default base ports for batch experiments
DEFAULT_BASE_PORT_CNN=36000
DEFAULT_BASE_PORT_CONV=37000
# Define the log directory globally
LOG_DIR="$PROJECT_DIR/logs"
mkdir -p "$LOG_DIR"
# QUIET_MODE=1 (default) logs outputs to files, suppressing terminal output. Set to 0 for verbose terminal display.
QUIET_MODE=1
# Function to run server and client for the specified CNN network version.
run_server_and_client() {
local version=$1
local port=$2
local network_label
case $version in
1)
network_label="A"
;;
2)
network_label="B"
;;
3)
network_label="C"
;;
4)
network_label="D"
;;
5)
network_label="E"
;;
*)
echo "Invalid version number: $version"
exit 1
;;
esac
local datetime=$(date +%Y%m%d-%H%M%S)
local logfile="${LOG_DIR}/${network_label}_Run_$datetime.log"
echo "Running server.py and client.py for CNN network $network_label on port $port..."
if [ "$QUIET_MODE" -eq 1 ]; then
if ss -tuln | grep -q ":$port "; then
echo "Alert: Port $port is busy. Please select a different port."
else
echo "Port $port is available."
fi
python3 "$PROJECT_DIR/src/cnn_networks/Server.py" "$version" "$port" &> /dev/null &
SERVER_PID=$!
sleep 2
python3 "$PROJECT_DIR/src/cnn_networks/Client.py" "$port" &> /dev/null
wait $SERVER_PID
echo "Navigating to proof generation directory..."
cd "$PROJECT_DIR/src/proof_generation/vPIN_proof_generation/src"
echo "Generating Proof..."
cargo run -- $network_label >"$logfile" 2>/dev/null
echo -e "Proof generated, check logfile ${network_label}_Run_$datetime.log for seeing the result.\n"
else
python3 "$PROJECT_DIR/src/cnn_networks/Server.py" "$version" "$port" &
SERVER_PID=$!
sleep 2
python3 "$PROJECT_DIR/src/cnn_networks/Client.py" "$port"
wait $SERVER_PID
echo "Navigating to proof generation directory..."
cd "$PROJECT_DIR/src/proof_generation/vPIN_proof_generation/src"
echo "Generating Proof..."
cargo run -- $network_label | tee /dev/tty | grep -v 'warning' > "$logfile"
fi
}
run_all_experiments() {
echo "Running all CNN networks sequentially..."
for i in {1..5}; do
# Calculate the port based on the base port and the index
local port=$(($DEFAULT_BASE_PORT_CNN + ($i - 1)))
run_server_and_client $i $port
done
}
# Function to run server and client with the specified filter and image sizes.
run_server_and_client2() {
local version=$1
local size=$2
local port=$3
if [[ ! "$version" =~ ^(3|5|7)$ ]]; then
echo "Invalid version number: $version. Allowed values are 3, 5, or 7."
exit 1
fi
if [[ ! "$size" =~ ^(32|64|128|256)$ ]]; then
echo "Invalid size: $size. Allowed values are 32, 64, 128, or 256."
exit 1
fi
local datetime=$(date +%Y%m%d-%H%M%S)
local logfile="${LOG_DIR}/Convolution_${version}_${size}_Run_$datetime.log"
echo "Running server.py with filter size $version and client.py with image size $size on port $port..."
if [ "$QUIET_MODE" -eq 1 ]; then
if ss -tuln | grep -q ":$port "; then
echo "Alert: Port $port is busy. Please select a different port."
else
echo "Port $port is available."
fi
python3 "$PROJECT_DIR/src/convolution/Server.py" "$version" "$port" "$size" &> /dev/null &
SERVER_PID=$!
sleep 2
python3 "$PROJECT_DIR/src/convolution/Client.py" "$size" "$port" &> /dev/null
wait $SERVER_PID
echo "Navigating to proof generation directory..."
cd "$PROJECT_DIR/src/proof_generation/vPIN_proof_generation/src"
echo "Generating Proof..."
cargo run -- "${version}_${size}" >"$logfile" 2>/dev/null
echo -e "Proof generated, check logfile Convolution_${version}_${size}_Run_$datetime.log for seeing the result.\n"
else
python3 "$PROJECT_DIR/src/convolution/Server.py" "$version" "$port" "$size" &
SERVER_PID=$!
sleep 2
python3 "$PROJECT_DIR/src/convolution/Client.py" "$size" "$port"
wait $SERVER_PID
echo "Navigating to proof generation directory..."
cd "$PROJECT_DIR/src/proof_generation/vPIN_proof_generation/src"
echo "Generating Proof..."
cargo run -- "${version}_${size}" | tee /dev/tty | grep -v 'warning' > "$logfile"
fi
}
# Function to run all convolution experiments sequentially
run_all_convolution_experiments() {
echo "Running all convolution experiments sequentially..."
local index=0
for filter_size in 3 5 7; do
for input_size in 32 64 128 256; do
local port=$(($DEFAULT_BASE_PORT_CONV + $index))
run_server_and_client2 "$filter_size" "$input_size" "$port"
index=$(($index + 1))
done
done
}
# Function to run the LeNet model server and client.
run_server_and_client3() {
local port=$1
echo "Running LeNet Model (server.py and client.py) on port $port..."
if [ "$QUIET_MODE" -eq 1 ]; then
if ss -tuln | grep -q ":$port "; then
echo "Alert: Port $port is busy. Please select a different port."
else
echo "Port $port is available."
fi
python3 "$PROJECT_DIR/src/LeNet/Server.py" "$port" &> /dev/null &
SERVER_PID=$!
sleep 2
python3 "$PROJECT_DIR/src/LeNet/Client.py" "$port" &> /dev/null
wait $SERVER_PID
echo "Navigating to proof generation directory..."
cd "$PROJECT_DIR/src/proof_generation/vPIN_proof_generation/src"
# Loop to generate proofs for each layer L1 to L7
for i in {1..7}; do
local layer="L$i"
echo "Generating Proof for $layer..."
local datetime=$(date +%Y%m%d-%H%M%S)
local logfile="${LOG_DIR}/LeNet_${layer}_Run_$datetime.log"
cargo run -- "$layer" >"$logfile" 2>/dev/null
echo -e "Proof generated, check logfile LeNet_${layer}_Run_$datetime.log for seeing the result.\n"
done
else
python3 "$PROJECT_DIR/src/LeNet/Server.py" "$port" &
SERVER_PID=$!
sleep 2
python3 "$PROJECT_DIR/src/LeNet/Client.py" "$port"
wait $SERVER_PID
echo "Navigating to proof generation directory..."
cd "$PROJECT_DIR/src/proof_generation/vPIN_proof_generation/src"
# Loop to generate proofs for each layer L1 to L7
for i in {1..7}; do
local layer="L$i"
echo "Generating Proof for $layer..."
local datetime=$(date +%Y%m%d-%H%M%S)
local logfile="${LOG_DIR}/LeNet_${layer}_Run_$datetime.log"
cargo run -- "$layer" | tee /dev/tty | grep -v 'warning' > "$logfile"
done
fi
}
# Main script execution based on provided command-line arguments.
case $1 in
-a)
echo "Running accuracy/train_test_lenet5.py..."
python3 "$PROJECT_DIR/src/accuracy/train_test_lenet5.py"
;;
-c)
if [ $# -ne 2 ]; then
usage
fi
case $2 in
-A)
run_server_and_client 1 $DEFAULT_PORT_CNN_A
;;
-B)
run_server_and_client 2 $DEFAULT_PORT_CNN_B
;;
-C)
run_server_and_client 3 $DEFAULT_PORT_CNN_C
;;
-D)
run_server_and_client 4 $DEFAULT_PORT_CNN_D
;;
-E)
run_server_and_client 5 $DEFAULT_PORT_CNN_E
;;
-t)
run_all_experiments
;;
*)
usage
;;
esac
;;
-l)
run_server_and_client3 $DEFAULT_PORT_LENET
;;
-b)
echo "Running baby-step-giant-step.py..."
python3 "$PROJECT_DIR/src/Pre_computed_table/baby-step-giant-step.py"
;;
-d)
if [ $# -ne 3 ] && [ "$2" != "-t" ]; then
usage
elif [ "$2" == "-t" ]; then
run_all_convolution_experiments
fi
run_server_and_client2 $2 $3 $DEFAULT_PORT_CONV
;;
*)
usage
;;
esac
echo "Script execution completed."