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.

windows_build_whl.sh 4.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #!/bin/bash -e
  2. NT=$(echo `uname` | grep "NT")
  3. echo $NT
  4. if [ -z "$NT" ];then
  5. echo "only run at windows bash env"
  6. echo "pls consider install bash-like tools, eg MSYS or git-cmd, etc"
  7. exit -1
  8. fi
  9. function err_env() {
  10. echo "check_env failed: pls refs ${SRC_DIR}/scripts/whl/BUILD_PYTHON_WHL_README.md to init env"
  11. exit -1
  12. }
  13. function append_path_env_and_check() {
  14. echo "export swig pwd to PATH"
  15. export PATH=/c/Users/${USER}/swigwin-4.0.2::$PATH
  16. echo "export vs2019 install path"
  17. export VS_PATH=/c/Program\ Files\ \(x86\)/Microsoft\ Visual\ Studio/2019/Enterprise
  18. # for llvm-strip
  19. export PATH=$VS_PATH/VC/Tools/Llvm/bin/:$PATH
  20. }
  21. append_path_env_and_check
  22. SRC_DIR=$(READLINK -f "`dirname $0`/../../../")
  23. ALL_PYTHON=${ALL_PYTHON}
  24. FULL_PYTHON_VER="3.5.4 3.6.8 3.7.7 3.8.3"
  25. if [[ -z ${ALL_PYTHON} ]]
  26. then
  27. ALL_PYTHON=${FULL_PYTHON_VER}
  28. fi
  29. PYTHON_DIR=
  30. PYTHON_LIBRARY=
  31. PYTHON_INCLUDE_DIR=
  32. WINDOWS_WHL_HOME=${SRC_DIR}/scripts/whl/windows/windows_whl_home
  33. if [ -e "${WINDOWS_WHL_HOME}" ]; then
  34. echo "remove old windows whl file"
  35. rm -rf ${WINDOWS_WHL_HOME}
  36. fi
  37. mkdir -p ${WINDOWS_WHL_HOME}
  38. function config_python_env() {
  39. PYTHON_DIR=/c/Users/${USER}/mge_whl_python_env/$1
  40. PYTHON_BIN=${PYTHON_DIR}
  41. if [ ! -f "$PYTHON_BIN/python3.exe" ]; then
  42. echo "ERR: can not find $PYTHON_BIN , Invalid python package"
  43. echo "now support list: ${FULL_PYTHON_VER}"
  44. err_env
  45. else
  46. echo "put python3 to env..."
  47. export PATH=${PYTHON_BIN}:$PATH
  48. which python3
  49. fi
  50. echo ${ver}
  51. PYTHON_LIBRARY=${PYTHON_DIR}/libs/python3.lib
  52. PYTHON_INCLUDE_DIR=${PYTHON_DIR}/include
  53. }
  54. function do_build() {
  55. for ver in ${ALL_PYTHON}
  56. do
  57. #config
  58. config_python_env ${ver}
  59. #check env
  60. if [ ! -f "$PYTHON_LIBRARY" ]; then
  61. echo "ERR: can not find $PYTHON_LIBRARY , Invalid python package"
  62. err_env
  63. fi
  64. if [ ! -d "$PYTHON_INCLUDE_DIR" ]; then
  65. echo "ERR: can not find $PYTHON_INCLUDE_DIR , Invalid python package"
  66. err_env
  67. fi
  68. echo "PYTHON_LIBRARY: ${PYTHON_LIBRARY}"
  69. echo "PYTHON_INCLUDE_DIR: ${PYTHON_INCLUDE_DIR}"
  70. #append cmake args for config python
  71. #FIXME: ninja handle err with cmake 3.17 when assgin PYTHON_LIBRARY
  72. #But after put python3.exe to HEAD of PATH by config_python_env, cmake can also handle the
  73. #right PYTHON_LIBRARY and PYTHON_INCLUDE_DIR, at the same time, clang-cl need swig target
  74. #force LINK a real PYTHON_LIBRARY file, after test we do not find the symbols conflict with python
  75. #export EXTRA_CMAKE_ARGS="-DPYTHON_LIBRARY=${PYTHON_LIBRARY} -DPYTHON_INCLUDE_DIR=${PYTHON_INCLUDE_DIR} "
  76. #config build type to RelWithDebInfo to enable MGB_ENABLE_DEBUG_UTIL etc
  77. export EXTRA_CMAKE_ARGS=${EXTRA_CMAKE_ARGS}" -DCMAKE_BUILD_TYPE=RelWithDebInfo "
  78. #call build and install
  79. #FIXME: cmake do not triger update python config, after
  80. #change PYTHON_LIBRARY and PYTHON_INCLUDE_DIR, so add
  81. #-r to remove build cache after a new ver build, which
  82. #will be more slow build than without -r
  83. ${SRC_DIR}/scripts/cmake-build/host_build.sh -t -r
  84. #call setup.py
  85. BUILD_DIR=${SRC_DIR}/build_dir/host/build/
  86. cd ${BUILD_DIR}
  87. if [ -d "staging" ]; then
  88. echo "remove old build cache file"
  89. rm -rf staging
  90. fi
  91. mkdir -p staging
  92. cp -a python_module/{megengine,setup.py,requires.txt,requires-style.txt,requires-test.txt} staging/
  93. cd ${BUILD_DIR}/staging/megengine/_internal
  94. llvm-strip -s _mgb.pyd
  95. cd ${BUILD_DIR}/staging
  96. ${PYTHON_DIR}/python3 setup.py bdist_wheel
  97. cp ${BUILD_DIR}/staging/dist/Meg*.whl ${WINDOWS_WHL_HOME}/
  98. echo ""
  99. echo "##############################################################################################"
  100. echo "windows whl package location: ${WINDOWS_WHL_HOME}"
  101. ls ${WINDOWS_WHL_HOME}
  102. echo "##############################################################################################"
  103. done
  104. }
  105. function third_party_prepare() {
  106. echo "init third_party..."
  107. ${SRC_DIR}/third_party/prepare.sh
  108. if [[ -z ${ALREADY_INSTALL_MKL} ]]
  109. then
  110. echo "init third_party..."
  111. ${SRC_DIR}/third_party/install-mkl.sh
  112. else
  113. echo "skip init mkl internal"
  114. fi
  115. }
  116. ######################
  117. third_party_prepare
  118. do_build

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