/
onnx.sh
129 lines (102 loc) · 4.51 KB
/
onnx.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
# ================================================================
# Compile ONNX
# ================================================================
[ -e $STAGE/onnx ] && ( set -xe
cd $SCRATCH
"$ROOT_DIR/pkgs/utils/pip_install_from_git.sh" \
cython/cython \
benjaminp/six \
'pytest-dev/pytest,[3.6=7.0.]' \
'numpy/numpy,v[3.6=v1.19.|3.7=v1.21.]' \
# Known issues:
# - SciPy meson build uses the wrong casing of OpenBLAS for CMake.
# On Debian, pkg-config also searches in /usr/local and works as a fallback, but not on CentOS 7.
# https://github.com/scipy/scipy/issues/16308
(
set -xe
case "$DISTRO_ID" in
'centos' | 'fedora' | 'rhel' | 'scientific')
export PKG_CONFIG_PATH="$(rpm -ql roaster-openblas | grep -v '/src/' | grep '\.pc' | xargs -rI{} dirname {} | sort -u | paste -sd: -)"
;;
'debian' | 'linuxmint' | 'ubuntu')
export PKG_CONFIG_PATH="$(dpkg -L roaster-openblas | grep -v '/src/' | grep '\.pc' | xargs -rI{} dirname {} | sort -u | paste -sd: -)"
;;
esac
"$ROOT_DIR/pkgs/utils/pip_install_from_git.sh" \
'scipy/scipy,v[3.6=v1.5.|3.7=v1.7.]' \
)
"$ROOT_DIR/pkgs/utils/pip_install_from_git.sh" \
'scikit-learn/scikit-learn,[3.6=0.24.|3.7=1.0.]'
# ------------------------------------------------------------
. "$ROOT_DIR/pkgs/utils/git/version.sh" onnx/onnx,main
until git clone -b "$GIT_TAG" "$GIT_REPO"; do echo 'Retrying'; done
cd onnx
git remote add patch "$GIT_MIRROR/xkszltl/onnx.git"
# Patches:
# - Google benchmark 1.4.1 failed to compile with gcc-11.
# https://github.com/onnx/onnx/issues/4144
PATCHES=""
for i in $PATCHES; do
git fetch patch "$i"
git cherry-pick FETCH_HEAD
done
. "$ROOT_DIR/pkgs/utils/git/submodule.sh"
# pushd third_party/pybind11
# git checkout master
# rm -rf pybind11
# cp -rf /usr/local/src/pybind11 pybind11
# popd
# git commit -am "Update submodule \"pybind11\"."
# ------------------------------------------------------------
. "$ROOT_DIR/pkgs/utils/fpm/pre_build.sh"
(
. "$ROOT_DIR/pkgs/utils/fpm/toolchain.sh"
. "$ROOT_DIR/pkgs/utils/fpm/distro_cc.sh"
# --------------------------------------------------------
# Hack for protoc-gen-mypy bug:
# https://github.com/onnx/onnx/issues/1952
# --------------------------------------------------------
if which python3; then
PY_DIR="$(readlink -f "$INSTALL_ROOT/../python")"
mkdir -p "$PY_DIR"
ln -sf "$(which python3)" "$PY_DIR/python"
export PATH="$PY_DIR:$PATH"
fi
CMAKE_ARGS="$CMAKE_ARGS
-DBUILD_SHARED_LIBS=ON
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_C_COMPILER='$(which "$CC")'
-DCMAKE_C_COMPILER_LAUNCHER=ccache
-DCMAKE_CXX_COMPILER='$(which "$CXX")'
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
-DONNX_GEN_PB_TYPE_STUBS=ON
" ONNX_ML=1 "$ROOT_DIR/pkgs/utils/pip_install_from_git.sh" .
mkdir -p build
cd $_
"$TOOLCHAIN/cmake" \
-DBENCHMARK_ENABLE_LTO=ON \
-DBUILD_ONNX_PYTHON=ON \
-DBUILD_SHARED_LIBS=ON \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER="$CC" \
-DCMAKE_CXX_COMPILER="$CXX" \
-DCMAKE_C{,XX}_COMPILER_LAUNCHER=ccache \
-DCMAKE_C{,XX}_FLAGS="-fdebug-prefix-map='$SCRATCH'='$INSTALL_PREFIX/src' -g" \
-DCMAKE_INSTALL_PREFIX="$INSTALL_ABS" \
-DONNX_BUILD_BENCHMARKS=ON \
-DONNX_BUILD_TESTS=OFF \
-DONNX_GEN_PB_TYPE_STUBS=ON \
-DONNX_ML=ON \
-G"Ninja" \
..
time "$TOOLCHAIN/cmake" --build .
time "$TOOLCHAIN/cmake" --build . --target install
)
"$ROOT_DIR/pkgs/utils/fpm/install_from_git.sh"
# ------------------------------------------------------------
cd
rm -rf $SCRATCH/onnx
"$ROOT_DIR/pkgs/utils/pip_install_from_git.sh" microsoft/onnxconverter-common,v onnx/{keras,sklearn}-onnx,v onnx/onnxmltools,
)
sudo rm -vf $STAGE/onnx
sync || true