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

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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]] [-A] [-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 optionss
  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:vA' 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. ;;
  55. s)
  56. ENABLE_GE_ST="on"
  57. ;;
  58. t)
  59. ENABLE_GE_UT="on"
  60. ;;
  61. c)
  62. ENABLE_GE_COV="on"
  63. ;;
  64. h)
  65. usage
  66. exit 0
  67. ;;
  68. j)
  69. THREAD_NUM=$OPTARG
  70. ;;
  71. v)
  72. VERBOSE="VERBOSE=1"
  73. ;;
  74. A)
  75. usage
  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. make ${VERBOSE} -j${THREAD_NUM}
  111. echo "GraphEngine build success!"
  112. }
  113. g++ -v
  114. build_graphengine
  115. echo "---------------- GraphEngine build finished ----------------"
  116. mk_dir ${OUTPUT_PATH}
  117. cp -rf "${BUILD_PATH}/graphengine/"*.so "${OUTPUT_PATH}"
  118. rm -rf "${OUTPUT_PATH}/"libproto*
  119. rm -f ${OUTPUT_PATH}/libgmock*.so
  120. rm -f ${OUTPUT_PATH}/libgtest*.so
  121. rm -f ${OUTPUT_PATH}/lib*_stub.so
  122. chmod -R 750 ${OUTPUT_PATH}
  123. find ${OUTPUT_PATH} -name "*.so*" -print0 | xargs -0 chmod 500
  124. echo "---------------- GraphEngine output package generated ----------------"
  125. if [[ "X$ENABLE_GE_ST" = "Xon" ]]; then
  126. cp ${BUILD_PATH}/graphengine/tests/st/st_resnet50_train ${OUTPUT_PATH}
  127. fi
  128. if [[ "X$ENABLE_GE_UT" = "Xon" || "X$ENABLE_GE_COV" = "Xon" ]]; then
  129. cp ${BUILD_PATH}/graphengine/tests/ut/common/graph/ut_libgraph ${OUTPUT_PATH}
  130. cp ${BUILD_PATH}/graphengine/tests/ut/ge/ut_libge_multiparts_utest ${OUTPUT_PATH}
  131. cp ${BUILD_PATH}/graphengine/tests/ut/ge/ut_libge_distinct_load_utest ${OUTPUT_PATH}
  132. cp ${BUILD_PATH}/graphengine/tests/ut/ge/ut_libge_others_utest ${OUTPUT_PATH}
  133. cp ${BUILD_PATH}/graphengine/tests/ut/ge/ut_libge_kernel_utest ${OUTPUT_PATH}
  134. if [[ "X${ENABLE_GE_UT_ONLY_COMPILE}" != "Xon" ]]; then
  135. export LD_LIBRARY_PATH=${D_LINK_PATH}/x86_64/:${BUILD_PATH}/graphengine/:/usr/local/HiAI/driver/lib64:/usr/local/HiAI/runtime/lib64:${LD_LIBRARY_PATH}
  136. echo ${LD_LIBRARY_PATH}
  137. ${OUTPUT_PATH}/ut_libgraph &&
  138. ${OUTPUT_PATH}/ut_libge_multiparts_utest &&
  139. ${OUTPUT_PATH}/ut_libge_distinct_load_utest &&
  140. ${OUTPUT_PATH}/ut_libge_others_utest &&
  141. ${OUTPUT_PATH}/ut_libge_kernel_utest
  142. if [[ "$?" -ne 0 ]]; then
  143. echo "!!! UT FAILED, PLEASE CHECK YOUR CHANGES !!!"
  144. exit 1;
  145. fi
  146. fi
  147. if [[ "X$ENABLE_GE_COV" = "Xon" ]]; then
  148. echo "Generating coverage statistics, please wait..."
  149. cd ${BASEPATH}
  150. rm -rf ${BASEPATH}/cov
  151. mkdir ${BASEPATH}/cov
  152. gcovr -r ./ --exclude 'third_party' --exclude 'build' --exclude 'tests' --exclude 'prebuild' --exclude 'inc' --print-summary --html --html-details -d -o cov/index.html
  153. fi
  154. fi

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

Contributors (1)