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.

ubuntu-cpu-source.sh 3.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/bin/bash
  2. # Copyright 2022 Huawei Technologies Co., Ltd
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. # ============================================================================
  16. # Prepare environment for mindspore cpu compilation on Ubuntu 18.04.
  17. #
  18. # This file will:
  19. # - change deb source to huaweicloud mirror
  20. # - install compile dependencies via apt like cmake, gcc
  21. # - install python3 & pip3 via apt and set it to default
  22. # - install LLVM if LLVM is set to on.
  23. #
  24. # Augments:
  25. # - PYTHON_VERSION: python version to install. [3.7(default), 3.9]
  26. # - LLVM: whether to install optional dependency LLVM for graph kernel fusion. [on, off(default)]
  27. #
  28. # Usage:
  29. # Need root permission to run, like `sudo bash ./ubuntu-cpu-source.sh`.
  30. # To set augments, run it as `sudo PYTHON_VERSION=3.9 LLVM=on bash ./ubuntu-cpu-source.sh`.
  31. set -e
  32. PYTHON_VERSION=${PYTHON_VERSION:-3.7}
  33. LLVM=${LLVM:-off}
  34. available_py_version=(3.7 3.9)
  35. if [[ " ${available_py_version[*]} " != *" $PYTHON_VERSION "* ]]; then
  36. echo "PYTHON_VERSION is '$PYTHON_VERSION', but available versions are [${available_py_version[*]}]."
  37. exit 1
  38. fi
  39. # use huaweicloud mirror in China
  40. sed -i "s@http://.*archive.ubuntu.com@http://repo.huaweicloud.com@g" /etc/apt/sources.list
  41. sed -i "s@http://.*security.ubuntu.com@http://repo.huaweicloud.com@g" /etc/apt/sources.list
  42. # base packages
  43. apt-get update
  44. apt-get install software-properties-common lsb-release -y
  45. apt-get install curl tcl gcc-7 git libgmp-dev patch libnuma-dev -y
  46. # cmake
  47. wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | apt-key add -
  48. apt-add-repository "deb https://apt.kitware.com/ubuntu/ $(lsb_release -cs) main"
  49. apt-get install cmake -y
  50. # optional dependency LLVM for graph-computation fusion
  51. if [[ X"$LLVM" == "Xon" ]]; then
  52. wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
  53. add-apt-repository "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-12 main"
  54. apt-get update
  55. apt-get install llvm-12-dev -y
  56. fi
  57. # python
  58. add-apt-repository -y ppa:deadsnakes/ppa
  59. apt-get install python$PYTHON_VERSION python$PYTHON_VERSION-dev python$PYTHON_VERSION-distutils python3-pip -y
  60. update-alternatives --install /usr/bin/python python /usr/bin/python$PYTHON_VERSION 100
  61. # pip
  62. sudo -u $SUDO_USER python -m pip install pip -i https://pypi.tuna.tsinghua.edu.cn/simple
  63. update-alternatives --install /usr/bin/pip pip ~/.local/bin/pip$PYTHON_VERSION 100
  64. update-alternatives --install /usr/local/bin/pip pip ~/.local/bin/pip$PYTHON_VERSION 100
  65. sudo -u $SUDO_USER pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
  66. # wheel
  67. sudo -u $SUDO_USER pip install wheel
  68. # python 3.9 needs setuptools>44.0
  69. sudo -u $SUDO_USER pip install -U setuptools
  70. echo "The environment is ready to clone and compile mindspore."