-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbuild.sh
More file actions
207 lines (181 loc) · 6.15 KB
/
Copy pathbuild.sh
File metadata and controls
207 lines (181 loc) · 6.15 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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/bin/bash
# Installing the plugins requires 'sudo' privileges to modify an external
# directory. It will ask for your password.
install_plugins=false
# The tests will only run if `make test` is called from the same script that
# invoked `make install`. If '--install-plugins' is not set, tests will fail.
run_all_tests=false
# Only run tests that give you useful feedback in a reasonable amount of time.
# On the reference system (32-core M1 Max, 32 GB), this means tests that take
# less than ~20 seconds.
run_most_tests=false
# Only run tests that give you useful feedback in a short amount of time.
# On the reference system (32-core M1 Max, 32 GB), this means tests that take
# less than ~5 seconds.
run_quick_tests=false
# TODO: After incorporating mixed precision, re-partition the test suite.
# Very quick tests: ones that routinely fail when something is wrong
# TestMetalCheckpointsSingle
# TestMetalDispersionPMESingle
# TestMetalEwaldSingle
# TestMetalGBSAOBCForceSingle
# Use cmake -R to run these tests, otherwise compiling the same as --quick-tests.
if [[ $# != 0 ]]; then
invalid_input=false
if [[ $# -gt 3 ]]; then
echo "Too many arguments."
invalid_input=true
fi
if [[ $invalid_input == false ]]; then
for param in "$@"; do
if [[ $param == "--install" ]]; then
if [[ $install_plugin == true ]]; then
echo "Duplicate argument '--install'."
invalid_input=true
else
install_plugins=true
fi
elif [[ $param == "--all-tests" ]]; then
if [[ $run_all_tests == true ]]; then
echo "Duplicate argument '--all-tests'."
invalid_input=true
else
run_all_tests=true
fi
elif [[ $param == "--most-tests" ]]; then
if [[ $run_all_tests == true ]]; then
echo "Duplicate argument '--most-tests'."
invalid_input=true
else
run_most_tests=true
fi
elif [[ $param == "--quick-tests" ]]; then
if [[ $run_all_tests == true ]]; then
echo "Duplicate argument '--quick-tests'."
invalid_input=true
else
run_quick_tests=true
fi
else
echo "Unrecognized argument '${param}'."
invalid_input=true
fi
done
fi
if [[ $invalid_input == true ]]; then
echo "Usage: build.sh [--install] [--all-tests] [--most-tests] [--quick-tests]"
exit -1
fi
fi
if [[ ! -d ".build" ]]; then
mkdir ".build"
fi
if [[ ! -d ".build" ]]; then
echo "Malformed .build directory"
exit -1
fi
cd ".build"
touch "python_messaging.txt"
# Check that OpenMM is installed.
echo '
message = "success"
try:
import openmm
except ImportError:
message = "failure"
f = open("python_messaging.txt", "w")
f.write(message)
f.close()
' > "python_script.py"
python python_script.py
if [[ "success" != `cat python_messaging.txt` ]]; then
# If this fails, try replacing 'python python_script.py' with 'python3
# python_script.py'. The last one was what worked originally. Now, the first
# one works and the last one doesn't.
echo "OpenMM not installed."
exit -1
fi
# Extract OpenMM version.
echo '
import openmm
f = open("python_messaging.txt", "w")
f.write(openmm.version.version)
f.close()
' > "python_script.py"
python python_script.py
openmm_version=`cat python_messaging.txt`
old_IFS=$IFS
IFS='.'
read -a strarr <<< "$openmm_version"
openmm_version_major=$((strarr[0] + 0)) # Force convert to integer.
openmm_version_minor=$((strarr[1] + 0)) # Force convert to integer.
IFS=$old_IFS
# TODO: Require OpenMM 8.1.0 when the HIP workaround is removed.
if [[ $openmm_version_major -lt 8 ]]; then
echo "OpenMM must be version 8.0.0 or higher."
exit -1
fi
if [[ $openmm_version_major == 8 ]]; then
if [[ $openmm_version_minor -lt 0 ]]; then
echo "OpenMM must be version 8.0.0 or higher."
exit -1
fi
fi
# Extract OpenMM install location.
# WARNING: The machine building this must link against the same location as you
# would expect on client machines. The location seems different on x86_64.
echo '
import openmm
import os
path = openmm.version.openmm_library_path
path = os.path.normpath(path)
path, ignored = os.path.split(path)
path = path.replace(os.path.expanduser("~"), "~", 1)
f = open("python_messaging.txt", "w")
f.write(path)
f.close()
' > "python_script.py"
python python_script.py
openmm_parent_dir=`cat python_messaging.txt`
openmm_lib_dir="${openmm_parent_dir}/lib"
openmm_include_dir="${openmm_parent_dir}/include"
# Creates:
# libOpenMMMetal.dylib
# libOpenMMAmoebaMetal.dylib
# libOpenMMDrudeMetal.dylib
# libOpenMMRPMDMetal.dylib
if [[ $run_all_tests == true ]]; then
build_tests_flags="-DOPENMM_BUILD_OPENCL_TESTS=1 -DOPENMM_BUILD_LONG_TESTS=1 -DOPENMM_BUILD_VERY_LONG_TESTS=1"
elif [[ $run_most_tests == true ]]; then
build_tests_flags="-DOPENMM_BUILD_OPENCL_TESTS=1 -DOPENMM_BUILD_LONG_TESTS=1 -DOPENMM_BUILD_VERY_LONG_TESTS=0"
elif [[ $run_quick_tests == true ]]; then
build_tests_flags="-DOPENMM_BUILD_OPENCL_TESTS=1 -DOPENMM_BUILD_LONG_TESTS=0"
else
build_tests_flags="-DOPENMM_BUILD_OPENCL_TESTS=0"
fi
cmake .. \
-DCMAKE_OSX_ARCHITECTURES=arm64 \
-DCMAKE_INSTALL_PREFIX="/usr/local/openmm" \
-DOPENMM_DIR=${openmm_parent_dir} \
${build_tests_flags} \
# 4 CPU cores is the most compatible amount of cores across all Mac systems.
# It doesn't eat into M1 efficiency cores which harm performance, and doesn't
# cause load imbalance on quad-core Intel Macs.
# Nevermind - 8 cores is fastest on my local machine. Perhaps using the E-cores
# wouldn't _hurt_ on base M1 and double-overloading a quad-core Intel Mac
# wouldn't hurt. It won't change performance on the hexa-core Intel Mac mini.
make -j8
if [[ $install_plugins == true ]]; then
sudo make install
fi
if [[ $run_all_tests == true ]]; then
make test
elif [[ $run_most_tests == true ]]; then
make test
elif [[ $run_quick_tests == true ]]; then
make test
fi
mv "platforms/metal/libOpenMMMetal.dylib" "libOpenMMMetal.dylib"
mv "plugins/amoeba/platforms/metal/libOpenMMAmoebaMetal.dylib" "libOpenMMAmoebaMetal.dylib"
mv "plugins/drude/platforms/metal/libOpenMMDrudeMetal.dylib" "libOpenMMDrudeMetal.dylib"
mv "plugins/rpmd/platforms/metal/libOpenMMRPMDMetal.dylib" "libOpenMMRPMDMetal.dylib"