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.

do_build_common.sh 6.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #!/bin/bash -e
  2. function handle_strip() {
  3. echo "now handle strip $1"
  4. objcopy --only-keep-debug $1 $1.dbg
  5. strip -s $1
  6. objcopy --add-gnu-debuglink=$1.dbg $1
  7. rm $1.dbg
  8. }
  9. function full_copy_so(){
  10. lib_path=$1
  11. dst_dir=$2
  12. append_rpath=$3
  13. lib_name=$(basename $lib_path)
  14. cp $lib_path $dst_dir/$lib_name
  15. if [ "$append_rpath" != "" ];then
  16. ori_rpath=$(patchelf --print-rpath $dst_dir/$lib_name)
  17. if [ "$ori_rpath" != "" ];then
  18. patchelf --set-rpath "$ori_rpath:$append_rpath" $dst_dir/$lib_name
  19. else
  20. patchelf --set-rpath "$append_rpath" $dst_dir/$lib_name
  21. fi
  22. fi
  23. }
  24. function handle_copy_cuda_libs() {
  25. TO_DIR=$1
  26. if [ ${BUILD_WHL_CPU_ONLY} = "OFF" ]; then
  27. echo "handle cuda lib to ${TO_DIR}"
  28. cp ${BUILD_DIR}/dnn/cuda-stub/libcuda_stub.so ${TO_DIR}
  29. handle_strip ${TO_DIR}/libcuda_stub.so
  30. cp /usr/local/cuda/lib64/libnvToolsExt.so.1 ${TO_DIR}
  31. IFS=: read -a lib_name_array <<<"$CUDA_COPY_LIB_LIST"
  32. append_rpath='$ORIGIN'
  33. for lib_name in ${lib_name_array[@]};do
  34. echo "cuda copy detail: ${lib_name} to ${TO_DIR}"
  35. full_copy_so $lib_name ${TO_DIR} $append_rpath
  36. done
  37. fi
  38. }
  39. function patch_elf_depend_lib_mgb_mge() {
  40. echo "handle common depend lib for mgb or mge"
  41. LIBS_DIR=${BUILD_DIR}/staging/megengine/core/lib
  42. mkdir -p ${LIBS_DIR}
  43. cp /usr/lib64/libatomic.so.1 ${LIBS_DIR}
  44. patchelf --remove-rpath ${BUILD_DIR}/staging/megengine/core/_imperative_rt.so
  45. patchelf --force-rpath --set-rpath '$ORIGIN/lib' ${BUILD_DIR}/staging/megengine/core/_imperative_rt.so
  46. handle_strip ${BUILD_DIR}/staging/megengine/core/_imperative_rt.so
  47. cp ${BUILD_DIR}/src/libmegengine_export.so ${LIBS_DIR}
  48. patchelf --remove-rpath ${LIBS_DIR}/libmegengine_export.so
  49. patchelf --force-rpath --set-rpath '$ORIGIN/.' ${LIBS_DIR}/libmegengine_export.so
  50. handle_strip ${LIBS_DIR}/libmegengine_export.so
  51. # as some version of cudnn/trt libs have dlopen libs, so we can not use auditwheel
  52. # TODO: PR for auditwheel to support args for dlopen libs
  53. handle_copy_cuda_libs ${LIBS_DIR}
  54. }
  55. SRC_DIR=$(readlink -f "`dirname $0`/../../../")
  56. source ${SRC_DIR}/scripts/whl/utils/utils.sh
  57. SUPPORT_ALL_VERSION="35m 36m 37m 38"
  58. ALL_PYTHON=${ALL_PYTHON}
  59. if [[ -z ${ALL_PYTHON} ]]
  60. then
  61. ALL_PYTHON=${SUPPORT_ALL_VERSION}
  62. else
  63. check_python_version_is_valid "${ALL_PYTHON}" "${SUPPORT_ALL_VERSION}"
  64. fi
  65. BUILD_WHL_CPU_ONLY=${BUILD_WHL_CPU_ONLY}
  66. if [[ -z ${BUILD_WHL_CPU_ONLY} ]]
  67. then
  68. BUILD_WHL_CPU_ONLY="OFF"
  69. fi
  70. BUILD_DIR=${SRC_DIR}/build_dir/host/MGE_WITH_CUDA_OFF/MGE_INFERENCE_ONLY_OFF/Release/build/
  71. if [ ${BUILD_WHL_CPU_ONLY} = "OFF" ]; then
  72. BUILD_DIR=${SRC_DIR}/build_dir/host/MGE_WITH_CUDA_ON/MGE_INFERENCE_ONLY_OFF/Release/build/
  73. fi
  74. # here we just treat cu file should not in the increment build file list
  75. INCREMENT_KEY_WORDS=".cu.o is dirty"
  76. IS_IN_FIRST_LOOP=TRUE
  77. ORG_EXTRA_CMAKE_FLAG=${EXTRA_CMAKE_FLAG}
  78. for ver in ${ALL_PYTHON}
  79. do
  80. # we want run a full clean build at the first loop
  81. if [ ${IS_IN_FIRST_LOOP} = "TRUE" ]; then
  82. # TODO: may all cmake issue can be resolved after rm CMakeCache?
  83. # if YES, remove this to use old cache and speed up CI
  84. echo "warning: remove old build_dir for the first loop"
  85. rm -rf ${BUILD_DIR}
  86. fi
  87. python_ver=${ver:0:2}
  88. MAJOR=${python_ver:0:1}
  89. MINOR=${ver:1}
  90. PYTHON_DIR=/opt/python/cp${python_ver}-cp${ver}/
  91. export EXTRA_CMAKE_ARGS="${ORG_EXTRA_CMAKE_FLAG} -DCMAKE_BUILD_TYPE=RelWithDebInfo"
  92. export EXTRA_CMAKE_ARGS="${EXTRA_CMAKE_ARGS} -DPYTHON_EXECUTABLE=${PYTHON_DIR}/bin/python3"
  93. export EXTRA_CMAKE_ARGS="${EXTRA_CMAKE_ARGS} -DPYTHON_LIBRARY=${PYTHON_DIR}lib/"
  94. export EXTRA_CMAKE_ARGS="${EXTRA_CMAKE_ARGS} -DPYTHON_INCLUDE_DIR=${PYTHON_DIR}include/python${MAJOR}.${MINOR}"
  95. export EXTRA_CMAKE_ARGS="${EXTRA_CMAKE_ARGS} -DMGE_WITH_ATLAS=ON"
  96. if [ -d "${BUILD_DIR}" ]; then
  97. # insure rm have args
  98. touch ${BUILD_DIR}/empty.so
  99. touch ${BUILD_DIR}/CMakeCache.txt
  100. find ${BUILD_DIR} -name "*.so" | xargs rm
  101. # as we now use increment build mode when switch python
  102. # But I do not known any more issue at CMakeLists.txt or not
  103. # so Force remove CMakeCache.txt
  104. find ${BUILD_DIR} -name CMakeCache.txt | xargs rm
  105. fi
  106. HOST_BUILD_ARGS="-t -s"
  107. if [ ${BUILD_WHL_CPU_ONLY} = "OFF" ]; then
  108. HOST_BUILD_ARGS="${HOST_BUILD_ARGS} -c"
  109. fi
  110. # call ninja dry run and check increment is invalid or not
  111. if [ ${IS_IN_FIRST_LOOP} = "FALSE" ]; then
  112. ninja_dry_run_and_check_increment "${SRC_DIR}/scripts/cmake-build/host_build.sh" "${HOST_BUILD_ARGS}" "${INCREMENT_KEY_WORDS}"
  113. fi
  114. # call real build
  115. echo "host_build.sh HOST_BUILD_ARGS: ${HOST_BUILD_ARGS}"
  116. ${SRC_DIR}/scripts/cmake-build/host_build.sh ${HOST_BUILD_ARGS}
  117. # check python api call setup.py
  118. cd ${BUILD_DIR}
  119. check_build_ninja_python_api ${ver}
  120. rm -rf staging
  121. mkdir -p staging
  122. cp -a imperative/python/{megengine,setup.py,requires.txt,requires-style.txt,requires-test.txt} staging/
  123. cd ${BUILD_DIR}/staging/megengine/core
  124. mkdir -p lib/ucx
  125. patch_elf_depend_lib_mgb_mge
  126. cd ${BUILD_DIR}/staging/
  127. ${PYTHON_DIR}/bin/python setup.py bdist_wheel
  128. cd /home/output
  129. mkdir -p ${SRC_DIR}/scripts/whl/manylinux2014/output/wheelhouse/${SDK_NAME}
  130. cd ${BUILD_DIR}/staging/dist/
  131. org_whl_name=`ls Meg*${ver}*.whl`
  132. compat_whl_name=`echo ${org_whl_name} | sed 's/linux/manylinux2014/'`
  133. echo "org whl name: ${org_whl_name}"
  134. echo "comapt whl name: ${compat_whl_name}"
  135. mv ${org_whl_name} ${SRC_DIR}/scripts/whl/manylinux2014/output/wheelhouse/${SDK_NAME}/${compat_whl_name}
  136. cd /home/output
  137. chown -R ${UID}.${UID} .
  138. # compat for root-less docker env to remove output at host side
  139. chmod -R 777 .
  140. echo "python $ver done"
  141. IS_IN_FIRST_LOOP=FALSE
  142. done

MegEngine 安装包中集成了使用 GPU 运行代码所需的 CUDA 环境,不用区分 CPU 和 GPU 版。 如果想要运行 GPU 程序,请确保机器本身配有 GPU 硬件设备并安装好驱动。 如果你想体验在云端 GPU 算力平台进行深度学习开发的感觉,欢迎访问 MegStudio 平台