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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. #!/bin/bash -ex
  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. ALL_PYTHON=${ALL_PYTHON}
  56. if [[ -z ${ALL_PYTHON} ]]
  57. then
  58. ALL_PYTHON="35m 36m 37m 38"
  59. fi
  60. BUILD_WHL_CPU_ONLY=${BUILD_WHL_CPU_ONLY}
  61. if [[ -z ${BUILD_WHL_CPU_ONLY} ]]
  62. then
  63. BUILD_WHL_CPU_ONLY="OFF"
  64. fi
  65. SRC_DIR=$(readlink -f "`dirname $0`/../../../")
  66. source ${SRC_DIR}/scripts/whl/utils/utils.sh
  67. BUILD_DIR=${SRC_DIR}/build_dir/host/MGE_WITH_CUDA_OFF/MGE_INFERENCE_ONLY_OFF/Release/build/
  68. if [ ${BUILD_WHL_CPU_ONLY} = "OFF" ]; then
  69. BUILD_DIR=${SRC_DIR}/build_dir/host/MGE_WITH_CUDA_ON/MGE_INFERENCE_ONLY_OFF/Release/build/
  70. fi
  71. # here we just treat cu file should not in the increment build file list
  72. INCREMENT_KEY_WORDS=".cu.o is dirty"
  73. IS_IN_FIRST_LOOP=TRUE
  74. for ver in ${ALL_PYTHON}
  75. do
  76. # we want run a full clean build at the first loop
  77. if [ ${IS_IN_FIRST_LOOP} = "TRUE" ]; then
  78. # TODO: may all cmake issue can be resolved after rm CMakeCache?
  79. # if YES, remove this to use old cache and speed up CI
  80. echo "warning: remove old build_dir for the first loop"
  81. rm -rf ${BUILD_DIR}
  82. fi
  83. python_ver=${ver:0:2}
  84. MAJOR=${python_ver:0:1}
  85. MINOR=${ver:1}
  86. PYTHON_DIR=/opt/python/cp${python_ver}-cp${ver}/
  87. export EXTRA_CMAKE_ARGS="${EXTRA_CMAKE_ARGS} ${EXTRA_CMAKE_FLAG}"
  88. export EXTRA_CMAKE_ARGS="${EXTRA_CMAKE_ARGS} -DCMAKE_BUILD_TYPE=RelWithDebInfo"
  89. export EXTRA_CMAKE_ARGS="${EXTRA_CMAKE_ARGS} -DPYTHON_EXECUTABLE=${PYTHON_DIR}/bin/python3"
  90. export EXTRA_CMAKE_ARGS="${EXTRA_CMAKE_ARGS} -DPYTHON_LIBRARY=${PYTHON_DIR}lib/"
  91. export EXTRA_CMAKE_ARGS="${EXTRA_CMAKE_ARGS} -DPYTHON_INCLUDE_DIR=${PYTHON_DIR}include/python${MAJOR}.${MINOR}"
  92. export EXTRA_CMAKE_ARGS="${EXTRA_CMAKE_ARGS} -DMGE_WITH_ATLAS=ON"
  93. if [ -d "${BUILD_DIR}" ]; then
  94. # insure rm have args
  95. touch ${BUILD_DIR}/empty.so
  96. touch ${BUILD_DIR}/CMakeCache.txt
  97. find ${BUILD_DIR} -name "*.so" | xargs rm
  98. # as we now use increment build mode when switch python
  99. # But I do not known any more issue at CMakeLists.txt or not
  100. # so Force remove CMakeCache.txt
  101. find ${BUILD_DIR} -name CMakeCache.txt | xargs rm
  102. fi
  103. HOST_BUILD_ARGS="-t -s"
  104. if [ ${BUILD_WHL_CPU_ONLY} = "OFF" ]; then
  105. HOST_BUILD_ARGS="${HOST_BUILD_ARGS} -c"
  106. fi
  107. # call ninja dry run and check increment is invalid or not
  108. if [ ${IS_IN_FIRST_LOOP} = "FALSE" ]; then
  109. ninja_dry_run_and_check_increment "${SRC_DIR}/scripts/cmake-build/host_build.sh" "${HOST_BUILD_ARGS}" "${INCREMENT_KEY_WORDS}"
  110. fi
  111. # call real build
  112. echo "host_build.sh HOST_BUILD_ARGS: ${HOST_BUILD_ARGS}"
  113. ${SRC_DIR}/scripts/cmake-build/host_build.sh ${HOST_BUILD_ARGS}
  114. # check python api call setup.py
  115. cd ${BUILD_DIR}
  116. check_build_ninja_python_api ${ver}
  117. rm -rf staging
  118. mkdir -p staging
  119. cp -a imperative/python/{megengine,setup.py,requires.txt,requires-style.txt,requires-test.txt} staging/
  120. cd ${BUILD_DIR}/staging/megengine/core
  121. mkdir -p lib/ucx
  122. patch_elf_depend_lib_mgb_mge
  123. cd ${BUILD_DIR}/staging/
  124. ${PYTHON_DIR}/bin/python setup.py bdist_wheel
  125. cd /home/output
  126. mkdir -p ${SRC_DIR}/scripts/whl/manylinux2014/output/wheelhouse/${SDK_NAME}
  127. cd ${BUILD_DIR}/staging/dist/
  128. org_whl_name=`ls Meg*${ver}*.whl`
  129. compat_whl_name=`echo ${org_whl_name} | sed 's/linux/manylinux2014/'`
  130. echo "org whl name: ${org_whl_name}"
  131. echo "comapt whl name: ${compat_whl_name}"
  132. mv ${org_whl_name} ${SRC_DIR}/scripts/whl/manylinux2014/output/wheelhouse/${SDK_NAME}/${compat_whl_name}
  133. cd /home/output
  134. chown -R ${UID}.${UID} .
  135. # compat for root-less docker env to remove output at host side
  136. chmod -R 777 .
  137. echo "python $ver done"
  138. IS_IN_FIRST_LOOP=FALSE
  139. done

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