forked from pytorch/builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
89 lines (76 loc) · 2.55 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
#!/usr/bin/env bash
export CMAKE_LIBRARY_PATH=$PREFIX/lib:$PREFIX/include:$CMAKE_LIBRARY_PATH
export CMAKE_PREFIX_PATH=$PREFIX
# compile for Kepler, Kepler+Tesla, Maxwell, Volta
export TORCH_CUDA_ARCH_LIST="3.5;5.0+PTX;6.0;6.1"
export TORCH_NVCC_FLAGS="-Xfatbin -compress-all"
export TH_BINARY_BUILD=1
export PYTORCH_BUILD_VERSION=$PKG_VERSION
export PYTORCH_BUILD_NUMBER=$PKG_BUILDNUM
export NCCL_ROOT_DIR=/usr/local/cuda
export USE_STATIC_CUDNN=1
export USE_STATIC_NCCL=1
export ATEN_STATIC_CUDA=1
fname_with_sha256() {
HASH=$(sha256sum $1 | cut -c1-8)
DIRNAME=$(dirname $1)
BASENAME=$(basename $1)
if [[ $BASENAME == "libnvrtc-builtins.so" ]]; then
echo $1
else
INITNAME=$(echo $BASENAME | cut -f1 -d".")
ENDNAME=$(echo $BASENAME | cut -f 2- -d".")
echo "$DIRNAME/$INITNAME-$HASH.$ENDNAME"
fi
}
DEPS_LIST=(
)
DEPS_SONAME=(
)
if [[ "$OSTYPE" == "darwin"* ]]; then
MACOSX_DEPLOYMENT_TARGET=10.9 python setup.py install
else
# install
python setup.py install
# copy over needed dependent .so files over and tag them with their hash
patched=()
for filepath in "${DEPS_LIST[@]}"
do
filename=$(basename $filepath)
destpath=$SP_DIR/torch/lib/$filename
cp $filepath $destpath
patchedpath=$(fname_with_sha256 $destpath)
patchedname=$(basename $patchedpath)
mv $destpath $patchedpath
patched+=("$patchedname")
echo "Copied $filepath to $patchedpath"
done
# run patchelf to fix the so names to the hashed names
for ((i=0;i<${#DEPS_LIST[@]};++i));
do
find $SP_DIR/torch -name '*.so*' | while read sofile; do
origname=${DEPS_SONAME[i]}
patchedname=${patched[i]}
set +e
patchelf --print-needed $sofile | grep $origname 2>&1 >/dev/null
ERRCODE=$?
set -e
if [ "$ERRCODE" -eq "0" ]; then
echo "patching $sofile entry $origname to $patchedname"
patchelf --replace-needed $origname $patchedname $sofile
fi
done
done
# set RPATH of _C.so and similar to $ORIGIN, $ORIGIN/lib and conda/lib
find $SP_DIR/torch -name "*.so*" -maxdepth 1 -type f | while read sofile; do
echo "Setting rpath of $sofile to " '$ORIGIN:$ORIGIN/lib:$ORIGIN/../../..'
patchelf --set-rpath '$ORIGIN:$ORIGIN/lib:$ORIGIN/../../..' $sofile
patchelf --print-rpath $sofile
done
# set RPATH of lib/ files to $ORIGIN and conda/lib
find $SP_DIR/torch/lib -name "*.so*" -maxdepth 1 -type f | while read sofile; do
echo "Setting rpath of $sofile to " '$ORIGIN:$ORIGIN/lib:$ORIGIN/../../../..'
patchelf --set-rpath '$ORIGIN:$ORIGIN/../../../..' $sofile
patchelf --print-rpath $sofile
done
fi