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.

euleros-ascend-source.sh 4.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 ascend compilation on EulerOS 2.8.
  17. #
  18. # This file will:
  19. # - install mindspore dependencies via apt like gcc, cmake
  20. # - install conda and set up environment for mindspore
  21. #
  22. # Augments:
  23. # - PYTHON_VERSION: python version to set up. [3.7(default), 3.8, 3.9]
  24. # - MINDSPORE_VERSION: mindspore version to install, default 1.6.0
  25. # - OPENMPI: whether to install optional package Open MPI for distributed training. [on, off(default)]
  26. #
  27. # Usage:
  28. # Run script like `bash -i ./euleros-ascend-source.sh`.
  29. # To set augments, run it as `PYTHON_VERSION=3.9 MINDSPORE_VERSION=1.5.0 bash -i ./euleros-ascend-source.sh`.
  30. set -e
  31. PYTHON_VERSION=${PYTHON_VERSION:-3.7}
  32. MINDSPORE_VERSION=${MINDSPORE_VERSION:-1.6.0}
  33. OPENMPI=${OPENMPI:-off}
  34. available_py_version=(3.7 3.8 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. # add value to environment variable if value is not in it
  40. add_env() {
  41. local name=$1
  42. if [[ ":${!name}:" != *":$2:"* ]]; then
  43. echo -e "export $1=$2:\$$1" >> ~/.bashrc
  44. fi
  45. }
  46. sudo yum install gcc git gmp-devel tcl patch numactl-devel flex -y
  47. curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.rpm.sh | sudo os=el dist=7 bash
  48. sudo yum install git-lfs -y
  49. git lfs install
  50. install_conda() {
  51. conda_file_name="Miniconda3-py3${PYTHON_VERSION##*.}_4.10.3-Linux-$(arch).sh"
  52. cd /tmp
  53. curl -O https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/$conda_file_name
  54. bash $conda_file_name -b
  55. cd -
  56. . ~/miniconda3/etc/profile.d/conda.sh
  57. conda init bash
  58. # setting up conda mirror with tsinghua source
  59. cat >~/.condarc <<END
  60. channels:
  61. - defaults
  62. show_channel_urls: true
  63. default_channels:
  64. - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  65. - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  66. - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
  67. custom_channels:
  68. conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  69. msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  70. bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  71. menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  72. simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  73. END
  74. }
  75. # install conda
  76. set +e && type conda &>/dev/null
  77. if [[ $? -eq 0 ]]; then
  78. echo "conda has been installed, skip."
  79. source "$(conda info --base)"/etc/profile.d/conda.sh
  80. else
  81. install_conda
  82. fi
  83. set -e
  84. # set up conda env
  85. env_name=mindspore_py3${PYTHON_VERSION##*.}
  86. conda create -n $env_name python=${PYTHON_VERSION} -y
  87. conda activate $env_name
  88. pip install wheel
  89. pip install -U setuptools
  90. # cmake
  91. cd /tmp
  92. cmake_file_name="cmake-3.19.8-Linux-$(arch).sh"
  93. curl -O "https://cmake.org/files/v3.19/${cmake_file_name}"
  94. sudo mkdir $HOME/cmake-3.19.8
  95. sudo bash cmake-3.19.8-Linux-*.sh --prefix=$HOME/cmake-3.19.8 --exclude-subdir
  96. add_env PATH $HOME/cmake-3.19.8/bin
  97. source ~/.bashrc
  98. cd -
  99. # optional openmpi for distributed training
  100. if [[ X"$OPENMPI" == "Xon" ]]; then
  101. origin_wd=$PWD
  102. cd /tmp
  103. curl -O https://download.open-mpi.org/release/open-mpi/v4.0/openmpi-4.0.3.tar.gz
  104. tar xzf openmpi-4.0.3.tar.gz
  105. cd openmpi-4.0.3
  106. ./configure --prefix=$HOME/openmpi-4.0.3
  107. make
  108. sudo make install
  109. add_env PATH $HOME/openmpi-4.0.3/bin
  110. add_env LD_LIBRARY_PATH $HOME/openmpi-4.0.3/lib
  111. cd $origin_wd
  112. fi
  113. echo "The environment is ready to clone and compile mindspore."