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

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

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