run_demo.sh 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. #!/bin/bash
  2. # Licensed to the Apache Software Foundation (ASF) under one
  3. # or more contributor license agreements. See the NOTICE file
  4. # distributed with this work for additional information
  5. # regarding copyright ownership. The ASF licenses this file
  6. # to you under the Apache License, Version 2.0 (the
  7. # "License"); you may not use this file except in compliance
  8. # with the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing,
  13. # software distributed under the License is distributed on an
  14. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. # KIND, either express or implied. See the License for the
  16. # specific language governing permissions and limitations
  17. # under the License.
  18. set -e
  19. set -u
  20. set -o pipefail
  21. # Show usage
  22. function show_usage() {
  23. cat <<EOF
  24. Usage: run_demo.sh
  25. -h, --help
  26. Display this help message.
  27. --cmsis_path CMSIS_PATH
  28. Set path to CMSIS.
  29. --ethosu_platform_path ETHOSU_PLATFORM_PATH
  30. Set path to Arm(R) Ethos(TM)-U core platform.
  31. --fvp_path FVP_PATH
  32. Set path to FVP.
  33. --cmake_path
  34. Set path to cmake.
  35. --enable_FVP
  36. Set 1 to run application on local Fixed Virtual Platforms (FVPs) executables.
  37. EOF
  38. }
  39. # Configure environment variables
  40. FVP_enable=0
  41. export PATH=/opt/arm/gcc-arm-none-eabi/bin:$PATH
  42. # Install python libraries
  43. echo -e "\e[36mInstall python libraries\e[0m"
  44. sudo pip install -r ./requirements.txt
  45. # Parse arguments
  46. while (( $# )); do
  47. case "$1" in
  48. -h|--help)
  49. show_usage
  50. exit 0
  51. ;;
  52. --cmsis_path)
  53. if [ $# -gt 1 ]
  54. then
  55. export CMSIS_PATH="$2"
  56. shift 2
  57. else
  58. echo 'ERROR: --cmsis_path requires a non-empty argument' >&2
  59. show_usage >&2
  60. exit 1
  61. fi
  62. ;;
  63. --ethosu_platform_path)
  64. if [ $# -gt 1 ]
  65. then
  66. export ETHOSU_PLATFORM_PATH="$2"
  67. shift 2
  68. else
  69. echo 'ERROR: --ethosu_platform_path requires a non-empty argument' >&2
  70. show_usage >&2
  71. exit 1
  72. fi
  73. ;;
  74. --fvp_path)
  75. if [ $# -gt 1 ]
  76. then
  77. export PATH="$2/models/Linux64_GCC-6.4:$PATH"
  78. shift 2
  79. else
  80. echo 'ERROR: --fvp_path requires a non-empty argument' >&2
  81. show_usage >&2
  82. exit 1
  83. fi
  84. ;;
  85. --cmake_path)
  86. if [ $# -gt 1 ]
  87. then
  88. export CMAKE="$2"
  89. shift 2
  90. else
  91. echo 'ERROR: --cmake_path requires a non-empty argument' >&2
  92. show_usage >&2
  93. exit 1
  94. fi
  95. ;;
  96. --enable_FVP)
  97. if [ $# -gt 1 ] && [ "$2" == "1" -o "$2" == "0" ];
  98. then
  99. FVP_enable="$2"
  100. shift 2
  101. else
  102. echo 'ERROR: --enable_FVP requires a right argument 1 or 0' >&2
  103. show_usage >&2
  104. exit 1
  105. fi
  106. ;;
  107. -*|--*)
  108. echo "Error: Unknown flag: $1" >&2
  109. show_usage >&2
  110. exit 1
  111. ;;
  112. esac
  113. done
  114. # Choose running environment: cloud(default) or local environment
  115. Platform="VHT_Corstone_SSE-300_Ethos-U55"
  116. if [ $FVP_enable == "1" ]; then
  117. Platform="FVP_Corstone_SSE-300_Ethos-U55"
  118. echo -e "\e[36mRun application on local Fixed Virtual Platforms (FVPs)\e[0m"
  119. else
  120. if [ ! -d "/opt/arm/" ]; then
  121. sudo ./configure_avh.sh
  122. fi
  123. fi
  124. # Directories
  125. script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
  126. # Make build directory
  127. make cleanall
  128. mkdir -p build
  129. cd build
  130. # Get PaddlePaddle inference model
  131. echo -e "\e[36mDownload PaddlePaddle inference model\e[0m"
  132. wget https://paddleocr.bj.bcebos.com/tvm/ocr_en.tar
  133. tar -xf ocr_en.tar
  134. # Compile model for Arm(R) Cortex(R)-M55 CPU and CMSIS-NN
  135. # An alternative to using "python3 -m tvm.driver.tvmc" is to call
  136. # "tvmc" directly once TVM has been pip installed.
  137. python3 -m tvm.driver.tvmc compile --target=cmsis-nn,c \
  138. --target-cmsis-nn-mcpu=cortex-m55 \
  139. --target-c-mcpu=cortex-m55 \
  140. --runtime=crt \
  141. --executor=aot \
  142. --executor-aot-interface-api=c \
  143. --executor-aot-unpacked-api=1 \
  144. --pass-config tir.usmp.enable=1 \
  145. --pass-config tir.usmp.algorithm=hill_climb \
  146. --pass-config tir.disable_storage_rewrite=1 \
  147. --pass-config tir.disable_vectorize=1 ocr_en/inference.pdmodel \
  148. --output-format=mlf \
  149. --model-format=paddle \
  150. --module-name=rec \
  151. --input-shapes x:[1,3,32,320] \
  152. --output=rec.tar
  153. tar -xf rec.tar
  154. # Create C header files
  155. cd ..
  156. python3 ./convert_image.py imgs_words_en/word_116.png
  157. # Build demo executable
  158. cd ${script_dir}
  159. echo ${script_dir}
  160. make
  161. # Run demo executable on the AVH
  162. $Platform -C cpu0.CFGDTCMSZ=15 \
  163. -C cpu0.CFGITCMSZ=15 -C mps3_board.uart0.out_file=\"-\" -C mps3_board.uart0.shutdown_tag=\"EXITTHESIM\" \
  164. -C mps3_board.visualisation.disable-visualisation=1 -C mps3_board.telnetterminal0.start_telnet=0 \
  165. -C mps3_board.telnetterminal1.start_telnet=0 -C mps3_board.telnetterminal2.start_telnet=0 -C mps3_board.telnetterminal5.start_telnet=0 \
  166. ./build/demo --stat