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 6.0 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
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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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 GraphEngine, 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. # GraphEngine build start
  91. echo "---------------- GraphEngine build start ----------------"
  92. # create build path
  93. build_graphengine()
  94. {
  95. echo "create build directory and build GraphEngine";
  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 [ $? -ne 0 ]
  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 [ $? -ne 0 ]
  118. then
  119. echo "execute command: make ${VERBOSE} -j${THREAD_NUM} && make install failed."
  120. return 1
  121. fi
  122. echo "GraphEngine build success!"
  123. }
  124. g++ -v
  125. mk_dir ${OUTPUT_PATH}
  126. build_graphengine || { echo "GraphEngine build failed."; return; }
  127. echo "---------------- GraphEngine build finished ----------------"
  128. #cp -rf "${BUILD_PATH}/graphengine/"*.so "${OUTPUT_PATH}"
  129. #rm -rf "${OUTPUT_PATH}/"libproto*
  130. rm -f ${OUTPUT_PATH}/libgmock*.so
  131. rm -f ${OUTPUT_PATH}/libgtest*.so
  132. rm -f ${OUTPUT_PATH}/lib*_stub.so
  133. chmod -R 750 ${OUTPUT_PATH}
  134. find ${OUTPUT_PATH} -name "*.so*" -print0 | xargs -0 chmod 500
  135. echo "---------------- GraphEngine output generated ----------------"
  136. # if [[ "X$ENABLE_GE_ST" = "Xon" ]]; then
  137. # cp ${BUILD_PATH}/graphengine/tests/st/st_resnet50_train ${OUTPUT_PATH}
  138. # fi
  139. # if [[ "X$ENABLE_GE_UT" = "Xon" || "X$ENABLE_GE_COV" = "Xon" ]]; then
  140. # cp ${BUILD_PATH}/graphengine/tests/ut/common/graph/ut_libgraph ${OUTPUT_PATH}
  141. # cp ${BUILD_PATH}/graphengine/tests/ut/ge/ut_libge_multiparts_utest ${OUTPUT_PATH}
  142. # cp ${BUILD_PATH}/graphengine/tests/ut/ge/ut_libge_distinct_load_utest ${OUTPUT_PATH}
  143. # cp ${BUILD_PATH}/graphengine/tests/ut/ge/ut_libge_others_utest ${OUTPUT_PATH}
  144. # cp ${BUILD_PATH}/graphengine/tests/ut/ge/ut_libge_kernel_utest ${OUTPUT_PATH}
  145. # if [[ "X${ENABLE_GE_UT_ONLY_COMPILE}" != "Xon" ]]; then
  146. # export LD_LIBRARY_PATH=${D_LINK_PATH}/x86_64/:${BUILD_PATH}../third_party/prebuild/x86_64/:${BUILD_PATH}/graphengine/:/usr/local/HiAI/driver/lib64:/usr/local/HiAI/runtime/lib64:${LD_LIBRARY_PATH}
  147. # echo ${LD_LIBRARY_PATH}
  148. # ${OUTPUT_PATH}/ut_libgraph &&
  149. # ${OUTPUT_PATH}/ut_libge_multiparts_utest &&
  150. # ${OUTPUT_PATH}/ut_libge_distinct_load_utest &&
  151. # ${OUTPUT_PATH}/ut_libge_others_utest &&
  152. # ${OUTPUT_PATH}/ut_libge_kernel_utest
  153. # if [[ "$?" -ne 0 ]]; then
  154. # echo "!!! UT FAILED, PLEASE CHECK YOUR CHANGES !!!"
  155. # exit 1;
  156. # fi
  157. # fi
  158. # if [[ "X$ENABLE_GE_COV" = "Xon" ]]; then
  159. # echo "Generating coverage statistics, please wait..."
  160. # cd ${BASEPATH}
  161. # rm -rf ${BASEPATH}/cov
  162. # mkdir ${BASEPATH}/cov
  163. # gcovr -r ./ --exclude 'third_party' --exclude 'build' --exclude 'tests' --exclude 'prebuild' --exclude 'inc' --print-summary --html --html-details -d -o cov/index.html
  164. # fi
  165. # fi
  166. # generate output package in tar form, including ut/st libraries/executables
  167. generate_package()
  168. {
  169. cd "${BASEPATH}"
  170. GRAPHENGINE_LIB_PATH="lib"
  171. find output/ -name graphengine_lib.tar -exec rm {} \;
  172. cd "${OUTPUT_PATH}"
  173. tar -cf graphengine_lib.tar "${GRAPHENGINE_LIB_PATH}"
  174. }
  175. if [[ "X$ENABLE_GE_UT" = "Xoff" ]]; then
  176. generate_package
  177. fi
  178. echo "---------------- GraphEngine package archive generated ----------------"

图引擎模块(GE)是MindSpore的一个子模块,其代码由C++实现,位于前端模块ME和底层硬件之间,起到承接作用。图引擎模块以ME下发的图作为输入,然后进行一系列的深度图优化操作,最后输出一张可以在底层硬件上高效运行的图。GE针对昇腾AI处理器的硬件结构特点,做了特定的优化工作,以此来充分发挥出昇腾AI处理器的强大算力。在进行模型训练/推理时,GE会被自动调用而用户并不感知.