forked from MegEngine/MegEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cross_build_linux_arm_inference.sh
executable file
·165 lines (151 loc) · 4.8 KB
/
cross_build_linux_arm_inference.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
#!/usr/bin/env bash
set -e
ARCHS=("arm64-v8a" "armeabi-v7a-softfp" "armeabi-v7a-hardfp")
BUILD_TYPE=Release
MGE_WITH_CUDA=OFF
MGE_ARMV8_2_FEATURE_FP16=OFF
MGE_DISABLE_FLOAT16=OFF
ARCH=arm64-v8a
REMOVE_OLD_BUILD=false
CMAKE_C_FLAGS="-Wno-psabi"
CMAKE_CXX_FLAGS="-Wno-psabi"
echo "EXTRA_CMAKE_ARGS: ${EXTRA_CMAKE_ARGS}"
function usage() {
echo "$0 args1 args2 .."
echo "available args detail:"
echo "-d : Build with Debug mode, default Release mode"
echo "-c : Build with CUDA, default without CUDA(for arm with cuda, example tx1)"
echo "-f : enable MGE_ARMV8_2_FEATURE_FP16 for ARM64, need toolchain and hardware support"
echo "-k : open MGE_DISABLE_FLOAT16 for NEON "
echo "-a : config build arch available: ${ARCHS[@]}"
echo "-r : remove old build dir before make, default off"
echo "-h : show usage"
echo "append other cmake config by export EXTRA_CMAKE_ARGS=..."
echo "example: $0 -d"
exit -1
}
while getopts "rkhdcfa:" arg
do
case $arg in
d)
echo "Build with Debug mode"
BUILD_TYPE=Debug
;;
c)
echo "Build with CUDA"
MGE_WITH_CUDA=ON
;;
f)
echo "enable MGE_ARMV8_2_FEATURE_FP16 for ARM64"
MGE_ARMV8_2_FEATURE_FP16=ON
;;
k)
echo "open MGE_DISABLE_FLOAT16 for NEON"
MGE_DISABLE_FLOAT16=ON
;;
a)
tmp_arch=null
for arch in ${ARCHS[@]}; do
if [ "$arch" = "$OPTARG" ]; then
echo "CONFIG BUILD ARCH to : $OPTARG"
tmp_arch=$OPTARG
ARCH=$OPTARG
break
fi
done
if [ "$tmp_arch" = "null" ]; then
echo "ERR args for arch (-a)"
echo "available arch list: ${ARCHS[@]}"
usage
fi
;;
h)
echo "show usage"
usage
;;
r)
echo "config REMOVE_OLD_BUILD=true"
REMOVE_OLD_BUILD=true
;;
?)
echo "unkonw argument"
usage
;;
esac
done
echo "----------------------------------------------------"
echo "build config summary:"
echo "BUILD_TYPE: $BUILD_TYPE"
echo "MGE_WITH_CUDA: $MGE_WITH_CUDA"
echo "MGE_ARMV8_2_FEATURE_FP16: $MGE_ARMV8_2_FEATURE_FP16"
echo "MGE_DISABLE_FLOAT16: $MGE_DISABLE_FLOAT16"
echo "ARCH: $ARCH"
echo "----------------------------------------------------"
READLINK=readlink
MAKEFILE_TYPE="Unix"
OS=$(uname -s)
if [ $OS = "Darwin" ];then
READLINK=greadlink
elif [[ $OS =~ "NT" ]]; then
echo "BUILD in NT ..."
MAKEFILE_TYPE="Unix"
fi
if [ ! $OS = "Linux" ] && [ $MGE_WITH_CUDA = "ON" ];then
echo "cross build for arm with cuda only support from Linux"
exit -1
fi
if [ $MGE_WITH_CUDA = "ON" ] && [ ! $ARCH = "arm64-v8a" ];then
echo "arm with cuda only support ARCH: arm64-v8a"
exit -1
fi
if [ $MGE_WITH_CUDA = "OFF" ];then
echo "config -Werror=unused-parameter when cuda off for CI check"
CMAKE_C_FLAGS="-Werror=unused-parameter -Wno-psabi"
CMAKE_CXX_FLAGS="-Werror=unused-parameter -Wno-psabi"
fi
SRC_DIR=$($READLINK -f "`dirname $0`/../../")
source $SRC_DIR/scripts/cmake-build/utils/utils.sh
function cmake_build() {
BUILD_DIR=$SRC_DIR/build_dir/gnu-linux/MGE_WITH_CUDA_$3/$1/$BUILD_TYPE/build
INSTALL_DIR=$BUILD_DIR/../install
TOOLCHAIN=$SRC_DIR/toolchains/$2
MGE_WITH_CUDA=$3
echo "build dir: $BUILD_DIR"
echo "install dir: $INSTALL_DIR"
echo "build type: $BUILD_TYPE"
echo "build toolchain: $TOOLCHAIN"
echo "MGE_WITH_CUDA: $MGE_WITH_CUDA"
echo "BUILD MAKEFILE_TYPE: $MAKEFILE_TYPE"
try_remove_old_build $REMOVE_OLD_BUILD $BUILD_DIR $INSTALL_DIR
echo "create build dir"
mkdir -p $BUILD_DIR
mkdir -p $INSTALL_DIR
cd $BUILD_DIR
cmake -G "$MAKEFILE_TYPE Makefiles" \
-DCMAKE_C_FLAGS=$CMAKE_C_FLAGS \
-DCMAKE_CXX_FLAGS=$CMAKE_CXX_FLAGS \
-DCMAKE_TOOLCHAIN_FILE=$TOOLCHAIN \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DMGE_INFERENCE_ONLY=ON \
-DMGE_WITH_CUDA=$MGE_WITH_CUDA \
-DMGE_ARMV8_2_FEATURE_FP16= $MGE_ARMV8_2_FEATURE_FP16 \
-DMGE_DISABLE_FLOAT16=$MGE_DISABLE_FLOAT16 \
-DCMAKE_INSTALL_PREFIX=$INSTALL_DIR \
${EXTRA_CMAKE_ARGS} \
$SRC_DIR
make -j$(nproc)
make install/strip
}
build_flatc $SRC_DIR $REMOVE_OLD_BUILD
toolchain=null
if [ "$ARCH" = "arm64-v8a" ]; then
toolchain="aarch64-linux-gnu.toolchain.cmake"
elif [ "$ARCH" = "armeabi-v7a-hardfp" ]; then
toolchain="arm-linux-gnueabihf.toolchain.cmake"
elif [ "$ARCH" = "armeabi-v7a-softfp" ]; then
toolchain="arm-linux-gnueabi.toolchain.cmake"
else
echo "ERR CONFIG ABORT NOW!!"
exit -1
fi
cmake_build $ARCH $toolchain $MGE_WITH_CUDA