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.9 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
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
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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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] [-p]"
  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 "to be continued ..."
  36. }
  37. # parse and set options
  38. checkopts()
  39. {
  40. VERBOSE=""
  41. THREAD_NUM=8
  42. # ENABLE_GE_UT_ONLY_COMPILE="off"
  43. ENABLE_GE_UT="off"
  44. ENABLE_GE_ST="off"
  45. ENABLE_GE_COV="off"
  46. GE_ONLY="on"
  47. PLATFORM="inference"
  48. PRODUCT="normal"
  49. # Process the options
  50. while getopts 'ustchj:p:g:v' opt
  51. do
  52. OPTARG=$(echo ${OPTARG} | tr '[A-Z]' '[a-z]')
  53. case "${opt}" in
  54. u)
  55. # ENABLE_GE_UT_ONLY_COMPILE="on"
  56. ENABLE_GE_UT="on"
  57. GE_ONLY="off"
  58. ;;
  59. s)
  60. ENABLE_GE_ST="on"
  61. ;;
  62. t)
  63. ENABLE_GE_UT="on"
  64. GE_ONLY="off"
  65. ;;
  66. c)
  67. ENABLE_GE_COV="on"
  68. GE_ONLY="off"
  69. ;;
  70. h)
  71. usage
  72. exit 0
  73. ;;
  74. j)
  75. THREAD_NUM=$OPTARG
  76. ;;
  77. v)
  78. VERBOSE="VERBOSE=1"
  79. ;;
  80. p)
  81. PLATFORM=$OPTARG
  82. ;;
  83. g)
  84. PRODUCT=$OPTARG
  85. ;;
  86. *)
  87. echo "Undefined option: ${opt}"
  88. usage
  89. exit 1
  90. esac
  91. done
  92. }
  93. checkopts "$@"
  94. mk_dir() {
  95. local create_dir="$1" # the target to make
  96. mkdir -pv "${create_dir}"
  97. echo "created ${create_dir}"
  98. }
  99. # GraphEngine build start
  100. echo "---------------- GraphEngine build start ----------------"
  101. # create build path
  102. build_graphengine()
  103. {
  104. echo "create build directory and build GraphEngine";
  105. mk_dir "${BUILD_PATH}"
  106. cd "${BUILD_PATH}"
  107. CMAKE_ARGS="-DBUILD_PATH=$BUILD_PATH -DGE_ONLY=$GE_ONLY"
  108. if [[ "X$ENABLE_GE_COV" = "Xon" ]]; then
  109. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_GE_COV=ON"
  110. fi
  111. if [[ "X$ENABLE_GE_UT" = "Xon" ]]; then
  112. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_GE_UT=ON"
  113. fi
  114. if [[ "X$ENABLE_GE_ST" = "Xon" ]]; then
  115. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_GE_ST=ON"
  116. fi
  117. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_OPEN_SRC=True -DCMAKE_INSTALL_PREFIX=${OUTPUT_PATH} -DPLATFORM=${PLATFORM} -DPRODUCT=${PRODUCT}"
  118. echo "${CMAKE_ARGS}"
  119. cmake ${CMAKE_ARGS} ..
  120. if [ $? -ne 0 ]
  121. then
  122. echo "execute command: cmake ${CMAKE_ARGS} .. failed."
  123. return 1
  124. fi
  125. COMMON_TARGET="ge_common engine fmk_parser parser_common _caffe_parser fmk_onnx_parser graph register "
  126. TARGET=${COMMON_TARGET}
  127. if [ "x${PLATFORM}" = "xtrain" ]
  128. then
  129. TARGET="ge_runner ge_local_engine ge_local_opskernel_builder host_cpu_engine host_cpu_opskernel_builder ${TARGET}"
  130. elif [ "x${PLATFORM}" = "xinference" ]
  131. then
  132. 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}"
  133. elif [ "x${PLATFORM}" = "xall" ]
  134. then
  135. # build all the target
  136. TARGET=""
  137. fi
  138. make ${VERBOSE} ${TARGET} -j${THREAD_NUM} && make install
  139. if [ $? -ne 0 ]
  140. then
  141. echo "execute command: make ${VERBOSE} -j${THREAD_NUM} && make install failed."
  142. return 1
  143. fi
  144. echo "GraphEngine build success!"
  145. }
  146. g++ -v
  147. mk_dir ${OUTPUT_PATH}
  148. build_graphengine || { echo "GraphEngine build failed."; return; }
  149. echo "---------------- GraphEngine build finished ----------------"
  150. #cp -rf "${BUILD_PATH}/graphengine/"*.so "${OUTPUT_PATH}"
  151. #rm -rf "${OUTPUT_PATH}/"libproto*
  152. rm -f ${OUTPUT_PATH}/libgmock*.so
  153. rm -f ${OUTPUT_PATH}/libgtest*.so
  154. rm -f ${OUTPUT_PATH}/lib*_stub.so
  155. chmod -R 750 ${OUTPUT_PATH}
  156. find ${OUTPUT_PATH} -name "*.so*" -print0 | xargs -0 chmod 500
  157. echo "---------------- GraphEngine output generated ----------------"
  158. # if [[ "X$ENABLE_GE_ST" = "Xon" ]]; then
  159. # cp ${BUILD_PATH}/graphengine/tests/st/st_resnet50_train ${OUTPUT_PATH}
  160. # fi
  161. # if [[ "X$ENABLE_GE_UT" = "Xon" || "X$ENABLE_GE_COV" = "Xon" ]]; then
  162. # cp ${BUILD_PATH}/graphengine/tests/ut/common/graph/ut_libgraph ${OUTPUT_PATH}
  163. # cp ${BUILD_PATH}/graphengine/tests/ut/ge/ut_libge_multiparts_utest ${OUTPUT_PATH}
  164. # cp ${BUILD_PATH}/graphengine/tests/ut/ge/ut_libge_distinct_load_utest ${OUTPUT_PATH}
  165. # cp ${BUILD_PATH}/graphengine/tests/ut/ge/ut_libge_others_utest ${OUTPUT_PATH}
  166. # cp ${BUILD_PATH}/graphengine/tests/ut/ge/ut_libge_kernel_utest ${OUTPUT_PATH}
  167. # if [[ "X${ENABLE_GE_UT_ONLY_COMPILE}" != "Xon" ]]; then
  168. # 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}
  169. # echo ${LD_LIBRARY_PATH}
  170. # ${OUTPUT_PATH}/ut_libgraph &&
  171. # ${OUTPUT_PATH}/ut_libge_multiparts_utest &&
  172. # ${OUTPUT_PATH}/ut_libge_distinct_load_utest &&
  173. # ${OUTPUT_PATH}/ut_libge_others_utest &&
  174. # ${OUTPUT_PATH}/ut_libge_kernel_utest
  175. # if [[ "$?" -ne 0 ]]; then
  176. # echo "!!! UT FAILED, PLEASE CHECK YOUR CHANGES !!!"
  177. # exit 1;
  178. # fi
  179. # fi
  180. # if [[ "X$ENABLE_GE_COV" = "Xon" ]]; then
  181. # echo "Generating coverage statistics, please wait..."
  182. # cd ${BASEPATH}
  183. # rm -rf ${BASEPATH}/cov
  184. # mkdir ${BASEPATH}/cov
  185. # gcovr -r ./ --exclude 'third_party' --exclude 'build' --exclude 'tests' --exclude 'prebuild' --exclude 'inc' --print-summary --html --html-details -d -o cov/index.html
  186. # fi
  187. # fi
  188. # generate output package in tar form, including ut/st libraries/executables
  189. generate_package()
  190. {
  191. cd "${BASEPATH}"
  192. GRAPHENGINE_LIB_PATH="lib"
  193. cd "${OUTPUT_PATH}"
  194. find ./ -name graphengine_lib.tar -exec rm {} \;
  195. find ./bin -name atc -exec cp {} "${OUTPUT_PATH}/${GRAPHENGINE_LIB_PATH}" \;
  196. tar -cf graphengine_lib.tar "${GRAPHENGINE_LIB_PATH}"
  197. }
  198. if [[ "X$ENABLE_GE_UT" = "Xoff" ]]; then
  199. generate_package
  200. fi
  201. echo "---------------- GraphEngine package archive generated ----------------"

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