forked from Cambricon/mlu-ops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.sh
executable file
·155 lines (137 loc) · 4.08 KB
/
release.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
#!/bin/bash
set -e
# Initialize the Variables
BUILD_MODE="Normal"
BUILD_OUT_DIR=${BANGPY_BUILD_PATH}
if [ -n "${BUILD_OUT_DIR}" ]; then
if [ "${BUILD_OUT_DIR:0-1}" != "/" ]; then
BUILD_OUT_DIR=${BANGPY_BUILD_PATH}"/"
fi
else
echo "Please set BANGPY_BUILD_PATH environment variable first."
echo "eg. export BANGPY_BUILD_PATH=/mlu-ops/bangpy-ops/outs/"
exit -1
fi
if [ -z "${BANGPY_HOME}" ]; then
echo "Please set BANGPY_HOME environment variable first."
echo "eg. export BANGPY_HOME=/mlu-ops/bangpy-ops/"
exit -1
fi
if [ "${BANGPY_HOME:0-1}" != "/" ]; then
BANGPY_HOME=${BANGPY_HOME}"/"
fi
BANGPY_UTILS_PATH=${BANGPY_HOME}"utils/"
usage () {
echo "USAGE: release.sh <options>"
echo
echo "OPTIONS:"
echo " -h, --help Print usage"
echo " --filter=* Build specified OP only"
echo " --target=* Test mlu target:[mlu270, mlu370-s4, mlu220-m2, mlu290]"
echo " --opsfile=* Operators list file"
echo " -r, --release Build by release mode"
echo " -t, --test Test operators after build"
echo
}
ARGS="$*"
TEST_ENABLE="False"
cmdline_args=$(getopt -o h,r,t --long filter:,release,test,target:,opsfile: -n 'release.sh' -- "$@")
eval set -- "$cmdline_args"
if [ $? != 0 ]; then echo "Unknown options, use -h or --help" >&2 ; exit -1; fi
if [ $# != 0 ]; then
while true; do
case "$1" in
--filter)
shift
shift
;;
--target)
shift
shift
;;
--opsfile)
shift
shift
;;
-r | --release)
BUILD_MODE="Release"
shift
;;
-t | --test)
TEST_ENABLE="True"
shift
;;
-h | --help)
usage
exit 0
;;
--)
shift
break
;;
*)
echo "-- Unknown options ${1}, use -h or --help"
usage
exit -1
;;
esac
done
fi
${BANGPY_UTILS_PATH}"build_operators.sh" ${ARGS}
if [ "${BUILD_MODE}" == "Release" ]; then
# Link the files of .so in the compiled directory to bangpylib.
BANGPY_HEAD_FILES_LIST=()
BANGPY_LINK_FILE_LIST=(${BANGPY_HOME}"prebuild/runtime_tensor.o")
BANGPY_LINK_OP_DIR_LIST=()
if [ -z "${BANGPY_LINK_OP_DIR_LIST}" ]; then
for file in $(find ${BUILD_OUT_DIR} -maxdepth 1 -type d)
do
file_name=${file##*/}
BANGPY_LINK_OP_DIR_LIST+=(${file_name})
done
fi
BANGPY_ALL_SO=()
for i in ${BANGPY_LINK_OP_DIR_LIST[@]}
do
for link_file in $(find ${BUILD_OUT_DIR}$i/ -maxdepth 4 -name libmluops.so)
do
BANGPY_ALL_SO+=(${link_file})
done
for link_file in $(find ${BUILD_OUT_DIR}$i/ -maxdepth 1 -name "*\.o")
do
BANGPY_LINK_FILE_LIST+=(${link_file})
done
for link_file in $(find ${BUILD_OUT_DIR}$i/ -maxdepth 1 -name host.h)
do
BANGPY_HEAD_FILES_LIST+=(${link_file})
done
done
if [ -z "${BANGPY_LINK_FILE_LIST}" ]; then
echo "Could not find any linkable file, please check input operators."
exit -1
fi
gcc -shared -o ${BUILD_OUT_DIR}"libmluops.so" ${BANGPY_LINK_FILE_LIST[@]}
if [ -n "${BANGPY_HEAD_FILES_LIST}" ]; then
for i in ${BANGPY_HEAD_FILES_LIST[@]}
do
BANGPY_HEARDER_LIST_STR=${BANGPY_HEARDER_LIST_STR}"$i"","
done
BANGPY_HEARDER_LIST_STR=${BANGPY_HEARDER_LIST_STR%?}
fi
python3 ${BANGPY_UTILS_PATH}"generate_all_ops_header.py" ${BANGPY_HEARDER_LIST_STR}
# Delete the files of libmluops.so in the compiled directory.
for i in ${BANGPY_ALL_SO[@]}
do
rm $i
done
fi
if [ "${TEST_ENABLE}" == "True" ]; then
${BANGPY_UTILS_PATH}"test_operators.sh" ${ARGS} "--only_test"
fi
# rm all but libbangpy_ops.so and mluops.h
if [ "${BUILD_MODE}" == "Release" ]; then
for i in ${BANGPY_LINK_OP_DIR_LIST[@]}
do
rm ${BUILD_OUT_DIR}$i -rf
done
fi