-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathinstall_cpp_dependencies.sh
More file actions
321 lines (297 loc) · 9.13 KB
/
Copy pathinstall_cpp_dependencies.sh
File metadata and controls
321 lines (297 loc) · 9.13 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
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
#!/bin/bash
set -e
# Usage: install_cpp_dependencies.sh <cpp_cgmanifest_path> <macis_cgmanifest_path>
#
# Arguments:
# cpp_cgmanifest_path - Full path to cpp/manifest/qdk-chemistry/cgmanifest.json
# macis_cgmanifest_path - Full path to external/macis/manifest/cgmanifest.json
if [[ $# -ne 2 ]]; then
echo "Usage: $0 <cpp_cgmanifest_path> <macis_cgmanifest_path>"
echo ""
echo "Example:"
echo " $0 /repo/cpp/manifest/qdk-chemistry/cgmanifest.json /repo/external/macis/manifest/cgmanifest.json"
exit 1
fi
CGMANIFEST="$1"
MACIS_CGMANIFEST="$2"
if [[ ! -f "$CGMANIFEST" ]]; then
echo "Error: cgmanifest.json not found at $CGMANIFEST"
exit 1
fi
if [[ ! -f "$MACIS_CGMANIFEST" ]]; then
echo "Error: macis cgmanifest.json not found at $MACIS_CGMANIFEST"
exit 1
fi
echo "Installing C++ dependencies for QDK Chemistry..."
echo "Using cgmanifest: $CGMANIFEST"
echo "Using macis cgmanifest: $MACIS_CGMANIFEST"
# Configuration
BUILD_DIR="${BUILD_DIR:-/tmp/qdk_deps_build}"
INSTALL_PREFIX="${INSTALL_PREFIX:-/usr/local}"
BUILD_TYPE="${BUILD_TYPE:-Release}"
BUILD_SHARED_LIBS="${BUILD_SHARED_LIBS:-OFF}" # Default to static
LIBINT_JOBS=${LIBINT_JOBS:-4} # Limit libint build jobs to 4 due to high memory usage
KEEP_BUILD_DIR="${KEEP_BUILD_DIR:-0}"
if command -v nproc >/dev/null 2>&1; then
JOBS=$(nproc) # Linux
else
JOBS=$(sysctl -n hw.logicalcpu) # macOS
fi
MAC_BUILD="OFF"
if [[ "$OSTYPE" == "darwin"* ]]; then
MAC_BUILD="ON"
fi
# Helper function to extract commit hash from cgmanifest by repository URL pattern
get_commit_hash() {
local manifest="$1"
local repo_pattern="$2"
python3 -c "
import json
with open('$manifest') as f:
data = json.load(f)
for reg in data['registrations']:
comp = reg['component']
if comp['type'] == 'git' and '$repo_pattern' in comp['git'].get('repositoryUrl', ''):
print(comp['git']['commitHash'].strip())
break
"
}
# Helper function to extract tag from cgmanifest by repository URL pattern
get_tag() {
local manifest="$1"
local repo_pattern="$2"
python3 -c "
import json
with open('$manifest') as f:
data = json.load(f)
for reg in data['registrations']:
comp = reg['component']
if comp['type'] == 'git' and '$repo_pattern' in comp['git'].get('repositoryUrl', ''):
print(comp['git'].get('tag', ''))
break
"
}
# Helper function to get download URL for "other" type components
get_download_url() {
local manifest="$1"
local name="$2"
python3 -c "
import json
with open('$manifest') as f:
data = json.load(f)
for reg in data['registrations']:
comp = reg['component']
if comp['type'] == 'other' and comp['other'].get('name') == '$name':
print(comp['other']['downloadUrl'])
break
"
}
# Read versions from cpp cgmanifest
SPDLOG_COMMIT=$(get_commit_hash "$CGMANIFEST" "gabime/spdlog")
if [[ -z "$SPDLOG_COMMIT" ]]; then
echo "Error: Could not find spdlog commit hash in $CGMANIFEST"
exit 1
fi
SPDLOG_TAG=$(get_tag "$CGMANIFEST" "gabime/spdlog")
if [[ -z "$SPDLOG_TAG" ]]; then
echo "Error: Could not find spdlog tag in $CGMANIFEST"
exit 1
fi
LIBECPINT_COMMIT=$(get_commit_hash "$CGMANIFEST" "robashaw/libecpint")
if [[ -z "$LIBECPINT_COMMIT" ]]; then
echo "Error: Could not find libecpint commit hash in $CGMANIFEST"
exit 1
fi
LIBECPINT_TAG=$(get_tag "$CGMANIFEST" "robashaw/libecpint")
if [[ -z "$LIBECPINT_TAG" ]]; then
echo "Error: Could not find libecpint tag in $CGMANIFEST"
exit 1
fi
LIBINT_URL=$(get_download_url "$CGMANIFEST" "Libint")
if [[ -z "$LIBINT_URL" ]]; then
echo "Error: Could not find Libint download URL in $CGMANIFEST"
exit 1
fi
GAUXC_COMMIT=$(get_commit_hash "$CGMANIFEST" "wavefunction91/gauxc")
if [[ -z "$GAUXC_COMMIT" ]]; then
echo "Error: Could not find gauxc commit hash in $CGMANIFEST"
exit 1
fi
BTAS_COMMIT=$(get_commit_hash "$CGMANIFEST" "BTAS/btas")
if [[ -z "$BTAS_COMMIT" ]]; then
echo "Error: Could not find BTAS commit hash in $CGMANIFEST"
exit 1
fi
# Read versions from macis cgmanifest
BLASPP_COMMIT=$(get_commit_hash "$MACIS_CGMANIFEST" "icl-utk-edu/blaspp")
if [[ -z "$BLASPP_COMMIT" ]]; then
echo "Error: Could not find blaspp commit hash in $MACIS_CGMANIFEST"
exit 1
fi
LAPACKPP_COMMIT=$(get_commit_hash "$MACIS_CGMANIFEST" "icl-utk-edu/lapackpp")
if [[ -z "$LAPACKPP_COMMIT" ]]; then
echo "Error: Could not find lapackpp commit hash in $MACIS_CGMANIFEST"
exit 1
fi
echo "Using versions from cgmanifest.json:"
echo " spdlog: ${SPDLOG_TAG:-$SPDLOG_COMMIT}"
echo " blaspp: $BLASPP_COMMIT"
echo " lapackpp: $LAPACKPP_COMMIT"
echo " libecpint: ${LIBECPINT_TAG:-$LIBECPINT_COMMIT}"
echo " libint: $LIBINT_URL"
echo " gauxc: $GAUXC_COMMIT"
echo " btas: $BTAS_COMMIT"
mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR"
# Install spdlog
echo "=== Installing spdlog ==="
git clone https://github.com/gabime/spdlog.git spdlog
cd spdlog
git checkout "$SPDLOG_COMMIT"
mkdir -p build
cd build
cmake .. -DCMAKE_BUILD_TYPE="$BUILD_TYPE" \
-DCMAKE_INSTALL_PREFIX="$INSTALL_PREFIX" \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DCMAKE_CXX_FLAGS="-march=native -fPIC" \
-DBUILD_SHARED_LIBS="$BUILD_SHARED_LIBS"
make -j"$JOBS"
make install
cd "$BUILD_DIR"
rm -rf spdlog
# Install blaspp
echo "=== Installing blaspp ==="
git clone https://github.com/icl-utk-edu/blaspp.git blaspp
cd blaspp
git checkout "$BLASPP_COMMIT"
mkdir -p build
cd build
cmake .. -DCMAKE_BUILD_TYPE="$BUILD_TYPE" \
-DCMAKE_INSTALL_PREFIX="$INSTALL_PREFIX" \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DBUILD_TESTING=OFF \
-DBUILD_SHARED_LIBS="$BUILD_SHARED_LIBS"
make -j"$JOBS"
make install
cd "$BUILD_DIR"
rm -rf blaspp
# Install lapackpp
echo "=== Installing lapackpp ==="
git clone https://github.com/icl-utk-edu/lapackpp.git lapackpp
cd lapackpp
git checkout "$LAPACKPP_COMMIT"
mkdir -p build
cd build
cmake .. -DCMAKE_BUILD_TYPE="$BUILD_TYPE" \
-DCMAKE_INSTALL_PREFIX="$INSTALL_PREFIX" \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DBUILD_TESTING=OFF \
-DBUILD_SHARED_LIBS="$BUILD_SHARED_LIBS"
make -j"$JOBS"
make install
cd "$BUILD_DIR"
rm -rf lapackpp
# Install BTAS
# Must follow blaspp/lapackpp and share their prefix: BTAS installs the
# `blaspp_headers` marker beside them, where its installed config looks for it.
echo "=== Installing BTAS ==="
git clone https://github.com/BTAS/btas.git btas
cd btas
git checkout "$BTAS_COMMIT"
mkdir -p build
cd build
cmake .. -DCMAKE_BUILD_TYPE="$BUILD_TYPE" \
-DCMAKE_INSTALL_PREFIX="$INSTALL_PREFIX" \
-DCMAKE_PREFIX_PATH="$INSTALL_PREFIX" \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DBUILD_TESTING=OFF \
-DBTAS_BUILD_UNITTEST=OFF \
-DBUILD_SHARED_LIBS="$BUILD_SHARED_LIBS"
make install
cd "$BUILD_DIR"
rm -rf btas
# Install libint2
echo "=== Installing libint2 ==="
LIBINT_TARBALL=$(basename "$LIBINT_URL")
wget -q "$LIBINT_URL"
tar xzf "$LIBINT_TARBALL"
# The tarball libint-2.9.0-mpqc4.tgz extracts to libint-2.9.0, not libint-2.9.0-mpqc4
# Find the actual extracted directory (excluding macOS metadata files starting with ._)
LIBINT_DIR=$(ls -d libint-*/ 2>/dev/null | grep -v '^\._' | head -1 | tr -d '/')
if [[ -z "$LIBINT_DIR" || ! -d "$LIBINT_DIR" ]]; then
echo "Error: Could not find libint directory after extraction"
ls -la
exit 1
fi
echo "Found libint directory: $LIBINT_DIR"
cd "$LIBINT_DIR"
mkdir -p build
cd build
cmake .. -DCMAKE_BUILD_TYPE="$BUILD_TYPE" \
-DCMAKE_INSTALL_PREFIX="$INSTALL_PREFIX" \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DBUILD_SHARED_LIBS="$BUILD_SHARED_LIBS"
# libint's compilation is memory intensive so parallel jobs are limited to 4 to prevent OOM errors
make -j"$LIBINT_JOBS"
make install
cd "$BUILD_DIR"
rm -rf "$LIBINT_DIR" "$LIBINT_TARBALL"
# Install ecpint
echo "=== Installing ecpint ==="
git clone https://github.com/robashaw/libecpint ecpint
cd ecpint
git checkout "$LIBECPINT_COMMIT"
mkdir -p build
cd build
cmake .. -DCMAKE_BUILD_TYPE="$BUILD_TYPE" \
-DCMAKE_INSTALL_PREFIX="$INSTALL_PREFIX" \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DBUILD_TESTING=OFF \
-DLIBECPINT_BUILD_TESTS=OFF \
-DLIBECPINT_USE_PUGIXML=OFF \
-DBUILD_SHARED_LIBS="$BUILD_SHARED_LIBS"
make -j"$JOBS"
make install
cd "$BUILD_DIR"
rm -rf ecpint
# Install gauxc
echo "=== Installing gauxc ==="
git clone https://github.com/wavefunction91/gauxc.git gauxc
cd gauxc
git checkout "$GAUXC_COMMIT"
mkdir -p build
cd build
gauxc_cmake_args=(
..
-DCMAKE_BUILD_TYPE="$BUILD_TYPE"
-DCMAKE_INSTALL_PREFIX="$INSTALL_PREFIX"
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
-DBUILD_TESTING=OFF
-DEXCHCXX_ENABLE_LIBXC=OFF
-DGAUXC_ENABLE_HDF5=OFF
-DGAUXC_ENABLE_MAGMA=OFF
-DGAUXC_ENABLE_CUDA=OFF
-DGAUXC_ENABLE_MPI=OFF
-DBUILD_SHARED_LIBS="$BUILD_SHARED_LIBS"
)
if [[ "$MAC_BUILD" == "ON" ]]; then
gauxc_cmake_args+=(
-DGAUXC_ENABLE_CUTLASS=OFF
-DGAUXC_ENABLE_OPENMP=OFF
)
else
gauxc_cmake_args+=(
-DGAUXC_ENABLE_CUTLASS=ON
)
fi
cmake "${gauxc_cmake_args[@]}"
make -j"$JOBS"
make install
cd "$BUILD_DIR"
rm -rf gauxc
# Cleanup
if [[ "$KEEP_BUILD_DIR" != "1" ]]; then
cd /
rm -rf "$BUILD_DIR"
fi
echo "=== All dependencies installed successfully ==="