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 8.6 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
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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] [-S on|off]"
  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 " -S Enable enable download cmake compile dependency from gitee , default off"
  35. echo "to be continued ..."
  36. }
  37. # check value of input is 'on' or 'off'
  38. # usage: check_on_off arg_value arg_name
  39. check_on_off()
  40. {
  41. if [[ "X$1" != "Xon" && "X$1" != "Xoff" ]]; then
  42. echo "Invalid value $1 for option -$2"
  43. usage
  44. exit 1
  45. fi
  46. }
  47. # parse and set options
  48. checkopts()
  49. {
  50. VERBOSE=""
  51. THREAD_NUM=8
  52. # ENABLE_GE_UT_ONLY_COMPILE="off"
  53. ENABLE_GE_UT="off"
  54. ENABLE_GE_ST="off"
  55. ENABLE_GE_COV="off"
  56. GE_ONLY="on"
  57. PLATFORM="inference"
  58. PRODUCT="normal"
  59. ENABLE_GITEE="off"
  60. # Process the options
  61. while getopts 'ustchj:p:g:vS:' opt
  62. do
  63. OPTARG=$(echo ${OPTARG} | tr '[A-Z]' '[a-z]')
  64. case "${opt}" in
  65. u)
  66. # ENABLE_GE_UT_ONLY_COMPILE="on"
  67. ENABLE_GE_UT="on"
  68. GE_ONLY="off"
  69. ;;
  70. s)
  71. ENABLE_GE_ST="on"
  72. ;;
  73. t)
  74. ENABLE_GE_UT="on"
  75. GE_ONLY="off"
  76. ;;
  77. c)
  78. ENABLE_GE_COV="on"
  79. GE_ONLY="off"
  80. ;;
  81. h)
  82. usage
  83. exit 0
  84. ;;
  85. j)
  86. THREAD_NUM=$OPTARG
  87. ;;
  88. v)
  89. VERBOSE="VERBOSE=1"
  90. ;;
  91. p)
  92. PLATFORM=$OPTARG
  93. ;;
  94. g)
  95. PRODUCT=$OPTARG
  96. ;;
  97. S)
  98. check_on_off $OPTARG S
  99. ENABLE_GITEE="$OPTARG"
  100. echo "enable download from gitee"
  101. ;;
  102. *)
  103. echo "Undefined option: ${opt}"
  104. usage
  105. exit 1
  106. esac
  107. done
  108. }
  109. checkopts "$@"
  110. mk_dir() {
  111. local create_dir="$1" # the target to make
  112. mkdir -pv "${create_dir}"
  113. echo "created ${create_dir}"
  114. }
  115. # GraphEngine build start
  116. echo "---------------- GraphEngine build start ----------------"
  117. # create build path
  118. build_graphengine()
  119. {
  120. echo "create build directory and build GraphEngine";
  121. mk_dir "${BUILD_PATH}/graphengine"
  122. cd "${BUILD_PATH}/graphengine"
  123. CMAKE_ARGS="-DBUILD_PATH=$BUILD_PATH -DGE_ONLY=$GE_ONLY"
  124. if [[ "X$ENABLE_GE_COV" = "Xon" ]]; then
  125. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_GE_COV=ON"
  126. fi
  127. if [[ "X$ENABLE_GE_UT" = "Xon" ]]; then
  128. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_GE_UT=ON"
  129. fi
  130. if [[ "X$ENABLE_GE_ST" = "Xon" ]]; then
  131. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_GE_ST=ON"
  132. fi
  133. if [[ "X$ENABLE_GITEE" = "Xon" ]]; then
  134. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_GITEE=ON"
  135. fi
  136. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_OPEN_SRC=True -DCMAKE_INSTALL_PREFIX=${OUTPUT_PATH} -DPLATFORM=${PLATFORM} -DPRODUCT=${PRODUCT}"
  137. echo "${CMAKE_ARGS}"
  138. cmake ${CMAKE_ARGS} ..
  139. if [ $? -ne 0 ]
  140. then
  141. echo "execute command: cmake ${CMAKE_ARGS} .. failed."
  142. return 1
  143. fi
  144. COMMON_TARGET="ge_common engine fmk_parser parser_common _caffe_parser fmk_onnx_parser graph register engine_conf.json optimizer_priority.pbtxt "
  145. TARGET=${COMMON_TARGET}
  146. if [ "x${PLATFORM}" = "xtrain" ]
  147. then
  148. TARGET="ge_runner ge_local_engine host_cpu_engine ${TARGET}"
  149. elif [ "x${PLATFORM}" = "xinference" ]
  150. then
  151. TARGET="ge_compiler atc_ge_local_engine atc_host_cpu_engine atc opensrc_ascendcl ${TARGET}"
  152. elif [ "x${PLATFORM}" = "xall" ]
  153. then
  154. # build all the target
  155. TARGET=""
  156. fi
  157. make ${VERBOSE} ${TARGET} -j${THREAD_NUM} && make install
  158. if [ $? -ne 0 ]
  159. then
  160. echo "execute command: make ${VERBOSE} -j${THREAD_NUM} && make install failed."
  161. return 1
  162. fi
  163. echo "GraphEngine build success!"
  164. }
  165. g++ -v
  166. build_graphengine
  167. echo "---------------- GraphEngine build finished ----------------"
  168. mk_dir ${OUTPUT_PATH}
  169. cp -rf "${BUILD_PATH}/graphengine/"*.so "${OUTPUT_PATH}"
  170. rm -rf "${OUTPUT_PATH}/"libproto*
  171. rm -f ${OUTPUT_PATH}/libgmock*.so
  172. rm -f ${OUTPUT_PATH}/libgtest*.so
  173. rm -f ${OUTPUT_PATH}/lib*_stub.so
  174. chmod -R 750 ${OUTPUT_PATH}
  175. find ${OUTPUT_PATH} -name "*.so*" -print0 | xargs -0 chmod 500
  176. echo "---------------- GraphEngine output generated ----------------"
  177. # if [[ "X$ENABLE_GE_ST" = "Xon" ]]; then
  178. # cp ${BUILD_PATH}/graphengine/tests/st/st_resnet50_train ${OUTPUT_PATH}
  179. # fi
  180. # if [[ "X$ENABLE_GE_UT" = "Xon" || "X$ENABLE_GE_COV" = "Xon" ]]; then
  181. # cp ${BUILD_PATH}/graphengine/tests/ut/common/graph/ut_libgraph ${OUTPUT_PATH}
  182. # cp ${BUILD_PATH}/graphengine/tests/ut/ge/ut_libge_multiparts_utest ${OUTPUT_PATH}
  183. # cp ${BUILD_PATH}/graphengine/tests/ut/ge/ut_libge_distinct_load_utest ${OUTPUT_PATH}
  184. # cp ${BUILD_PATH}/graphengine/tests/ut/ge/ut_libge_others_utest ${OUTPUT_PATH}
  185. # cp ${BUILD_PATH}/graphengine/tests/ut/ge/ut_libge_kernel_utest ${OUTPUT_PATH}
  186. # if [[ "X${ENABLE_GE_UT_ONLY_COMPILE}" != "Xon" ]]; then
  187. # 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}
  188. # echo ${LD_LIBRARY_PATH}
  189. # ${OUTPUT_PATH}/ut_libgraph &&
  190. # ${OUTPUT_PATH}/ut_libge_multiparts_utest &&
  191. # ${OUTPUT_PATH}/ut_libge_distinct_load_utest &&
  192. # ${OUTPUT_PATH}/ut_libge_others_utest &&
  193. # ${OUTPUT_PATH}/ut_libge_kernel_utest
  194. # if [[ "$?" -ne 0 ]]; then
  195. # echo "!!! UT FAILED, PLEASE CHECK YOUR CHANGES !!!"
  196. # exit 1;
  197. # fi
  198. # fi
  199. # if [[ "X$ENABLE_GE_COV" = "Xon" ]]; then
  200. # echo "Generating coverage statistics, please wait..."
  201. # cd ${BASEPATH}
  202. # rm -rf ${BASEPATH}/cov
  203. # mkdir ${BASEPATH}/cov
  204. # gcovr -r ./ --exclude 'third_party' --exclude 'build' --exclude 'tests' --exclude 'prebuild' --exclude 'inc' --print-summary --html --html-details -d -o cov/index.html
  205. # fi
  206. # fi
  207. # generate output package in tar form, including ut/st libraries/executables
  208. generate_package()
  209. {
  210. cd "${BASEPATH}"
  211. FWK_PATH="fwkacllib/lib64"
  212. ATC_PATH="atc/lib64"
  213. NNENGINE_PATH="plugin/nnengine/ge_config"
  214. OPSKERNEL_PATH="plugin/opskernel"
  215. ATC_LIB=("libc_sec.so" "libge_common.so" "libge_compiler.so" "libgraph.so")
  216. FWK_LIB=("libge_common.so" "libge_runner.so" "libgraph.so")
  217. rm -rf ${OUTPUT_PATH:?}/${FWK_PATH}/
  218. rm -rf ${OUTPUT_PATH:?}/${ATC_PATH}/
  219. mk_dir "${OUTPUT_PATH}/${FWK_PATH}/${NNENGINE_PATH}"
  220. mk_dir "${OUTPUT_PATH}/${FWK_PATH}/${OPSKERNEL_PATH}"
  221. mk_dir "${OUTPUT_PATH}/${ATC_PATH}/${NNENGINE_PATH}"
  222. mk_dir "${OUTPUT_PATH}/${ATC_PATH}/${OPSKERNEL_PATH}"
  223. find output/ -name graphengine_lib.tar -exec rm {} \;
  224. cp src/ge/engine_manager/engine_conf.json ${OUTPUT_PATH}/${FWK_PATH}/${NNENGINE_PATH}
  225. cp src/ge/engine_manager/engine_conf.json ${OUTPUT_PATH}/${ATC_PATH}/${NNENGINE_PATH}
  226. find output/ -maxdepth 1 -name libengine.so -exec cp -f {} ${OUTPUT_PATH}/${FWK_PATH}/${NNENGINE_PATH}/../ \;
  227. find output/ -maxdepth 1 -name libengine.so -exec cp -f {} ${OUTPUT_PATH}/${ATC_PATH}/${NNENGINE_PATH}/../ \;
  228. find output/ -maxdepth 1 -name libge_local_engine.so -exec cp -f {} ${OUTPUT_PATH}/${FWK_PATH}/${OPSKERNEL_PATH} \;
  229. find output/ -maxdepth 1 -name libge_local_engine.so -exec cp -f {} ${OUTPUT_PATH}/${ATC_PATH}/${OPSKERNEL_PATH} \;
  230. cd "${OUTPUT_PATH}"
  231. for lib in "${ATC_LIB[@]}";
  232. do
  233. cp "$lib" "${OUTPUT_PATH}/${ATC_PATH}"
  234. done
  235. for lib in "${FWK_LIB[@]}";
  236. do
  237. cp "$lib" "${OUTPUT_PATH}/${FWK_PATH}"
  238. done
  239. tar -cf graphengine_lib.tar fwkacllib/ atc/
  240. }
  241. if [[ "X$ENABLE_GE_UT" = "Xoff" ]]; then
  242. generate_package
  243. fi
  244. echo "---------------- GraphEngine package archive generated ----------------"

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