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.

macos_build_whl.sh 6.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #!/bin/bash -e
  2. ######################################################################################################################
  3. # macos build whl env prepare #
  4. # 1: install xcodebuild for host-build #
  5. # 2: install brew: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" #
  6. # 3: build/install cmake3-14.4 #
  7. # wget https://cmake.org/files/v3.14/cmake-3.14.4.tar.gz #
  8. # tar -xzvf cmake-3.14.4.tar.gz;cd cmake-3.14.4; #
  9. # ./configure; make -j32; sudo make install #
  10. # #
  11. # 4: brew install wget python swig coreutils llvm #
  12. # echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >> ~/.zshrc (if u use other shell, chang this) #
  13. # #
  14. # 5: brew install python@3.8 (sub version may different) #
  15. # /usr/local/Cellar/python@3.8/3.8.3_2/bin/pip3 install numpy #
  16. # #
  17. # 6: brew install python@3.7 (sub version may different) #
  18. # /usr/local/Cellar/python@3.7/3.7.8_1/bin/pip3 install numpy #
  19. # #
  20. # 7: make link for easy use python3.x (not build necessary) #
  21. # ln -s /usr/local/Cellar/python@3.7/3.7.8_1/bin/pip3.7 /usr/local/bin/pip3.7 #
  22. # ln -s /usr/local/Cellar/python@3.7/3.7.8_1/bin/python3.7 /usr/local/bin/python3.7 #
  23. # ln -s /usr/local/Cellar/python@3.8/3.8.3_2/bin/pip3.8 /usr/local/bin/pip3.8 #
  24. # ln -s /usr/local/Cellar/python@3.8/3.8.3_2/bin/python3.8 /usr/local/bin/python3.8 #
  25. ######################################################################################################################
  26. READLINK=readlink
  27. OS=$(uname -s)
  28. if [ $OS = "Darwin" ];then
  29. READLINK=greadlink
  30. else
  31. echo "ERR: only run at macos env"
  32. exit -1
  33. fi
  34. SRC_DIR=$($READLINK -f "`dirname $0`/../../")
  35. ALL_PYTHON=${ALL_PYTHON}
  36. if [[ -z ${ALL_PYTHON} ]]
  37. then
  38. #FIXME: on catalina brew only official support 3.7 and 3.8
  39. ALL_PYTHON="37 38"
  40. fi
  41. PYTHON_DIR=
  42. PYTHON_LIBRARY=
  43. PYTHON_INCLUDE_DIR=
  44. function config_python_env() {
  45. if [[ "$1" -eq "38" ]]; then
  46. PYTHON_DIR=/usr/local/Cellar/python@3.8/3.8.3_2/Frameworks/Python.framework/Versions/3.8/
  47. PYTHON_LIBRARY=${PYTHON_DIR}lib/libpython3.8.dylib
  48. PYTHON_INCLUDE_DIR=${PYTHON_DIR}include/python3.8
  49. elif [[ "$1" -eq "37" ]]; then
  50. PYTHON_DIR=/usr/local/Cellar/python@3.7/3.7.8_1/Frameworks/Python.framework/Versions/3.7/
  51. PYTHON_LIBRARY=${PYTHON_DIR}lib/libpython3.7.dylib
  52. PYTHON_INCLUDE_DIR=${PYTHON_DIR}include/python3.7m
  53. else
  54. echo "ERR: DO NOT SUPPORT PYTHON VERSION"
  55. exit -1
  56. fi
  57. }
  58. MACOS_WHL_HOME=${SRC_DIR}/scripts/cmake-build/macos_whl_home
  59. if [ -e "${MACOS_WHL_HOME}" ]; then
  60. echo "remove old macos whl file"
  61. rm -rf ${MACOS_WHL_HOME}
  62. fi
  63. mkdir -p ${MACOS_WHL_HOME}
  64. for ver in ${ALL_PYTHON}
  65. do
  66. #config
  67. config_python_env ${ver}
  68. #check env
  69. if [ ! -f "$PYTHON_LIBRARY" ]; then
  70. echo "ERR: can not find $PYTHON_LIBRARY , Invalid python package"
  71. exit -1
  72. fi
  73. if [ ! -d "$PYTHON_INCLUDE_DIR" ]; then
  74. echo "ERR: can not find $PYTHON_INCLUDE_DIR , Invalid python package"
  75. exit -1
  76. fi
  77. echo "PYTHON_LIBRARY: ${PYTHON_LIBRARY}"
  78. echo "PYTHON_INCLUDE_DIR: ${PYTHON_INCLUDE_DIR}"
  79. #append cmake args for config python
  80. export EXTRA_CMAKE_ARGS="-DCMAKE_PREFIX_PATH=${PYTHON_DIR} -DPYTHON_LIBRARY=${PYTHON_LIBRARY} -DPYTHON_INCLUDE_DIR=${PYTHON_INCLUDE_DIR} "
  81. #config build type to RelWithDebInfo to enable MGB_ENABLE_DEBUG_UTIL etc
  82. export EXTRA_CMAKE_ARGS=${EXTRA_CMAKE_ARGS}" -DCMAKE_BUILD_TYPE=RelWithDebInfo "
  83. #call build and install
  84. #FIXME: cmake do not triger update python config, after
  85. #change PYTHON_LIBRARY and PYTHON_INCLUDE_DIR, so add
  86. #-r to remove build cache after a new ver build, which
  87. #will be more slow build than without -r
  88. ${SRC_DIR}/scripts/cmake-build/host_build.sh -t -r
  89. #call setup.py
  90. BUILD_DIR=${SRC_DIR}/build_dir/host/MGE_WITH_CUDA_OFF/MGE_INFERENCE_ONLY_OFF/Release/build/
  91. cd ${BUILD_DIR}
  92. if [ -d "staging" ]; then
  93. echo "remove old build cache file"
  94. rm -rf staging
  95. fi
  96. mkdir -p staging
  97. cp -a python_module/{megengine,setup.py,requires.txt,requires-style.txt,requires-test.txt} staging/
  98. cd ${BUILD_DIR}/staging/megengine/_internal
  99. #FIXME: set lib suffix to dylib may be better, BUT we find after distutils.file_util.copy_file
  100. #will change to .so at macos even we set suffix to dylib, at the same time, macos also support .so
  101. llvm-strip -s _mgb.so
  102. cd ${BUILD_DIR}/staging
  103. ${PYTHON_DIR}/bin/python3 setup.py bdist_wheel
  104. cp ${BUILD_DIR}/staging/dist/Meg*.whl ${MACOS_WHL_HOME}/
  105. echo ""
  106. echo "##############################################################################################"
  107. echo "macos whl package location: ${MACOS_WHL_HOME}"
  108. ls ${MACOS_WHL_HOME}
  109. echo "##############################################################################################"
  110. done

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