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 7.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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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}/graphengine"
  97. cd "${BUILD_PATH}/graphengine"
  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"
  109. echo "${CMAKE_ARGS}"
  110. cmake ${CMAKE_ARGS} ../..
  111. make ${VERBOSE} -j${THREAD_NUM}
  112. echo "GraphEngine build success!"
  113. }
  114. g++ -v
  115. build_graphengine
  116. echo "---------------- GraphEngine build finished ----------------"
  117. mk_dir ${OUTPUT_PATH}
  118. cp -rf "${BUILD_PATH}/graphengine/"*.so "${OUTPUT_PATH}"
  119. rm -rf "${OUTPUT_PATH}/"libproto*
  120. rm -f ${OUTPUT_PATH}/libgmock*.so
  121. rm -f ${OUTPUT_PATH}/libgtest*.so
  122. rm -f ${OUTPUT_PATH}/lib*_stub.so
  123. chmod -R 750 ${OUTPUT_PATH}
  124. find ${OUTPUT_PATH} -name "*.so*" -print0 | xargs -0 chmod 500
  125. echo "---------------- GraphEngine output generated ----------------"
  126. # if [[ "X$ENABLE_GE_ST" = "Xon" ]]; then
  127. # cp ${BUILD_PATH}/graphengine/tests/st/st_resnet50_train ${OUTPUT_PATH}
  128. # fi
  129. # if [[ "X$ENABLE_GE_UT" = "Xon" || "X$ENABLE_GE_COV" = "Xon" ]]; then
  130. # cp ${BUILD_PATH}/graphengine/tests/ut/common/graph/ut_libgraph ${OUTPUT_PATH}
  131. # cp ${BUILD_PATH}/graphengine/tests/ut/ge/ut_libge_multiparts_utest ${OUTPUT_PATH}
  132. # cp ${BUILD_PATH}/graphengine/tests/ut/ge/ut_libge_distinct_load_utest ${OUTPUT_PATH}
  133. # cp ${BUILD_PATH}/graphengine/tests/ut/ge/ut_libge_others_utest ${OUTPUT_PATH}
  134. # cp ${BUILD_PATH}/graphengine/tests/ut/ge/ut_libge_kernel_utest ${OUTPUT_PATH}
  135. # if [[ "X${ENABLE_GE_UT_ONLY_COMPILE}" != "Xon" ]]; then
  136. # 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}
  137. # echo ${LD_LIBRARY_PATH}
  138. # ${OUTPUT_PATH}/ut_libgraph &&
  139. # ${OUTPUT_PATH}/ut_libge_multiparts_utest &&
  140. # ${OUTPUT_PATH}/ut_libge_distinct_load_utest &&
  141. # ${OUTPUT_PATH}/ut_libge_others_utest &&
  142. # ${OUTPUT_PATH}/ut_libge_kernel_utest
  143. # if [[ "$?" -ne 0 ]]; then
  144. # echo "!!! UT FAILED, PLEASE CHECK YOUR CHANGES !!!"
  145. # exit 1;
  146. # fi
  147. # fi
  148. # if [[ "X$ENABLE_GE_COV" = "Xon" ]]; then
  149. # echo "Generating coverage statistics, please wait..."
  150. # cd ${BASEPATH}
  151. # rm -rf ${BASEPATH}/cov
  152. # mkdir ${BASEPATH}/cov
  153. # gcovr -r ./ --exclude 'third_party' --exclude 'build' --exclude 'tests' --exclude 'prebuild' --exclude 'inc' --print-summary --html --html-details -d -o cov/index.html
  154. # fi
  155. # fi
  156. # generate output package in tar form, including ut/st libraries/executables
  157. generate_package()
  158. {
  159. cd "${BASEPATH}"
  160. FWK_PATH="fwkacllib/lib64"
  161. ATC_PATH="atc/lib64"
  162. NNENGINE_PATH="plugin/nnengine/ge_config"
  163. OPSKERNEL_PATH="plugin/opskernel"
  164. ATC_LIB=("libc_sec.so" "libge_common.so" "libge_compiler.so" "libgraph.so")
  165. FWK_LIB=("libge_common.so" "libge_runner.so" "libgraph.so")
  166. rm -rf ${OUTPUT_PATH:?}/${FWK_PATH}/
  167. rm -rf ${OUTPUT_PATH:?}/${ATC_PATH}/
  168. mk_dir "${OUTPUT_PATH}/${FWK_PATH}/${NNENGINE_PATH}"
  169. mk_dir "${OUTPUT_PATH}/${FWK_PATH}/${OPSKERNEL_PATH}"
  170. mk_dir "${OUTPUT_PATH}/${ATC_PATH}/${NNENGINE_PATH}"
  171. mk_dir "${OUTPUT_PATH}/${ATC_PATH}/${OPSKERNEL_PATH}"
  172. find output/ -name graphengine_lib.tar -exec rm {} \;
  173. cp ge/engine_manager/engine_conf.json ${OUTPUT_PATH}/${FWK_PATH}/${NNENGINE_PATH}
  174. cp ge/engine_manager/engine_conf.json ${OUTPUT_PATH}/${ATC_PATH}/${NNENGINE_PATH}
  175. find output/ -maxdepth 1 -name libengine.so -exec cp -f {} ${OUTPUT_PATH}/${FWK_PATH}/${NNENGINE_PATH}/../ \;
  176. find output/ -maxdepth 1 -name libengine.so -exec cp -f {} ${OUTPUT_PATH}/${ATC_PATH}/${NNENGINE_PATH}/../ \;
  177. find output/ -maxdepth 1 -name libge_local_engine.so -exec cp -f {} ${OUTPUT_PATH}/${FWK_PATH}/${OPSKERNEL_PATH} \;
  178. find output/ -maxdepth 1 -name libge_local_engine.so -exec cp -f {} ${OUTPUT_PATH}/${ATC_PATH}/${OPSKERNEL_PATH} \;
  179. cd "${OUTPUT_PATH}"
  180. for lib in "${ATC_LIB[@]}";
  181. do
  182. cp "$lib" "${OUTPUT_PATH}/${ATC_PATH}"
  183. done
  184. for lib in "${FWK_LIB[@]}";
  185. do
  186. cp "$lib" "${OUTPUT_PATH}/${FWK_PATH}"
  187. done
  188. tar -cf graphengine_lib.tar fwkacllib/ atc/
  189. }
  190. if [[ "X$ENABLE_GE_UT" = "Xoff" ]]; then
  191. generate_package
  192. fi
  193. echo "---------------- GraphEngine package archive generated ----------------"

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