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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. if [[ -z ${WINDOWS_WHL_WITH_CUDA} ]]
  55. then
  56. WINDOWS_WHL_WITH_CUDA="false"
  57. fi
  58. # config NVIDIA libs
  59. TRT_LIB="/c/Program Files/NVIDIA GPU Computing Toolkit/TensorRT-6.0.1.5/lib/nvinfer.dll"
  60. CUDNN_LIB="/c/Program Files/NVIDIA GPU Computing Toolkit/cudnn-10.1-windows10-x64-v7.6.5.32/cuda/bin/cudnn64_7.dll"
  61. CUSOLVER_LIB="/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/bin/cusolver64_10.dll"
  62. CUBLAS_LIB="/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/bin/cublas64_10.dll"
  63. CURAND_LIB="/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/bin/curand64_10.dll"
  64. CUBLASLT_LIB="/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/bin/cublasLt64_10.dll"
  65. CUDART_LIB="/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/bin/cudart64_101.dll"
  66. function copy_more_dll() {
  67. # for python whl real use
  68. CP_DST=${BUILD_DIR}/staging/megengine/_internal/lib
  69. rm -rf ${CP_DST}
  70. mkdir ${CP_DST}
  71. if [ ${WINDOWS_WHL_WITH_CUDA} = "true" ]; then
  72. echo "copy nvidia lib to whl use...."
  73. cp "${TRT_LIB}" ${CP_DST}
  74. cp "${CUDNN_LIB}" ${CP_DST}
  75. cp "${CUSOLVER_LIB}" ${CP_DST}
  76. cp "${CUBLAS_LIB}" ${CP_DST}
  77. cp "${CURAND_LIB}" ${CP_DST}
  78. cp "${CUBLASLT_LIB}" ${CP_DST}
  79. cp "${CUDART_LIB}" ${CP_DST}
  80. fi
  81. }
  82. function do_build() {
  83. for ver in ${ALL_PYTHON}
  84. do
  85. #config
  86. config_python_env ${ver}
  87. #check env
  88. if [ ! -f "$PYTHON_LIBRARY" ]; then
  89. echo "ERR: can not find $PYTHON_LIBRARY , Invalid python package"
  90. err_env
  91. fi
  92. if [ ! -d "$PYTHON_INCLUDE_DIR" ]; then
  93. echo "ERR: can not find $PYTHON_INCLUDE_DIR , Invalid python package"
  94. err_env
  95. fi
  96. echo "PYTHON_LIBRARY: ${PYTHON_LIBRARY}"
  97. echo "PYTHON_INCLUDE_DIR: ${PYTHON_INCLUDE_DIR}"
  98. #append cmake args for config python
  99. #FIXME: ninja handle err with cmake 3.17 when assgin PYTHON_LIBRARY
  100. #But after put python3.exe to HEAD of PATH by config_python_env, cmake can also handle the
  101. #right PYTHON_LIBRARY and PYTHON_INCLUDE_DIR, at the same time, clang-cl need swig target
  102. #force LINK a real PYTHON_LIBRARY file, after test we do not find the symbols conflict with python
  103. #export EXTRA_CMAKE_ARGS="-DPYTHON_LIBRARY=${PYTHON_LIBRARY} -DPYTHON_INCLUDE_DIR=${PYTHON_INCLUDE_DIR} "
  104. #config build type to RelWithDebInfo to enable MGB_ENABLE_DEBUG_UTIL etc
  105. export EXTRA_CMAKE_ARGS=${EXTRA_CMAKE_ARGS}" -DCMAKE_BUILD_TYPE=RelWithDebInfo "
  106. #call build and install
  107. #FIXME: cmake do not triger update python config, after
  108. #change PYTHON_LIBRARY and PYTHON_INCLUDE_DIR, so add
  109. #-r to remove build cache after a new ver build, which
  110. #will be more slow build than without -r
  111. if [ ${WINDOWS_WHL_WITH_CUDA} = "true" ]; then
  112. echo "build windows whl with cuda"
  113. ${SRC_DIR}/scripts/cmake-build/host_build.sh -t -r -c
  114. else
  115. echo "build windows whl with cpu only"
  116. ${SRC_DIR}/scripts/cmake-build/host_build.sh -t -r
  117. fi
  118. #call setup.py
  119. BUILD_DIR=${SRC_DIR}/build_dir/host/build/
  120. cd ${BUILD_DIR}
  121. if [ -d "staging" ]; then
  122. echo "remove old build cache file"
  123. rm -rf staging
  124. fi
  125. mkdir -p staging
  126. cp -a python_module/{megengine,setup.py,requires.txt,requires-style.txt,requires-test.txt} staging/
  127. cd ${BUILD_DIR}/staging/megengine/_internal
  128. llvm-strip -s _mgb.pyd
  129. copy_more_dll
  130. cd ${BUILD_DIR}/staging
  131. ${PYTHON_DIR}/python3 setup.py bdist_wheel
  132. cp ${BUILD_DIR}/staging/dist/Meg*.whl ${WINDOWS_WHL_HOME}/
  133. echo ""
  134. echo "##############################################################################################"
  135. echo "windows whl package location: ${WINDOWS_WHL_HOME}"
  136. ls ${WINDOWS_WHL_HOME}
  137. echo "##############################################################################################"
  138. done
  139. }
  140. function third_party_prepare() {
  141. echo "init third_party..."
  142. ${SRC_DIR}/third_party/prepare.sh
  143. if [[ -z ${ALREADY_INSTALL_MKL} ]]
  144. then
  145. echo "init third_party..."
  146. ${SRC_DIR}/third_party/install-mkl.sh
  147. else
  148. echo "skip init mkl internal"
  149. fi
  150. }
  151. ######################
  152. third_party_prepare
  153. do_build

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