-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·142 lines (119 loc) · 3.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
set -e
set -o pipefail
TORCHAIR_ROOT=$(cd "$(dirname $0)"; pwd)
# print usage message
usage() {
echo "Usage:"
echo " bash build.sh [-h] [-j[n]] [-v] [-g] [-u] [-s] [-c]"
echo ""
echo "Options:"
echo " -h Print usage"
echo " -j[n] Set the number of threads used to build CANN, default is 8"
echo " -v Verbose"
echo " -g GCC compiler prefix, used to specify the compiler toolchain"
echo " -u torchair utest"
echo " -s torchair stest"
echo " -c torchair ci build"
echo " -i torchair ci build and install"
echo "to be continued ..."
}
logging() {
echo "[INFO] $@"
}
# parse and set optionss
checkopts() {
VERBOSE=""
THREAD_NUM=8
GCC_PREFIX=""
ENABLE_TORCHAIR_UT="off"
ENABLE_TORCHAIR_ST="off"
ENABLE_CI_BUILD="off"
# Process the options
while getopts 'hj:vuiscg:' opt
do
case "${opt}" in
h) usage
exit 0 ;;
j) THREAD_NUM=$OPTARG ;;
v) VERBOSE="VERBOSE=1" ;;
g) GCC_PREFIX=$OPTARG ;;
u) ENABLE_TORCHAIR_UT="on" ;;
s) ENABLE_TORCHAIR_ST="on" ;;
c) ENABLE_CI_BUILD="on" ;;
i) ENABLE_CI_BUILD_AND_INSTALL="on" ;;
*) logging "Undefined option: ${opt}"
usage
exit 1 ;;
esac
done
}
PACKAGE_NAME=torchair-0.1-py3-none-any.whl
build_torchair() {
logging "CMake Args: ${CMAKE_ARGS}"
local CMAKE_PATH="${TORCHAIR_ROOT}/build"
mkdir -pv "${CMAKE_PATH}"
cd "${CMAKE_PATH}" && cmake ${CMAKE_ARGS} ..
make torchair ${VERBOSE} -j${THREAD_NUM}
local RELEASE_PATH="${TORCHAIR_ROOT}/output"
mkdir -pv "${RELEASE_PATH}"
mv "${TORCHAIR_ROOT}/build/dist/dist/${PACKAGE_NAME}" ${RELEASE_PATH}
}
install_torchair() {
local RELEASE_PATH="${TORCHAIR_ROOT}/output"
pip3 uninstall torchair -y
pip3 install ${RELEASE_PATH}/${PACKAGE_NAME}
}
run_test() {
local TYPE="$1"
local CMAKE_PATH="${TORCHAIR_ROOT}/tests/build"
mkdir -pv "${CMAKE_PATH}"
cd "${CMAKE_PATH}" && cmake .. -DCMAKE_BUILD_TYPE=GCOV -DTORCHAIR_INSTALL_DST=${CMAKE_PATH}/${TYPE}/torchair -DPYTHON_BIN_PATH=${PYTHON_BIN_PATH}
export PYTHONPATH=${CMAKE_PATH}/${TYPE}:${PYTHONPATH}
export LD_LIBRARY_PATH=${CMAKE_PATH}/stubs:${ASCEND_SDK_PATH}/lib:${ASCEND_SDK_PATH}/lib64:${LD_LIBRARY_PATH}
mkdir -pv "${TORCHAIR_ROOT}/coverage"
make torchair_${TYPE} -j${THREAD_NUM}
lcov -o ${TORCHAIR_ROOT}/coverage/coverage.info -e ${CMAKE_PATH}/${TYPE}/${TYPE}.coverage "*torchair/torchair*"
}
main() {
checkopts "$@"
if [[ "$TARGET_PYTHON_PATH" == "" ]]; then
PYTHON_BIN_PATH=$(which python3 || which python3.8)
export TARGET_PYTHON_PATH=${PYTHON_BIN_PATH}
fi
if [[ "X$ASCEND_CUSTOM_PATH" = "X" ]]; then
if [[ "X$ENABLE_CI_BUILD" = "Xon" || "X$ENABLE_CI_BUILD_AND_INSTALL" = "Xon" ]]; then
echo "Building torchair with no ascned-sdk specified"
export NO_ASCEND_SDK=1
else
if [[ "X$ASCEND_HOME_PATH" = "X" ]]; then
echo "ASCEND_CUSTOM_PATH or ASCEND_HOME_PATH must be set when running ut or st"
exit 1
else
echo "Building torchair with ascned-sdk in ${ASCEND_HOME_PATH}"
export ASCEND_SDK_PATH=${ASCEND_HOME_PATH}
fi
fi
else
echo "Building torchair with ascned-sdk in ${ASCEND_CUSTOM_PATH}"
export ASCEND_SDK_PATH=${ASCEND_CUSTOM_PATH}/opensdk/opensdk/
fi
PYTHON_BIN_PATH=${PYTHON_BIN_PATH} bash ${TORCHAIR_ROOT}/configure
${GCC_PREFIX}g++ -v
if [[ "$GCC_PREFIX" != "" ]]; then
CMAKE_ARGS="$CMAKE_ARGS -DGCC_PREFIX=$GCC_PREFIX"
fi
if [[ "X$ENABLE_CI_BUILD" = "Xon" ]]; then
build_torchair
fi
if [[ "X$ENABLE_CI_BUILD_AND_INSTALL" = "Xon" ]]; then
build_torchair
install_torchair
fi
if [[ "X$ENABLE_TORCHAIR_UT" = "Xon" ]]; then
run_test "ut"
fi
if [[ "X$ENABLE_TORCHAIR_ST" = "Xon" ]]; then
run_test "st"
fi
}
main "$@"