This repository was archived by the owner on Jan 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecute_hinnperf_podman.sh
More file actions
executable file
·170 lines (142 loc) · 5.16 KB
/
execute_hinnperf_podman.sh
File metadata and controls
executable file
·170 lines (142 loc) · 5.16 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
#!/bin/bash
ROOT_DIR=/tmp/${USER}_hinnperf
mkdir -p $ROOT_DIR
export XDG_RUNTIME_DIR="$ROOT_DIR"
export HOME="$ROOT_DIR"
# Definition of constants
PODMAN_ROOT="$ROOT_DIR/podman-images/"
CONTAINER_DATA_ROOT="/data"
CONTAINER_A_FILE_LOCATION="$CONTAINER_DATA_ROOT/learn.a"
CONTAINER_EVALUATION_FILE_LOCATION="$CONTAINER_DATA_ROOT/evaluation.csv"
CONTAINER_ALL_FILE_LOCATION="$CONTAINER_DATA_ROOT/all.csv"
CONTAINER_HYPERPARAMETER_FILE_LOCATION="$CONTAINER_DATA_ROOT/hyperparameter_results.csv"
CONTAINER_LOG_FILE="$CONTAINER_DATA_ROOT/result.log"
CONTAINER_LOG_ERROR_FILE="$CONTAINER_DATA_ROOT/result.log_error"
CONTAINER_SCRIPT_LOCATION="/application/HINNPerf/execute_learning.py"
A_FILE_LOCATION="$ROOT_DIR/learn.a"
REMOVE_LOCAL_COPY=false
CURRENT_SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
# Definition of functions
parse_arguments () {
# Read in the arguments
POSITIONAL_ARGS=()
while [[ $# -gt 0 ]]; do
case $1 in
-e)
EVALUATION_FILE="$2"
shift # past argument
shift # past value
;;
-a)
ALL_FILE="$2"
shift # past argument
shift # past value
;;
-f)
HYPERPARAMETER_CSV_RESULT_FILE="$2"
shift # past argument
shift # past value
;;
-l)
LOG_FILE="$2"
shift # past argument
shift # past value
;;
--remove-images)
REMOVE_LOCAL_COPY=true
shift # past argument
;;
-*|--*)
echo "Unknown option $1"
exit 1
;;
*)
POSITIONAL_ARGS+=("$1") # save positional arg
shift # past argument
;;
esac
done
LEARNING_OPTIONS="${POSITIONAL_ARGS[@]}"
set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters
echo "Evaluation set file: $EVALUATION_FILE"
echo "All file: $ALL_FILE"
echo "Path to csv for hyperparameter tuning: $HYPERPARAMETER_CSV_RESULT_FILE"
echo "Log file: $LOG_FILE"
echo "Learning options: $LEARNING_OPTIONS"
if [ ! -z $HYPERPARAMETER_CSV_RESULT_FILE ]
then
echo "Performing hyperparameter tuning!"
else
echo "Performing normal learning!"
fi
if [ "$REMOVE_LOCAL_COPY" = true ]
then
echo "Local copy will be removed afterwards"
else
echo "Local copy will NOT be removed afterwards"
fi
}
create_a_file () {
# Overwrite the a file
echo "" > $A_FILE_LOCATION
echo "all $CONTAINER_ALL_FILE_LOCATION" >> $A_FILE_LOCATION
echo "evaluationset $CONTAINER_EVALUATION_FILE_LOCATION" >> $A_FILE_LOCATION
if [ ! -z $HYPERPARAMETER_CSV_RESULT_FILE ]
then
echo "learn-opt file:$CONTAINER_HYPERPARAMETER_FILE_LOCATION $LEARNING_OPTIONS" >> $A_FILE_LOCATION
else
echo "learn $LEARNING_OPTIONS" >> $A_FILE_LOCATION
fi
}
main () {
# First, parse arguments
parse_arguments $@
# Create the automation script that is used by the HINNPerf implementation in the container
create_a_file
# After reading in, execute the script
PODMAN_COMMAND="podman --root=$PODMAN_ROOT "
if [ ! -d $PODMAN_ROOT ]
then
echo "Building the container locally"
$PODMAN_COMMAND build -t hinnperf ${CURRENT_SCRIPT_DIR}
fi
# Start the container in detached mode
echo "Starting the container"
container_id=$($PODMAN_COMMAND run -d -t hinnperf /bin/bash)
# Create the data root directory
echo "Creating data root directory"
$PODMAN_COMMAND exec -it $container_id mkdir -p $CONTAINER_DATA_ROOT
# Copy the necessary files
echo "Copying necessary data into the container"
$PODMAN_COMMAND cp $A_FILE_LOCATION $container_id:$CONTAINER_A_FILE_LOCATION
$PODMAN_COMMAND cp $ALL_FILE $container_id:$CONTAINER_ALL_FILE_LOCATION
$PODMAN_COMMAND cp $EVALUATION_FILE $container_id:$CONTAINER_EVALUATION_FILE_LOCATION
# Execution of the learning/hyperparameter tuning process
# Redirect output to log file and log_error file
echo "Executing learning procedure"
echo "$PODMAN_COMMAND exec -it $container_id /bin/bash -c python $CONTAINER_SCRIPT_LOCATION $CONTAINER_A_FILE_LOCATION > $CONTAINER_LOG_FILE 2> $CONTAINER_LOG_ERROR_FILE"
$PODMAN_COMMAND exec -it $container_id /bin/bash -c "python $CONTAINER_SCRIPT_LOCATION $CONTAINER_A_FILE_LOCATION > $CONTAINER_LOG_FILE 2> $CONTAINER_LOG_ERROR_FILE"
rm $A_FILE_LOCATION
# Copy log files
echo "Copying results from container to destination"
$PODMAN_COMMAND cp $container_id:$CONTAINER_LOG_FILE $LOG_FILE
$PODMAN_COMMAND cp $container_id:$CONTAINER_LOG_ERROR_FILE ${LOG_FILE}_error
if [ ! -z $HYPERPARAMETER_CSV_RESULT_FILE ]
then
$PODMAN_COMMAND cp $container_id:$CONTAINER_HYPERPARAMETER_FILE_LOCATION $HYPERPARAMETER_CSV_RESULT_FILE
fi
# Stop the container
echo "Stopping container"
$PODMAN_COMMAND container stop $container_id
# Remove the container
echo "Removing container"
$PODMAN_COMMAND container rm $container_id
if [ "$REMOVE_LOCAL_COPY" = true ]
then
echo "Removing local podman directory"
$PODMAN_COMMAND rm -a
$PODMAN_COMMAND image prune -a -f
rm -r $PODMAN_ROOT
fi
}
main $@