bazel-adb-run.sh 2.0 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 21
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`

ANDROID_ABI=arm64-v8a
22
ANDROID_ABI=armeabi-v7a
L
Liangliang He 已提交
23
STRIP="--strip always"
24 25
VLOG_LEVEL=0
PROFILINE="--define profiling=true"
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 32
    --cl_kernel_dir=./mace/kernels/opencl/cl/ --output_path=${CODEGEN_DIR}/opencl/opencl_encrypt_program.cc

echo "Step 2: Generate version source"
bash mace/tools/git/gen_version_source.sh ${CODEGEN_DIR}/version/version.cc
Y
yejianwu 已提交
33

34
echo "Step 3: Build target"
35 36
# -D_GLIBCXX_USE_C99_MATH_TR1 is used to solve include error instead
# of linking error which solved by -lm
37 38 39 40
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 \
41 42
   --copt="-std=c++11" \
   --copt="-D_GLIBCXX_USE_C99_MATH_TR1" \
43
   --copt="-DMACE_DISABLE_NO_TUNING_WARNING" \
44
   --copt="-Werror=return-type" \
45
   --define neon=false
46

L
Liangliang He 已提交
47 48 49 50
if [ $? -ne 0 ]; then
  exit 1
fi

51
echo "Step 4: Run target"
L
Liangliang He 已提交
52 53 54 55 56 57 58
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"
59
  adb -s ${device} shell "mkdir -p $DEVICE_PATH/cl"
L
Liangliang He 已提交
60
  adb -s ${device} push $BAZEL_BIN_PATH/$BIN_NAME $DEVICE_PATH && \
L
Liangliang He 已提交
61
  adb -s ${device} shell "MACE_KERNEL_PATH=$DEVICE_CL_PATH MACE_CPP_MIN_VLOG_LEVEL=$VLOG_LEVEL $DEVICE_PATH/$BIN_NAME $@"
L
Liangliang He 已提交
62
done