-
Notifications
You must be signed in to change notification settings - Fork 288
/
Copy pathbuild.sh
executable file
·76 lines (56 loc) · 1.98 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
#!/bin/bash
if [ $# != 1 ];then
echo "usage: $0 [delta|deltann]"
exit 1
fi
# be careful:
# delta depend on tensorflow python package
# deltann not depend on tensorflow python package
target=$1
if [ -z $MAIN_ROOT ];then
pushd ../../ && source env.sh && popd
echo "source env.sh"
fi
set -e
set -u
set -o pipefail
# check tf compiler version
if [ $target == 'delta' ];then
local_ver=`gcc --version | grep ^gcc | sed 's/^.* //g'`
tf_ver=`python -c "import tensorflow as tf; print(tf.version.COMPILER_VERSION.split()[0]);"`
if [ ${local_ver:0:1} -ne ${tf_ver:0:1} ];then
echo "gcc version($local_ver) not compatiable with tf compile version($tf_ver)"
exit -1
fi
fi
# prepare dependency
echo "build ops: prepare dependency"
if [ -L $MAIN_ROOT/core/ops/cppjieba ]; then
unlink $MAIN_ROOT/core/ops/cppjieba
fi
if ! [ -f $MAIN_ROOT/tools/cppjieba.done ]; then
pushd $MAIN_ROOT/tools && make cppjieba.done && popd
fi
ln -sf $MAIN_ROOT/tools/cppjieba $MAIN_ROOT/core/ops/cppjieba || { echo "build ops: link jieba error" ; exit 1; }
# clean
make clean &> /dev/null || exit 1
# compile custom ops under tensorflow/core/user_ops
if [ $target == 'delta' ];then
make -j $(nproc)
if [ ! -f ./x_ops.so ];then
echo "No x_ops.so generated. Compiling ops failed!"
exit 1
fi
elif [ $target == 'deltann' ]; then
ops_dir=$MAIN_ROOT/tools/tensorflow/tensorflow/core/user_ops/ops
if [ -L $ops_dir ] && [ -d $ops_dir ]; then
unlink $MAIN_ROOT/tools/tensorflow/tensorflow/core/user_ops/ops
fi
ln -sf $MAIN_ROOT/core/ops $MAIN_ROOT/tools/tensorflow/tensorflow/core/user_ops
python3 gen_build.py
pushd $MAIN_ROOT/tools/tensorflow
bazel build --verbose_failures -c opt //tensorflow/core/user_ops/ops:x_ops.so || { echo "compile custom ops error"; exit 1; }
cp bazel-bin/tensorflow/core/user_ops/ops/*.so $MAIN_ROOT/dpl/lib/custom_ops
cp $MAIN_ROOT/dpl/lib/custom_ops/x_ops.so $MAIN_ROOT/core/ops/
popd
fi