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.

build.sh 3.7 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/bin/bash
  2. # Copyright 2021 Huawei Technologies Co., Ltd
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. # ============================================================================
  16. usage()
  17. {
  18. echo "Usage:"
  19. echo "bash build.sh [-e npu] "
  20. echo ""
  21. echo "Options:"
  22. echo " If set to -e npu, we will download the library of CPU+NPU, otherwise it will download the library of CPU+GPU by default."
  23. }
  24. BASEPATH=$(
  25. cd "$(dirname $0)" || exit
  26. pwd
  27. )
  28. get_version() {
  29. VERSION_MAJOR=$(grep "const int ms_version_major =" ${BASEPATH}/../../include/version.h | tr -dc "[0-9]")
  30. VERSION_MINOR=$(grep "const int ms_version_minor =" ${BASEPATH}/../../include/version.h | tr -dc "[0-9]")
  31. VERSION_REVISION=$(grep "const int ms_version_revision =" ${BASEPATH}/../../include/version.h | tr -dc "[0-9]")
  32. VERSION_STR=${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REVISION}
  33. }
  34. # check and set options
  35. checkopts()
  36. {
  37. # Init default values of build options
  38. DEVICE="GPU"
  39. SUPPORT_NPU="off"
  40. MINDSPORE_FILE_NAME="mindspore-lite-${VERSION_STR}-android-aarch64"
  41. MINDSPORE_FILE="${MINDSPORE_FILE_NAME}.tar.gz"
  42. MINDSPORE_LITE_DOWNLOAD_URL="https://ms-release.obs.cn-north-4.myhuaweicloud.com/${VERSION_STR}/MindSpore/lite/release/android/gpu/${MINDSPORE_FILE}"
  43. # Process the options
  44. while getopts 'e:h' opt
  45. do
  46. OPTARG=$(echo ${OPTARG} | tr '[A-Z]' '[a-z]')
  47. case "${opt}" in
  48. e)
  49. DEVICE=$OPTARG
  50. if [[ "X${DEVICE}" == "Xgpu" ]]; then
  51. continue
  52. elif [[ "X${DEVICE}" == "Xnpu" ]]; then
  53. MINDSPORE_FILE_NAME="mindspore-lite-${VERSION_STR}-android-aarch64"
  54. MINDSPORE_LITE_DOWNLOAD_URL="https://ms-release.obs.cn-north-4.myhuaweicloud.com/${VERSION_STR}/MindSpore/lite/release/android/${MINDSPORE_FILE}"
  55. SUPPORT_NPU="on"
  56. else
  57. echo "Unknown DEVICE option ${OPTARG}!"
  58. usage
  59. exit 1
  60. fi
  61. ;;
  62. h)
  63. usage
  64. exit 0
  65. ;;
  66. *)
  67. echo "Unknown option ${opt}!"
  68. usage
  69. exit 1
  70. esac
  71. done
  72. }
  73. get_version
  74. checkopts "$@"
  75. MODEL_DOWNLOAD_URL="https://download.mindspore.cn/model_zoo/official/lite/mobilenetv2_imagenet/mobilenetv2.ms"
  76. mkdir -p build
  77. mkdir -p lib
  78. mkdir -p model
  79. if [ ! -e ${BASEPATH}/model/mobilenetv2.ms ]; then
  80. wget -c -O ${BASEPATH}/model/mobilenetv2.ms --no-check-certificate ${MODEL_DOWNLOAD_URL}
  81. fi
  82. if [ ! -e ${BASEPATH}/build/${MINDSPORE_FILE} ]; then
  83. wget -c -O ${BASEPATH}/build/${MINDSPORE_FILE} --no-check-certificate ${MINDSPORE_LITE_DOWNLOAD_URL}
  84. fi
  85. tar xzvf ${BASEPATH}/build/${MINDSPORE_FILE} -C ${BASEPATH}/build/
  86. cp -r ${BASEPATH}/build/${MINDSPORE_FILE_NAME}/inference/lib/libmindspore-lite.a ${BASEPATH}/lib
  87. cp -r ${BASEPATH}/build/${MINDSPORE_FILE_NAME}/inference/include ${BASEPATH}/
  88. if [[ "X${DEVICE}" == "Xnpu" ]]; then
  89. cp -r ${BASEPATH}/build/${MINDSPORE_FILE_NAME}/inference/third_party/hiai_ddk/lib/*.so ${BASEPATH}/lib
  90. fi
  91. cd ${BASEPATH}/build || exit
  92. cmake -DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake" -DANDROID_NATIVE_API_LEVEL="19" \
  93. -DANDROID_NDK="${ANDROID_NDK}" -DANDROID_ABI="arm64-v8a" -DANDROID_STL="c++_shared" ${BASEPATH} -DSUPPORT_NPU=${SUPPORT_NPU}
  94. make && make install && make package