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 4.1 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #!/bin/bash
  2. # Copyright 2019-2020 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. set -e
  17. BASEPATH=$(cd "$(dirname $0)"; pwd)
  18. OUTPUT_PATH="${BASEPATH}/output"
  19. export BUILD_PATH="${BASEPATH}/build/"
  20. # print usage message
  21. usage()
  22. {
  23. echo "Usage:"
  24. echo "sh build.sh [-j[n]] [-h] [-v] [-s] [-t] [-u] [-c]"
  25. echo ""
  26. echo "Options:"
  27. echo " -h Print usage"
  28. echo " -u Only compile ut, not execute"
  29. echo " -s Build st"
  30. echo " -j[n] Set the number of threads used for building Parser, default is 8"
  31. echo " -t Build and execute ut"
  32. echo " -c Build ut with coverage tag"
  33. echo " -v Display build command"
  34. echo "to be continued ..."
  35. }
  36. # parse and set options
  37. checkopts()
  38. {
  39. VERBOSE=""
  40. THREAD_NUM=8
  41. # ENABLE_GE_UT_ONLY_COMPILE="off"
  42. ENABLE_GE_UT="off"
  43. ENABLE_GE_ST="off"
  44. ENABLE_GE_COV="off"
  45. GE_ONLY="on"
  46. # Process the options
  47. while getopts 'ustchj:v' opt
  48. do
  49. OPTARG=$(echo ${OPTARG} | tr '[A-Z]' '[a-z]')
  50. case "${opt}" in
  51. u)
  52. # ENABLE_GE_UT_ONLY_COMPILE="on"
  53. ENABLE_GE_UT="on"
  54. GE_ONLY="off"
  55. ;;
  56. s)
  57. ENABLE_GE_ST="on"
  58. ;;
  59. t)
  60. ENABLE_GE_UT="on"
  61. GE_ONLY="off"
  62. ;;
  63. c)
  64. ENABLE_GE_COV="on"
  65. GE_ONLY="off"
  66. ;;
  67. h)
  68. usage
  69. exit 0
  70. ;;
  71. j)
  72. THREAD_NUM=$OPTARG
  73. ;;
  74. v)
  75. VERBOSE="VERBOSE=1"
  76. ;;
  77. *)
  78. echo "Undefined option: ${opt}"
  79. usage
  80. exit 1
  81. esac
  82. done
  83. }
  84. checkopts "$@"
  85. mk_dir() {
  86. local create_dir="$1" # the target to make
  87. mkdir -pv "${create_dir}"
  88. echo "created ${create_dir}"
  89. }
  90. # Parser build start
  91. echo "---------------- Parser build start ----------------"
  92. # create build path
  93. build_parser()
  94. {
  95. echo "create build directory and build Parser";
  96. mk_dir "${BUILD_PATH}"
  97. cd "${BUILD_PATH}"
  98. CMAKE_ARGS="-DBUILD_PATH=$BUILD_PATH -DGE_ONLY=$GE_ONLY"
  99. if [[ "X$ENABLE_GE_COV" = "Xon" ]]; then
  100. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_GE_COV=ON"
  101. fi
  102. if [[ "X$ENABLE_GE_UT" = "Xon" ]]; then
  103. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_GE_UT=ON"
  104. fi
  105. if [[ "X$ENABLE_GE_ST" = "Xon" ]]; then
  106. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_GE_ST=ON"
  107. fi
  108. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_OPEN_SRC=True -DCMAKE_INSTALL_PREFIX=${OUTPUT_PATH}"
  109. echo "${CMAKE_ARGS}"
  110. cmake ${CMAKE_ARGS} ..
  111. if [ 0 -ne $? ]
  112. then
  113. echo "execute command: cmake ${CMAKE_ARGS} .. failed."
  114. return 1
  115. fi
  116. make ${VERBOSE} -j${THREAD_NUM} && make install
  117. if [ 0 -ne $? ]
  118. then
  119. echo "execute command: make ${VERBOSE} -j${THREAD_NUM} && make install failed."
  120. return 1
  121. fi
  122. echo "Parser build success!"
  123. }
  124. g++ -v
  125. mk_dir ${OUTPUT_PATH}
  126. build_parser || { echo "Parser build failed."; return; }
  127. echo "---------------- Parser build finished ----------------"
  128. rm -f ${OUTPUT_PATH}/libgmock*.so
  129. rm -f ${OUTPUT_PATH}/libgtest*.so
  130. rm -f ${OUTPUT_PATH}/lib*_stub.so
  131. chmod -R 750 ${OUTPUT_PATH}
  132. find ${OUTPUT_PATH} -name "*.so*" -print0 | xargs -0 chmod 500
  133. echo "---------------- Parser output generated ----------------"
  134. # generate output package in tar form, including ut/st libraries/executables
  135. generate_package()
  136. {
  137. cd "${BASEPATH}"
  138. PARSER_LIB_PATH="lib"
  139. find output/ -name parser_lib.tar -exec rm {} \;
  140. cd "${OUTPUT_PATH}"
  141. tar -cf parser_lib.tar "${PARSER_LIB_PATH}"
  142. }
  143. if [[ "X$ENABLE_GE_UT" = "Xoff" ]]; then
  144. generate_package
  145. fi
  146. echo "---------------- Parser package archive generated ----------------"

Ascend CANN Parser(简称parser)配合TF_Adapter、 ATC工具、IR构图等使用,开发者通过以上工具,借助parser能方便地将第三方框架的算法表示转换成Ascend IR,充分利用昇腾AI处理器卓越的运算能力