-
Notifications
You must be signed in to change notification settings - Fork 10
/
build.sh
executable file
·260 lines (225 loc) · 8.73 KB
/
build.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
#!/bin/bash
# Copyright (c) 2019-2024, NVIDIA CORPORATION.
# cugraph build script
# This script is used to build the component(s) in this repo from
# source, and can be called with various options to customize the
# build as needed (see the help output for details)
# Abort script on first error
set -e
NUMARGS=$#
ARGS=$*
# NOTE: ensure all dir changes are relative to the location of this
# script, and that this script resides in the repo dir!
REPODIR=$(cd $(dirname $0); pwd)
RAPIDS_VERSION="$(sed -E -e 's/^([0-9]{2})\.([0-9]{2})\.([0-9]{2}).*$/\1.\2/' VERSION)"
# Valid args to this script (all possible targets and options) - only one per line
VALIDARGS="
clean
uninstall
cugraph-pyg
cugraph-dgl
pylibwholegraph
libwholegraph
tests
all
-v
-g
-n
--pydevelop
--allgpuarch
--clean
-h
--help
"
HELP="$0 [<target> ...] [<flag> ...]
where <target> is:
clean - remove all existing build artifacts and configuration (start over)
uninstall - uninstall libcugraph and cugraph from a prior build/install (see also -n)
cugraph-pyg - build the cugraph-pyg Python package
cugraph-dgl - build the cugraph-dgl extensions for DGL
pylibwholegraph - build the pylibwholegraph Python package
libwholegraph - build the libwholegraph library
tests - build the C++ tests
all - build everything
and <flag> is:
-v - verbose build mode
-g - build for debug
-n - do not install after a successful build (does not affect Python packages)
--pydevelop - install the Python packages in editable mode
--allgpuarch - build for all supported GPU architectures
--clean - clean an individual target (note: to do a complete rebuild, use the clean target described above)
-h - print this text
default action (no args) is to build and install 'libwholegraph' then 'pylibwholegraph' then 'cugraph-pyg' then 'cugraph-dgl'
"
CUGRAPH_PYG_BUILD_DIR=${REPODIR}/python/cugraph-pyg/build
CUGRAPH_DGL_BUILD_DIR=${REPODIR}/python/cugraph-dgl/build
PYLIBWHOLEGRAPH_BUILD_DIR=${REPODIR}/python/pylibwholegraph/build
LIBWHOLEGRAPH_BUILD_DIR=${REPODIR}/cpp/build
BUILD_DIRS="${CUGRAPH_PYG_BUILD_DIR}
${CUGRAPH_DGL_BUILD_DIR}
${PYLIBWHOLEGRAPH_BUILD_DIR}
${LIBWHOLEGRAPH_BUILD_DIR}
"
# Set defaults for vars modified by flags to this script
VERBOSE_FLAG=""
BUILD_TYPE=Release
INSTALL_TARGET="--target install"
BUILD_ALL_GPU_ARCH=0
PYTHON_ARGS_FOR_INSTALL="-m pip install --no-build-isolation --no-deps --config-settings rapidsai.disable-cuda=true"
# Set defaults for vars that may not have been defined externally
# FIXME: if PREFIX is not set, check CONDA_PREFIX, but there is no fallback
# from there!
INSTALL_PREFIX=${PREFIX:=${CONDA_PREFIX}}
PARALLEL_LEVEL=${PARALLEL_LEVEL:=`nproc`}
BUILD_ABI=${BUILD_ABI:=ON}
function hasArg {
(( ${NUMARGS} != 0 )) && (echo " ${ARGS} " | grep -q " $1 ")
}
function buildDefault {
(( ${NUMARGS} == 0 )) || !(echo " ${ARGS} " | grep -q " [^-][a-zA-Z0-9\_\-]\+ ")
}
function cleanPythonDir {
pushd $1 > /dev/null
find . -type d -name __pycache__ -print | xargs rm -rf
find . -type d -name build -print | xargs rm -rf
find . -type d -name dist -print | xargs rm -rf
find . -type f -name "*.cpp" -delete
find . -type f -name "*.cpython*.so" -delete
find . -type d -name _external_repositories -print | xargs rm -rf
popd > /dev/null
}
if hasArg -h || hasArg --help; then
echo "${HELP}"
exit 0
fi
# Check for valid usage
if (( ${NUMARGS} != 0 )); then
for a in ${ARGS}; do
if ! (echo "${VALIDARGS}" | grep -q "^[[:blank:]]*${a}$"); then
echo "Invalid option: ${a}"
exit 1
fi
done
fi
# Process flags
if hasArg -v; then
VERBOSE_FLAG="-v"
CMAKE_VERBOSE_OPTION="--log-level=VERBOSE"
fi
if hasArg -g; then
BUILD_TYPE=Debug
fi
if hasArg -n; then
INSTALL_TARGET=""
fi
if hasArg --allgpuarch; then
BUILD_ALL_GPU_ARCH=1
fi
if hasArg --pydevelop; then
PYTHON_ARGS_FOR_INSTALL="${PYTHON_ARGS_FOR_INSTALL} -e"
fi
if hasArg tests; then
BUILD_TESTS=ON
else
BUILD_TESTS=OFF
fi
# If clean or uninstall targets given, run them prior to any other steps
if hasArg uninstall; then
if [[ "$INSTALL_PREFIX" != "" ]]; then
rm -rf ${INSTALL_PREFIX}/include/wholememory
rm -f ${INSTALL_PREFIX}/lib/libwholegraph.so
rm -rf ${INSTALL_PREFIX}/lib/cmake/wholegraph
fi
# This may be redundant given the above, but can also be used in case
# there are other installed files outside of the locations above.
if [ -e ${LIBWHOLEGRAPH_BUILD_DIR}/install_manifest.txt ]; then
xargs rm -f < ${LIBWHOLEGRAPH_BUILD_DIR}/install_manifest.txt > /dev/null 2>&1
fi
# uninstall cugraph-dgl/cugraph-pyg/wholegraph installed from a prior install
# FIXME: if multiple versions of these packages are installed, this only
# removes the latest one and leaves the others installed. build.sh uninstall
# can be run multiple times to remove all of them, but that is not obvious.
pip uninstall -y cugraph-dgl cugraph-pyg pylibwholegraph libwholegraph
fi
if hasArg clean; then
# Ignore errors for clean since missing files, etc. are not failures
set +e
# remove artifacts generated inplace
if [[ -d ${REPODIR}/python ]]; then
cleanPythonDir ${REPODIR}/python
fi
# If the dirs to clean are mounted dirs in a container, the contents should
# be removed but the mounted dirs will remain. The find removes all
# contents but leaves the dirs, the rmdir attempts to remove the dirs but
# can fail safely.
for bd in ${BUILD_DIRS}; do
if [ -d ${bd} ]; then
find ${bd} -mindepth 1 -delete
rmdir ${bd} || true
fi
done
# Go back to failing on first error for all other operations
set -e
fi
################################################################################
# Build and install the libwholegraph library
if hasArg libwholegraph || buildDefault || hasArg all ; then
# set values based on flags
if (( ${BUILD_ALL_GPU_ARCH} == 0 )); then
WHOLEGRAPH_CMAKE_CUDA_ARCHITECTURES="${WHOLEGRAPH_CMAKE_CUDA_ARCHITECTURES:=NATIVE}"
echo "Building for the architecture of the GPU in the system..."
else
WHOLEGRAPH_CMAKE_CUDA_ARCHITECTURES="70-real;75-real;80-real;86-real;90"
echo "Building for *ALL* supported GPU architectures..."
fi
cmake -S ${REPODIR}/cpp -B ${LIBWHOLEGRAPH_BUILD_DIR} \
-DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} \
-DCMAKE_CUDA_ARCHITECTURES=${WHOLEGRAPH_CMAKE_CUDA_ARCHITECTURES} \
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
-DCMAKE_PREFIX_PATH=${INSTALL_PREFIX} \
-DCMAKE_MESSAGE_LOG_LEVEL=VERBOSE \
-DBUILD_TESTS=${BUILD_TESTS} \
-DBUILD_WITH_NVSHMEM=${BUILD_WITH_NVSHMEM}
cd ${LIBWHOLEGRAPH_BUILD_DIR}
if ! hasArg --compile-cmd; then
## Build and (optionally) install library + tests
cmake --build . -j${PARALLEL_LEVEL} ${INSTALL_TARGET} ${VERBOSE_FLAG}
fi
fi
# Build and install the pylibwholegraph Python package
if hasArg pylibwholegraph || buildDefault || hasArg all; then
if hasArg --clean; then
cleanPythonDir ${REPODIR}/python/pylibwholegraph
fi
# setup.py and cmake reference an env var LIBWHOLEGRAPH_DIR to find the
# libwholegraph package (cmake).
# If not set by the user, set it to LIBWHOLEGRAPH_BUILD_DIR
LIBWHOLEGRAPH_DIR=${LIBWHOLEGRAPH_DIR:=${LIBWHOLEGRAPH_BUILD_DIR}}
if ! hasArg --compile-cmd; then
cd ${REPODIR}/python/pylibwholegraph
env LIBWHOLEGRAPH_DIR=${LIBWHOLEGRAPH_DIR} \
SKBUILD_CMAKE_ARGS="-DCMAKE_BUILD_TYPE=${BUILD_TYPE}" python ${PYTHON_ARGS_FOR_INSTALL} \
.
else
# just invoke cmake without going through scikit-build-core
env LIBWHOLEGRAPH_DIR=${LIBWHOLEGRAPH_DIR} \
cmake -S ${REPODIR}/python/pylibwholegraph -B ${REPODIR}/python/pylibwholegraph/build \
-DCMAKE_BUILD_TYPE=${BUILD_TYPE}
fi
fi
# Build and install the cugraph-pyg Python package
if hasArg cugraph-pyg || buildDefault || hasArg all; then
if hasArg --clean; then
cleanPythonDir ${REPODIR}/python/cugraph-pyg
else
python ${PYTHON_ARGS_FOR_INSTALL} ${REPODIR}/python/cugraph-pyg
fi
fi
# Install the cugraph-dgl extensions for DGL
if hasArg cugraph-dgl || buildDefault ||hasArg all; then
if hasArg --clean; then
cleanPythonDir ${REPODIR}/python/cugraph-dgl
else
python ${PYTHON_ARGS_FOR_INSTALL} ${REPODIR}/python/cugraph-dgl
fi
fi