-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcompile.sh
executable file
·138 lines (120 loc) · 4.32 KB
/
compile.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
#!/usr/bin/env bash
rm -fr build
mkdir build;
# params: <pcie|arm_pcie|soc|mips|cmodel> <local|sophonsdk3|allinone>
target_arch=soc
sdk_type=sophonsdk3
PYTHON_BIN=/workspace/pythons/Python-3.8.2/python_3.8.2/bin/python3
PYTHON_LIB=/workspace/pythons/Python-3.8.2/python_3.8.2/lib/
if [ -n "$1" ]; then
target_arch=$1
fi
if [ -n "$2" ]; then
sdk_type=$1
fi
echo sdk_type=$sdk_type
# judge param1
if [ "$target_arch" = "pcie" ]; then
cmake_param1="-DBUILD_TYPE=pcie"
elif [ "$target_arch" = "soc" ]; then
cmake_param1="-DBUILD_TYPE=soc -DCMAKE_TOOLCHAIN_FILE=./cmake/BM1684_SOC/ToolChain_aarch64_linux.cmake"
elif [ "$target_arch" = "mips" ]; then
cmake_param1="-DBUILD_TYPE=mips -DCMAKE_TOOLCHAIN_FILE=./cmake/mips64-linux-toolchain.cmake"
elif [ "$target_arch" = "arm_pcie" ]; then
cmake_param1="-DBUILD_TYPE=arm_pcie -DCMAKE_TOOLCHAIN_FILE=./cmake/aarch64-linux-toolchain.cmake"
fi
# judge param2
if [ "$sdk_type" = "sophonsdk3" ]; then
cmake_param2="-DUSE_SOPHONSDK3=ON -DUSE_LOCAL=OFF -DUSE_ALLINONE=OFF"
elif [ "$target_arch" = "local" ]; then
cmake_param2="-DUSE_SOPHONSDK3=OFF -DUSE_LOCAL=ON -DUSE_ALLINONE=OFF"
elif [ "$target_arch" = "allinone" ]; then
cmake_param2="-DUSE_SOPHONSDK3=OFF -DUSE_LOCAL=OFF -DUSE_ALLINONE=ON"
fi
cmake_param2="$cmake_param2 -DSDK_TYPE=$sdk_type"
echo $cmake_param2
function get_python3_version() {
U_V1=`$PYTHON_BIN -V 2>&1|awk '{print $2}'|awk -F '.' '{print $1}'`
U_V2=`$PYTHON_BIN -V 2>&1|awk '{print $2}'|awk -F '.' '{print $2}'`
U_V3=`$PYTHON_BIN -V 2>&1|awk '{print $2}'|awk -F '.' '{print $3}'`
echo $U_V1"."$U_V2"."$U_V3
return $?
}
function create_whl_path() {
U_V1=`$PYTHON_BIN -V 2>&1|awk '{print $2}'|awk -F '.' '{print $1}'`
U_V2=`$PYTHON_BIN -V 2>&1|awk '{print $2}'|awk -F '.' '{print $2}'`
mkdir -p out/sophon-inference/python$U_V1$U_V2
echo out/sophon-inference/python$U_V1$U_V2
return $?
}
function create_release_directory() {
echo "----------------------------- Create release folder ---------------------------"
if [ -d "out" ] ; then
rm -rf out
fi
mkdir -p out/sophon-inference/
mkdir -p out/sophon-inference/include/sail
mkdir -p out/sophon-inference/lib
}
function build_lib(){
echo "----------------------------- Start build lib ---------------------------------"
if [ ! -f "CMakeLists.txt" ]; then
echo "Error: Please excute the command at project root path!"
exit 1
fi
if [ ! -d "build" ]; then
mkdir build
else
rm -rf ./build/*
fi
export LD_LIBRARY_PATH=$PYTHON_LIB:$LD_LIBRARY_PATH
PYBIND11_PYTHON_VERSION=$(get_python3_version)
pushd build
cmake $cmake_param1 $cmake_param2 -DPYBIND11_PYTHON_VERSION=$PYBIND11_PYTHON_VERSION -DPYTHON_EXECUTABLE=$PYTHON_BIN -DCUSTOM_PY_LIBDIR=$PYTHON_LIB ..
core_nums=`cat /proc/cpuinfo| grep "processor"| wc -l`
make -j${core_nums}
if [ $? -eq 0 ];then
echo "Build succeed!"
else
echo "Build Failed!"
exit 1
fi
popd
}
function build_whl_pcie() {
echo "----------------------------- Start build wheel -------------------------------"
pushd python/pcie
./sophon_pcie_whl.sh
popd
echo "----------------------------- Start copy wheel --------------------------------"
whl_res_path=$(create_whl_path)/pcie/
mkdir -p $whl_res_path
cp ./python/pcie/dist/*.whl $whl_res_path
}
function build_whl_soc() {
echo "----------------------------- Start build wheel -------------------------------"
pushd python/soc
./sophon_soc_whl.sh
popd
echo "----------------------------- Start copy wheel --------------------------------"
whl_res_path=$(create_whl_path)/soc/
mkdir -p $whl_res_path
cp ./python/soc/arm/dist/*.whl $whl_res_path
}
function fill_headers() {
echo "----------------------------- Fill headers ------------------------------------"
cp ./include/*.h ./out/sophon-inference/include/sail
cp -r ./3rdparty/spdlog ./out/sophon-inference/include/sail
cp ./3rdparty/inireader* ./out/sophon-inference/include/sail
cp ./build/lib/libsail.so ./out/sophon-inference/lib/
}
shell_dir=$(dirname $(readlink -f "$0"))
export LD_LIBRARY_PATH=$PYTHON_LIB:$LD_LIBRARY_PATH
create_release_directory
build_lib
if [ "$target_arch" = "pcie" ]; then
build_whl_pcie
elif [ "$target_arch" = "soc" ]; then
build_whl_soc
fi
fill_headers