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.

ge_cov.sh 3.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #!/bin/bash
  2. # Copyright 2021 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. function help(){
  18. cat <<-EOF
  19. Usage: ge cov [OPTIONS]
  20. Options:
  21. -a, --all Full coverage
  22. -i, --increment Increment coverage
  23. -d, --directory Coverage of directory
  24. -h, --help
  25. EOF
  26. }
  27. PROJECT_HOME=${PROJECT_HOME:-$(dirname "$0")/../../}
  28. PROJECT_HOME=$(cd $PROJECT_HOME || return; pwd)
  29. ALL_COV_GEN_PATH=${PROJECT_HOME}/cov/all
  30. DIFF_FILE_PATH=${PROJECT_HOME}/cov/diff
  31. DIFF_FILE_NAME=${DIFF_FILE_PATH}/inc_change_diff.txt
  32. function process_diff_format(){
  33. sed -i "s/--- a/--- \/code\/Turing\/graphEngine/g" ${DIFF_FILE_NAME}
  34. sed -i "s/+++ b/+++ \/code\/Turing\/graphEngine/g" ${DIFF_FILE_NAME}
  35. }
  36. function add_cov_generate(){
  37. addlcov --diff ${ALL_COV_GEN_PATH}/coverage.info ${DIFF_FILE_NAME} -o ${PROJECT_HOME}/cov/diff/inc_coverage.info
  38. }
  39. function gen_add_cov_html(){
  40. genhtml --prefix ${PROJECT_HOME} -o ${PROJECT_HOME}/cov/diff/html ${PROJECT_HOME}/cov/diff/inc_coverage.info --legend -t CHG --no-branch-coverage --no-function-coverage
  41. }
  42. function increment_cov_for_directory(){
  43. [ -n "${DIFF_FILE_PATH}" ] && rm -rf "${DIFF_FILE_PATH}"
  44. mkdir -p ${DIFF_FILE_PATH}
  45. git diff HEAD -- $1 >>${DIFF_FILE_NAME}
  46. process_diff_format
  47. add_cov_generate
  48. gen_add_cov_html
  49. }
  50. function run_all_coverage(){
  51. [ -n "${ALL_COV_GEN_PATH}" ] && rm -rf ${ALL_COV_GEN_PATH}
  52. mkdir -p ${ALL_COV_GEN_PATH}
  53. pushd "${PWD}" >/dev/null
  54. cd ${PROJECT_HOME}
  55. lcov -c -d build/tests/ut/ge -d build/tests/ut/common/graph/ -o ${ALL_COV_GEN_PATH}/tmp.info
  56. lcov -r ${ALL_COV_GEN_PATH}/tmp.info '*/output/*' '*/build/opensrc/*' '*/build/proto/*' '*/third_party/*' '*/tests/*' '/usr/local/*' '/usr/include/*' '*/metadef/*' '*/parser/*' -o ${ALL_COV_GEN_PATH}/coverage.info
  57. cd ${ALL_COV_GEN_PATH}
  58. genhtml coverage.info
  59. popd >/dev/null
  60. }
  61. function do_coverage_run(){
  62. local cov_mode=$1
  63. local directory_dir=$2
  64. run_all_coverage
  65. if [ "$cov_mode" = "all" ]; then
  66. exit 1
  67. elif [ -n "$directory_dir" ]; then
  68. increment_cov_for_directory $directory_dir
  69. else
  70. increment_cov_for_directory "ge"
  71. fi
  72. }
  73. function parse_args(){
  74. parsed_args=$(getopt -a -o aid::h --long all,increment,directory::,help -- "$@") || {
  75. help
  76. exit 1
  77. }
  78. if [ $# -lt 1 ]; then
  79. run_all_coverage
  80. exit 1
  81. fi
  82. local cov_mode="increment"
  83. local directory_dir=
  84. eval set -- "$parsed_args"
  85. while true; do
  86. case "$1" in
  87. -a | --all)
  88. cov_mode="all"
  89. ;;
  90. -i | --increment)
  91. ;;
  92. -d | --directory)
  93. directory_dir=$2
  94. shift
  95. ;;
  96. -h | --help)
  97. help; exit 1;
  98. ;;
  99. --)
  100. shift; break;
  101. ;;
  102. *)
  103. help; exit 1;
  104. ;;
  105. esac
  106. shift
  107. done
  108. do_coverage_run $cov_mode $directory_dir
  109. }
  110. function main(){
  111. parse_args "$@"
  112. }
  113. main "$@"
  114. set +e

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