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.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 vs2019 install path"
  15. export VS_PATH=/c/Program\ Files\ \(x86\)/Microsoft\ Visual\ Studio/2019/Enterprise
  16. # for llvm-strip
  17. export PATH=$VS_PATH/VC/Tools/Llvm/bin/:$PATH
  18. }
  19. append_path_env_and_check
  20. SRC_DIR=$(READLINK -f "`dirname $0`/../../../")
  21. ALL_PYTHON=${ALL_PYTHON}
  22. FULL_PYTHON_VER="3.5.4 3.6.8 3.7.7 3.8.3"
  23. if [[ -z ${ALL_PYTHON} ]]
  24. then
  25. ALL_PYTHON=${FULL_PYTHON_VER}
  26. fi
  27. PYTHON_DIR=
  28. PYTHON_LIBRARY=
  29. PYTHON_INCLUDE_DIR=
  30. WINDOWS_WHL_HOME=${SRC_DIR}/scripts/whl/windows/windows_whl_home
  31. if [ -e "${WINDOWS_WHL_HOME}" ]; then
  32. echo "remove old windows whl file"
  33. rm -rf ${WINDOWS_WHL_HOME}
  34. fi
  35. mkdir -p ${WINDOWS_WHL_HOME}
  36. function config_python_env() {
  37. PYTHON_DIR=/c/Users/${USER}/mge_whl_python_env/$1
  38. PYTHON_BIN=${PYTHON_DIR}
  39. if [ ! -f "$PYTHON_BIN/python3.exe" ]; then
  40. echo "ERR: can not find $PYTHON_BIN , Invalid python package"
  41. echo "now support list: ${FULL_PYTHON_VER}"
  42. err_env
  43. else
  44. echo "put python3 to env..."
  45. export PATH=${PYTHON_BIN}:$PATH
  46. which python3
  47. fi
  48. echo ${ver}
  49. PYTHON_LIBRARY=${PYTHON_DIR}/libs/python3.lib
  50. PYTHON_INCLUDE_DIR=${PYTHON_DIR}/include
  51. }
  52. BUILD_WHL_CPU_ONLY=${BUILD_WHL_CPU_ONLY}
  53. if [[ -z ${BUILD_WHL_CPU_ONLY} ]]
  54. then
  55. BUILD_WHL_CPU_ONLY="OFF"
  56. fi
  57. # config NVIDIA libs
  58. TRT_LIB="/c/Program Files/NVIDIA GPU Computing Toolkit/TensorRT-6.0.1.5/lib/nvinfer.dll"
  59. CUDNN_LIB="/c/Program Files/NVIDIA GPU Computing Toolkit/cudnn-10.1-windows10-x64-v7.6.5.32/cuda/bin/cudnn64_7.dll"
  60. CUSOLVER_LIB="/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/bin/cusolver64_10.dll"
  61. CUBLAS_LIB="/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/bin/cublas64_10.dll"
  62. CURAND_LIB="/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/bin/curand64_10.dll"
  63. CUBLASLT_LIB="/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/bin/cublasLt64_10.dll"
  64. CUDART_LIB="/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/bin/cudart64_101.dll"
  65. function depend_real_copy() {
  66. REAL_DST=$1
  67. echo "real copy lib to $1"
  68. cp "${TRT_LIB}" ${REAL_DST}
  69. cp "${CUDNN_LIB}" ${REAL_DST}
  70. cp "${CUSOLVER_LIB}" ${REAL_DST}
  71. cp "${CUBLAS_LIB}" ${REAL_DST}
  72. cp "${CURAND_LIB}" ${REAL_DST}
  73. cp "${CUBLASLT_LIB}" ${REAL_DST}
  74. cp "${CUDART_LIB}" ${REAL_DST}
  75. }
  76. function copy_more_dll() {
  77. # for python whl real use
  78. echo "config BUILD_IMPERATIVE core lib dir"
  79. CP_WHL_DST_IMP=${BUILD_DIR}/staging/megengine/core/lib
  80. rm -rf ${CP_WHL_DST_IMP}
  81. mkdir ${CP_WHL_DST_IMP}
  82. # workround for cpu-only version import failed, use a
  83. # empty.file to triger setup.py to create a null empty
  84. echo "empty" > ${CP_WHL_DST_IMP}/empty.file
  85. if [ ${BUILD_WHL_CPU_ONLY} = "OFF" ]; then
  86. echo "copy nvidia lib to whl use...."
  87. depend_real_copy ${CP_WHL_DST_IMP}
  88. fi
  89. }
  90. function do_build() {
  91. for ver in ${ALL_PYTHON}
  92. do
  93. #config
  94. config_python_env ${ver}
  95. #check env
  96. if [ ! -f "$PYTHON_LIBRARY" ]; then
  97. echo "ERR: can not find $PYTHON_LIBRARY , Invalid python package"
  98. err_env
  99. fi
  100. if [ ! -d "$PYTHON_INCLUDE_DIR" ]; then
  101. echo "ERR: can not find $PYTHON_INCLUDE_DIR , Invalid python package"
  102. err_env
  103. fi
  104. echo "PYTHON_LIBRARY: ${PYTHON_LIBRARY}"
  105. echo "PYTHON_INCLUDE_DIR: ${PYTHON_INCLUDE_DIR}"
  106. #append cmake args for config python
  107. #FIXME: ninja handle err with cmake 3.17 when assgin PYTHON_LIBRARY
  108. #But after put python3.exe to HEAD of PATH by config_python_env, cmake can also handle the
  109. #right PYTHON_LIBRARY and PYTHON_INCLUDE_DIR, at the same time, clang-cl need swig target
  110. #force LINK a real PYTHON_LIBRARY file, after test we do not find the symbols conflict with python
  111. #export EXTRA_CMAKE_ARGS="-DPYTHON_LIBRARY=${PYTHON_LIBRARY} -DPYTHON_INCLUDE_DIR=${PYTHON_INCLUDE_DIR} "
  112. #config build type to RelWithDebInfo to enable MGB_ENABLE_DEBUG_UTIL etc
  113. export EXTRA_CMAKE_ARGS="${EXTRA_CMAKE_ARGS} -DCMAKE_BUILD_TYPE=RelWithDebInfo "
  114. #call build and install
  115. #FIXME: cmake do not triger update python config, after
  116. #change PYTHON_LIBRARY and PYTHON_INCLUDE_DIR, so add
  117. #-r to remove build cache after a new ver build, which
  118. #will be more slow build than without -r
  119. BUILD_ARGS=" -t -r"
  120. if [ ${BUILD_WHL_CPU_ONLY} = "OFF" ]; then
  121. echo "build windows whl with cuda"
  122. BUILD_ARGS="${BUILD_ARGS} -c "
  123. else
  124. echo "build windows whl with cpu only"
  125. fi
  126. echo "host_build.sh BUILD_ARGS: ${BUILD_ARGS}"
  127. ${SRC_DIR}/scripts/cmake-build/host_build.sh ${BUILD_ARGS}
  128. BUILD_DIR=${SRC_DIR}/build_dir/host/build/
  129. cd ${BUILD_DIR}
  130. rm -rf staging
  131. mkdir -p staging
  132. cp -a imperative/python/{megengine,setup.py,requires.txt,requires-style.txt,requires-test.txt} staging/
  133. cd ${BUILD_DIR}/staging/megengine/core
  134. rt_file=`ls _imperative_rt.*.pyd`
  135. echo "rt file is: ${rt_file}"
  136. if [[ -z ${rt_file} ]]
  137. then
  138. echo "ERR: can not find valid rt file"
  139. exit -1
  140. fi
  141. llvm-strip -s ${rt_file}
  142. mv ${rt_file} _imperative_rt.pyd
  143. copy_more_dll
  144. cd ${BUILD_DIR}/staging
  145. echo "call setup.py now"
  146. ${PYTHON_DIR}/python3 setup.py bdist_wheel
  147. cp ${BUILD_DIR}/staging/dist/Meg*.whl ${WINDOWS_WHL_HOME}/
  148. echo ""
  149. echo "##############################################################################################"
  150. echo "windows whl package location: ${WINDOWS_WHL_HOME}"
  151. ls ${WINDOWS_WHL_HOME}
  152. echo "##############################################################################################"
  153. done
  154. }
  155. function third_party_prepare() {
  156. echo "init third_party..."
  157. ${SRC_DIR}/third_party/prepare.sh
  158. if [[ -z ${ALREADY_INSTALL_MKL} ]]
  159. then
  160. echo "init third_party..."
  161. ${SRC_DIR}/third_party/install-mkl.sh
  162. else
  163. echo "skip init mkl internal"
  164. fi
  165. }
  166. ######################
  167. export ALREADY_CONFIG_PYTHON_VER="yes"
  168. third_party_prepare
  169. do_build

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