bazel-adb-run.sh 2.1 KB
Newer Older
L
Liangliang He 已提交
1 2 3 4 5 6 7
#!/bin/bash

if [ "$#" -lt 1 ]; then
  echo "$0" bazel-target [cmd params]
  exit 1
fi

Y
yejianwu 已提交
8
MACE_SOURCE_DIR=`/bin/pwd`
9
CODEGEN_DIR=${MACE_SOURCE_DIR}/mace/codegen
L
Liangliang He 已提交
10 11 12 13 14 15 16 17 18 19 20
DEVICE_PATH=/data/local/tmp/mace
DEVICE_CL_PATH=$DEVICE_PATH/cl/
BAZEL_TARGET=$1
shift

# change //mace/a/b:c to bazel-bin/mace/a/b/c
BAZEL_BIN_PATH=`echo $BAZEL_TARGET | cut -d: -f1`
BAZEL_BIN_PATH=${BAZEL_BIN_PATH#//}
BAZEL_BIN_PATH=bazel-bin/$BAZEL_BIN_PATH
BIN_NAME=`echo $BAZEL_TARGET | cut -d: -f2`

21
ANDROID_ABI=armeabi-v7a
22
ANDROID_ABI=arm64-v8a
L
Liangliang He 已提交
23
STRIP="--strip always"
24
VLOG_LEVEL=0
25
PROFILING="1"
L
Liangliang He 已提交
26

Y
yejianwu 已提交
27 28
echo "Step 1: Generate encrypted opencl source"
python mace/python/tools/encrypt_opencl_codegen.py \
29 30 31
    --cl_kernel_dir=./mace/kernels/opencl/cl/ --output_path=${CODEGEN_DIR}/opencl/opencl_encrypt_program.cc

echo "Step 2: Generate version source"
L
Liangliang He 已提交
32
mkdir -p ${CODEGEN_DIR}/version
33
bash mace/tools/git/gen_version_source.sh ${CODEGEN_DIR}/version/version.cc
Y
yejianwu 已提交
34

35
echo "Step 3: Build target"
36 37
# -D_GLIBCXX_USE_C99_MATH_TR1 is used to solve include error instead
# of linking error which solved by -lm
38 39 40 41
bazel build -c opt $STRIP --verbose_failures $BAZEL_TARGET \
   --crosstool_top=//external:android/crosstool \
   --host_crosstool_top=@bazel_tools//tools/cpp:toolchain  \
   --cpu=$ANDROID_ABI \
42 43
   --copt="-std=c++11" \
   --copt="-D_GLIBCXX_USE_C99_MATH_TR1" \
44
   --copt="-DMACE_DISABLE_NO_TUNING_WARNING" \
45
   --copt="-Werror=return-type" \
46 47
   --copt="-O3" \
   --define neon=true \
L
liuqi 已提交
48
   --define openmp=true
49

L
Liangliang He 已提交
50 51 52 53
if [ $? -ne 0 ]; then
  exit 1
fi

54
echo "Step 4: Run target"
L
Liangliang He 已提交
55 56 57 58 59 60 61
du -hs $BAZEL_BIN_PATH/$BIN_NAME

for device in `adb devices | grep "^[A-Za-z0-9]\+[[:space:]]\+device$"| cut -f1`; do
  echo ======================================================================
  echo "Run on device: ${device}"
  adb -s ${device} shell "rm -rf $DEVICE_PATH"
  adb -s ${device} shell "mkdir -p $DEVICE_PATH"
62
  adb -s ${device} shell "mkdir -p $DEVICE_PATH/cl"
L
Liangliang He 已提交
63
  adb -s ${device} push $BAZEL_BIN_PATH/$BIN_NAME $DEVICE_PATH && \
64
  adb -s ${device} shell "MACE_OPENCL_PROFILING=$PROFILING MACE_KERNEL_PATH=$DEVICE_CL_PATH MACE_CPP_MIN_VLOG_LEVEL=$VLOG_LEVEL $DEVICE_PATH/$BIN_NAME $@"
L
Liangliang He 已提交
65
done