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

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