generate_opencl_code.sh 1.5 KB
Newer Older
L
liuqi 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#!/usr/bin/env bash

Usage() {
  echo "Usage: bash tools/genenrate_opencl_code.sh type [target_soc] [cl_bin_dirs] [pull_or_not]"
}

if [ $# -lt 1 ]; then
  Usage
  exit 1
fi

CURRENT_DIR=`dirname $0`
source ${CURRENT_DIR}/env.sh

TYPE=$1
TARGET_SOC=$2
CL_BIN_DIRS=$3
PULL_OR_NOT=$4

L
liuqi 已提交
20 21
mkdir -p ${CL_CODEGEN_DIR}

L
liuqi 已提交
22 23 24 25 26 27 28
if [ x"$TYPE" == x"source" ];then
  python mace/python/tools/encrypt_opencl_codegen.py \
    --cl_kernel_dir=./mace/kernels/opencl/cl/ \
    --output_path=${CODEGEN_DIR}/opencl/opencl_encrypt_program.cc || exit 1
elif [ x"$#" == x"1" ];then

  python mace/python/tools/opencl_codegen.py \
29 30
    --built_kernel_file_name=${CL_BUILT_KERNEL_FILE_NAME} \
    --platform_info_file_name=${CL_PLATFORM_INFO_FILE_NAME} \
L
liuqi 已提交
31 32 33 34 35 36 37 38 39 40 41 42 43 44
    --output_path=${CL_CODEGEN_DIR}/opencl_compiled_program.cc || exit 1

else
  RESULT_VALUE=`echo_device_id_by_soc $TARGET_SOC`
  if [ $? -ne 0 ]; then
    echo $RESULT_VALUE
    exit 1
  else
    DEVICE_ID=$RESULT_VALUE
  fi

  if [ "$PULL_OR_NOT" = 1 ]; then
    CL_BIN_DIR=${CL_BIN_DIRS}
    mkdir -p ${CL_BIN_DIR}
45 46
    rm -rf ${CL_BIN_DIR}/${CL_BUILT_KERNEL_FILE_NAME}
    rm -rf ${CL_BIN_DIR}/${CL_PLATFORM_INFO_FILE_NAME}
L
liuqi 已提交
47 48 49 50 51 52
    if [ x"$TARGET_ABI" != x"host" ]; then
      adb -s $DEVICE_ID pull ${COMPILED_PROGRAM_DIR}/. ${CL_BIN_DIR} > /dev/null
    fi
  fi

  python mace/python/tools/opencl_codegen.py \
53 54
    --built_kernel_file_name=${CL_BUILT_KERNEL_FILE_NAME} \
    --platform_info_file_name=${CL_PLATFORM_INFO_FILE_NAME} \
L
liuqi 已提交
55 56 57 58
    --cl_binary_dirs=${CL_BIN_DIRS} \
    --output_path=${CL_CODEGEN_DIR}/opencl_compiled_program.cc || exit 1
fi