You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

cross_build_linux_arm_inference.sh 5.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. #!/usr/bin/env bash
  2. set -e
  3. ARCHS=("arm64-v8a" "armeabi-v7a-softfp" "armeabi-v7a-hardfp")
  4. BUILD_TYPE=Release
  5. MGE_WITH_CUDA=OFF
  6. MGE_ARMV8_2_FEATURE_FP16=OFF
  7. MGE_DISABLE_FLOAT16=OFF
  8. ARCH=arm64-v8a
  9. REMOVE_OLD_BUILD=false
  10. NINJA_VERBOSE=OFF
  11. NINJA_DRY_RUN=OFF
  12. SPECIFIED_TARGET="install/strip"
  13. READLINK=readlink
  14. OS=$(uname -s)
  15. if [ $OS = "Darwin" ];then
  16. READLINK=greadlink
  17. fi
  18. SRC_DIR=$($READLINK -f "`dirname $0`/../../")
  19. source $SRC_DIR/scripts/cmake-build/utils/utils.sh
  20. config_ninja_default_max_jobs
  21. echo "EXTRA_CMAKE_ARGS: ${EXTRA_CMAKE_ARGS}"
  22. function usage() {
  23. echo "$0 args1 args2 .."
  24. echo "available args detail:"
  25. echo "-d : Build with Debug mode, default Release mode"
  26. echo "-c : Build with CUDA, default without CUDA(for arm with cuda, example tx1)"
  27. echo "-f : enable MGE_ARMV8_2_FEATURE_FP16 for ARM64, need toolchain and hardware support"
  28. echo "-k : open MGE_DISABLE_FLOAT16 for NEON "
  29. echo "-a : config build arch available: ${ARCHS[@]}"
  30. echo "-r : remove old build dir before make, default off"
  31. echo "-v : ninja with verbose and explain, default off"
  32. echo "-n : ninja with -n dry run (don't run commands but act like they succeeded)"
  33. echo "-j : run N jobs in parallel for ninja, defaut is cpu_number + 2"
  34. echo "-e : build a specified target (always for debug, NOTICE: do not do strip/install target when use -e)"
  35. echo "-l : list CMakeLists.txt all options, can be use to config EXTRA_CMAKE_ARGS"
  36. echo "-h : show usage"
  37. echo "append other cmake config by config EXTRA_CMAKE_ARGS, for example, enable MGE_WITH_TEST and build with Debug mode:"
  38. echo "EXTRA_CMAKE_ARGS=\"-DMGE_WITH_TEST=ON\" $0 -d"
  39. exit -1
  40. }
  41. while getopts "lnvrkhdcfa:e:j:" arg
  42. do
  43. case $arg in
  44. j)
  45. NINJA_MAX_JOBS=$OPTARG
  46. echo "config NINJA_MAX_JOBS to ${NINJA_MAX_JOBS}"
  47. ;;
  48. l)
  49. echo "list CMakeLists.txt all options, can be used to config EXTRA_CMAKE_ARGS"
  50. show_cmakelist_options
  51. exit 0
  52. ;;
  53. d)
  54. echo "Build with Debug mode"
  55. BUILD_TYPE=Debug
  56. ;;
  57. c)
  58. echo "Build with CUDA"
  59. MGE_WITH_CUDA=ON
  60. ;;
  61. f)
  62. echo "enable MGE_ARMV8_2_FEATURE_FP16 for ARM64"
  63. MGE_ARMV8_2_FEATURE_FP16=ON
  64. ;;
  65. k)
  66. echo "open MGE_DISABLE_FLOAT16 for NEON"
  67. MGE_DISABLE_FLOAT16=ON
  68. ;;
  69. a)
  70. tmp_arch=null
  71. for arch in ${ARCHS[@]}; do
  72. if [ "$arch" = "$OPTARG" ]; then
  73. echo "CONFIG BUILD ARCH to : $OPTARG"
  74. tmp_arch=$OPTARG
  75. ARCH=$OPTARG
  76. break
  77. fi
  78. done
  79. if [ "$tmp_arch" = "null" ]; then
  80. echo "ERR args for arch (-a)"
  81. echo "available arch list: ${ARCHS[@]}"
  82. usage
  83. fi
  84. ;;
  85. h)
  86. echo "show usage"
  87. usage
  88. ;;
  89. r)
  90. echo "config REMOVE_OLD_BUILD=true"
  91. REMOVE_OLD_BUILD=true
  92. ;;
  93. v)
  94. echo "config NINJA_VERBOSE=ON"
  95. NINJA_VERBOSE=ON
  96. ;;
  97. n)
  98. echo "config NINJA_DRY_RUN=ON"
  99. NINJA_DRY_RUN=ON
  100. ;;
  101. e)
  102. SPECIFIED_TARGET=$OPTARG
  103. ;;
  104. ?)
  105. echo "unkonw argument"
  106. usage
  107. ;;
  108. esac
  109. done
  110. echo "----------------------------------------------------"
  111. echo "build config summary:"
  112. echo "BUILD_TYPE: $BUILD_TYPE"
  113. echo "MGE_WITH_CUDA: $MGE_WITH_CUDA"
  114. echo "MGE_ARMV8_2_FEATURE_FP16: $MGE_ARMV8_2_FEATURE_FP16"
  115. echo "MGE_DISABLE_FLOAT16: $MGE_DISABLE_FLOAT16"
  116. echo "SPECIFIED_TARGET: ${SPECIFIED_TARGET}"
  117. echo "NINJA_MAX_JOBS: ${NINJA_MAX_JOBS}"
  118. echo "ARCH: $ARCH"
  119. echo "----------------------------------------------------"
  120. if [[ $OS =~ "NT" ]]; then
  121. echo "BUILD in NT ..."
  122. fi
  123. if [ ! $OS = "Linux" ] && [ $MGE_WITH_CUDA = "ON" ];then
  124. echo "cross build for arm with cuda only support from Linux"
  125. exit -1
  126. fi
  127. if [ $MGE_WITH_CUDA = "ON" ] && [ ! $ARCH = "arm64-v8a" ];then
  128. echo "arm with cuda only support ARCH: arm64-v8a"
  129. exit -1
  130. fi
  131. function cmake_build() {
  132. BUILD_DIR=$SRC_DIR/build_dir/gnu-linux/MGE_WITH_CUDA_$3/$1/$BUILD_TYPE/build
  133. INSTALL_DIR=$BUILD_DIR/../install
  134. TOOLCHAIN=$SRC_DIR/toolchains/$2
  135. MGE_WITH_CUDA=$3
  136. echo "build dir: $BUILD_DIR"
  137. echo "install dir: $INSTALL_DIR"
  138. echo "build type: $BUILD_TYPE"
  139. echo "build toolchain: $TOOLCHAIN"
  140. echo "MGE_WITH_CUDA: $MGE_WITH_CUDA"
  141. try_remove_old_build $REMOVE_OLD_BUILD $BUILD_DIR $INSTALL_DIR
  142. echo "create build dir"
  143. mkdir -p $BUILD_DIR
  144. mkdir -p $INSTALL_DIR
  145. cd_real_build_dir $BUILD_DIR
  146. bash -c "cmake -G Ninja \
  147. -DCMAKE_TOOLCHAIN_FILE=$TOOLCHAIN \
  148. -DCMAKE_BUILD_TYPE=$BUILD_TYPE \
  149. -DMGE_INFERENCE_ONLY=ON \
  150. -DMGE_WITH_CUDA=$MGE_WITH_CUDA \
  151. -DMGE_ARMV8_2_FEATURE_FP16=$MGE_ARMV8_2_FEATURE_FP16 \
  152. -DMGE_DISABLE_FLOAT16=$MGE_DISABLE_FLOAT16 \
  153. -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR \
  154. ${EXTRA_CMAKE_ARGS} \
  155. $SRC_DIR "
  156. config_ninja_target_cmd ${NINJA_VERBOSE} "OFF" "${SPECIFIED_TARGET}" ${NINJA_DRY_RUN} ${NINJA_MAX_JOBS}
  157. bash -c "${NINJA_CMD}"
  158. }
  159. build_flatc $SRC_DIR $REMOVE_OLD_BUILD
  160. toolchain=null
  161. if [ "$ARCH" = "arm64-v8a" ]; then
  162. toolchain="aarch64-linux-gnu.toolchain.cmake"
  163. elif [ "$ARCH" = "armeabi-v7a-hardfp" ]; then
  164. toolchain="arm-linux-gnueabihf.toolchain.cmake"
  165. elif [ "$ARCH" = "armeabi-v7a-softfp" ]; then
  166. toolchain="arm-linux-gnueabi.toolchain.cmake"
  167. else
  168. echo "ERR CONFIG ABORT NOW!!"
  169. exit -1
  170. fi
  171. cmake_build $ARCH $toolchain $MGE_WITH_CUDA