-
Notifications
You must be signed in to change notification settings - Fork 35
/
metamake.sh
executable file
·238 lines (219 loc) · 6.1 KB
/
metamake.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
#!/bin/bash
# Initialize the commandline options and flags
use_cuda=0
use_profiler=0
use_gtest=0
use_gcc=0
use_clang=0
use_mpi=0
use_asan=0
use_opt=1
use_debug=0
ENSEMBLES=""
CMAKEARGS=""
# Check if nvcc is available
if command -v nvcc &> /dev/null
then
use_cuda=1
nvcc_version=($(python scripts/get_cuda_version.py))
if [ -z "$nvcc_version" ]
then
echo "python command not on path. trying python3"
nvcc_version=($(python3 scripts/get_cuda_version.py))
if [ -z "$nvcc_version" ]
then
echo "python3 command not on path. Please install/add to path. Exiting..."
exit 1
else
echo "python3 found"
fi
fi
# Check cuda version, if less than 11 then download CUB, otherwise skip
if [[ "$nvcc_version" < "11" ]]
then
# Check if ./lib/cub exists
if [ ! -d "./lib/cub" ]; then
cd lib
mkdir -p temp
cd temp
echo "==== GOMC needs CUB library to run..."
echo "==== Finding latest CUB library..."
# Find the link
LINK=$(curl -s https://api.github.com/repos/NVIDIA/cub/releases/latest | grep "zip" | cut -d : -f 2,3 | tr -d \",\ )
echo "==== Link found at ${LINK}"
# download the zip file
echo "==== Downloading the CUB library... (Shouldn't take too long)"
wget -O cub.zip "${LINK}" > /dev/null 2>&1
#unzip
echo "==== Extracting the CUB library..."
unzip cub.zip > /dev/null 2>&1
# move the cub directory to and remove the rest
mv */cub ../cub
rm -rf NVIDIA*
rm cub.zip
cd ..
rmdir temp
cd ..
else
echo "==== cub library already exists. Skipping..."
fi
else
echo "CUDA version is 11.0 or higher, no need to download CUB library! Skipping..."
rm -rf ./lib/cub/
fi
fi
while getopts 'acdglmnpt' opt; do
case "$opt" in
a)
use_asan=1;;
c)
CMAKEARGS+="-DGOMC_TIDY=on ";;
d)
use_debug=1;;
g)
use_gcc=1;;
l)
use_clang=1;;
m)
use_mpi=1
CMAKEARGS+="-DGOMC_MPI=on ";;
n)
use_opt=0;;
p)
use_profiler=1;;
t)
use_gtest=1
use_gcc=1;;
*) echo 'Error in command line options' >&2
echo "Available options are: "
echo "-a, enables address sanitizer runtime checking"
echo "-c, enables clang-tidy source code checks"
echo "-d, enables Debug Mode compilation"
echo "-g, use the GNU compiler"
echo "-l, use the Clang compiler"
echo "-m, enables MPI support (Required for Parallel Tempering)"
echo "-n, disables most compiler optimization flags"
echo "-p enables GPU code profiling (NVTX tags)"
echo "-t disables Intel compiler to allow GTests to compile"
echo "For combined usage, concatenate flags, e.g.: -ptmg"
exit 1
esac
done
shift "$(( OPTIND - 1 ))"
while [ "$#" -ne 0 ]; do
if [[ "$1" == 'CPU' ]]; then
ENSEMBLES+="NVT NPT GCMC GEMC "
shift
continue
fi
if [[ "$1" == 'GPU' ]]; then
ENSEMBLES+="GPU_NVT GPU_NPT GPU_GCMC GPU_GEMC "
shift
continue
fi
case "$1" in
NVT|NPT|GCMC|GEMC|GPU_NVT|GPU_NPT|GPU_GCMC|GPU_GEMC) # or just: -t|--t*)
ENSEMBLES+="$1 ";;
[!-]*) echo 'Error in Ensembles' >&2
echo 'Valid Options: {NVT|NPT|GCMC|GEMC|GPU_NVT|GPU_NPT|GPU_GCMC|GPU_GEMC}' >&2
exit 1;;# non-option detected, break out of loop
--) shift; break ;; # explicit end of options detected, break
*) echo 'Error in command line options' >&2
exit 1
esac
shift
done
# If user hasn't specified any ensemble, cmake automatically compiles all ensembles.
# This will ensure we don't print empty for ensembles.
if [ -z "$ENSEMBLES" ];
then
ENSEMBLES="NVT NPT GCMC GEMC "
if (( use_cuda ))
then
ENSEMBLES+="GPU_NVT GPU_NPT GPU_GCMC GPU_GEMC "
fi
fi
mkdir -p bin
cd bin
if (( !use_gtest )); then
if (( !use_gcc && !use_clang ));
then
# comment out this check until CUDA supports the newer Intel Compiler
# ICC_PATH="$(which icx 2> /dev/null)"
# ICPC_PATH="$(which icpx 2> /dev/null)"
# if [ -z "$ICC_PATH" ]
# then
ICC_PATH="$(which icc 2> /dev/null)"
ICPC_PATH="$(which icpc 2> /dev/null)"
# fi
if [ -z "$ICC_PATH" ]
then
export CC="$(which gcc 2> /dev/null)"
export CXX="$(which g++ 2> /dev/null)"
else
if (( use_asan )); then
echo "Warning: Address sanitizer unset. Not compatible with the Intel compiler."
use_asan=0
fi
export CC=${ICC_PATH}
export CXX=${ICPC_PATH}
fi
elif (( use_clang )); then
CLANG_PATH="$(which clang 2> /dev/null)"
CLANGXX_PATH="$(which clang++ 2> /dev/null)"
if [ -z "$CLANG_PATH" ]
then
export CC="$(which gcc 2> /dev/null)"
export CXX="$(which g++ 2> /dev/null)"
else
export CC=${CLANG_PATH}
export CXX=${CLANGXX_PATH}
fi
else
export CC="$(which gcc 2> /dev/null)"
export CXX="$(which g++ 2> /dev/null)"
fi
else
if (( use_mpi ));
then
TESTENS=""
for ENS in $ENSEMBLES
do
TESTENS+="GOMC_${ENS}_MPI_Test "
done
ENSEMBLES+=$TESTENS
CMAKEARGS+="-DGOMC_GTEST_MPI=on "
else
TESTENS=""
for ENS in $ENSEMBLES
do
TESTENS+="GOMC_${ENS}_Test "
done
ENSEMBLES+=$TESTENS
CMAKEARGS+="-DGOMC_GTEST=on "
fi
export CC="$(which gcc 2> /dev/null)"
export CXX="$(which g++ 2> /dev/null)"
fi
echo "Ensembles To Compile: $ENSEMBLES"
if (( use_profiler )); then
if (( use_cuda )); then
echo "Enabling NVTX profiling for CUDA "
CMAKEARGS+="-DGOMC_NVTX_ENABLED=on "
else
echo "Warning: Cannot enable NVTX profiling without CUDA enabled."
fi
fi
if (( use_asan )); then
use_debug=1
CMAKEARGS+="-DGOMC_ASAN=on "
fi
if (( use_opt )); then
CMAKEARGS+="-DGOMC_OPT=on "
fi
if (( use_debug )); then
echo "Enabling Debug Compilation "
CMAKEARGS+="-DCMAKE_BUILD_TYPE=Debug "
fi
cmake .. $CMAKEARGS
make -j8 $ENSEMBLES