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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. BUILD_DIR=${SRC_DIR}/build_dir/host/MGE_WITH_CUDA_OFF/MGE_INFERENCE_ONLY_OFF/Release/build/
  67. if [ ${BUILD_WHL_CPU_ONLY} = "OFF" ]; then
  68. BUILD_DIR=${SRC_DIR}/build_dir/host/MGE_WITH_CUDA_ON/MGE_INFERENCE_ONLY_OFF/Release/build/
  69. fi
  70. for ver in ${ALL_PYTHON}
  71. do
  72. python_ver=${ver:0:2}
  73. MAJOR=${python_ver:0:1}
  74. MINOR=${ver:1}
  75. PYTHON_DIR=/opt/python/cp${python_ver}-cp${ver}/
  76. export EXTRA_CMAKE_ARGS="${EXTRA_CMAKE_ARGS} ${EXTRA_CMAKE_FLAG}"
  77. export EXTRA_CMAKE_ARGS="${EXTRA_CMAKE_ARGS} -DCMAKE_BUILD_TYPE=RelWithDebInfo"
  78. export EXTRA_CMAKE_ARGS="${EXTRA_CMAKE_ARGS} -DCMAKE_PREFIX_PATH=${PYTHON_DIR}"
  79. export EXTRA_CMAKE_ARGS="${EXTRA_CMAKE_ARGS} -DPYTHON_EXECUTABLE=${PYTHON_DIR}/bin/python3"
  80. export EXTRA_CMAKE_ARGS="${EXTRA_CMAKE_ARGS} -DPYTHON_LIBRARY=${PYTHON_DIR}lib/"
  81. export EXTRA_CMAKE_ARGS="${EXTRA_CMAKE_ARGS} -DPYTHON_INCLUDE_DIR=${PYTHON_DIR}include/python${MAJOR}.${MINOR}"
  82. export EXTRA_CMAKE_ARGS="${EXTRA_CMAKE_ARGS} -DMGE_WITH_ATLAS=ON"
  83. # TODO: after change to Ninja, only the fisrt loop need add -r to save build time
  84. if [ ${BUILD_WHL_CPU_ONLY} = "OFF" ]; then
  85. ${SRC_DIR}/scripts/cmake-build/host_build.sh -c -t -r
  86. else
  87. ${SRC_DIR}/scripts/cmake-build/host_build.sh -t -r
  88. fi
  89. cd ${BUILD_DIR}
  90. rm -rf staging
  91. mkdir -p staging
  92. cp -a imperative/python/{megengine,setup.py,requires.txt,requires-style.txt,requires-test.txt} staging/
  93. cd ${BUILD_DIR}/staging/megengine/core
  94. mkdir -p lib/ucx
  95. patch_elf_depend_lib_mgb_mge
  96. cd ${BUILD_DIR}/staging/
  97. ${PYTHON_DIR}/bin/python setup.py bdist_wheel
  98. cd /home/output
  99. mkdir -p ${SRC_DIR}/scripts/whl/manylinux2014/output/wheelhouse/${SDK_NAME}
  100. cd ${BUILD_DIR}/staging/dist/
  101. org_whl_name=`ls Meg*${ver}*.whl`
  102. compat_whl_name=`echo ${org_whl_name} | sed 's/linux/manylinux2014/'`
  103. echo "org whl name: ${org_whl_name}"
  104. echo "comapt whl name: ${compat_whl_name}"
  105. mv ${org_whl_name} ${SRC_DIR}/scripts/whl/manylinux2014/output/wheelhouse/${SDK_NAME}/${compat_whl_name}
  106. cd /home/output
  107. chown -R ${UID}.${UID} .
  108. # compat for root-less docker env to remove output at host side
  109. chmod -R 777 .
  110. echo "python $ver done"
  111. done

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