• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
17# Prepare and Install mindspore ascend by Conda on EulerOS 2.8.
18#
19# This file will:
20#   - install mindspore dependencies via apt like gcc, libgmp
21#   - install conda and set up environment for mindspore
22#
23# Augments:
24#   - PYTHON_VERSION: python version to set up. [3.7(default), 3.8, 3.9]
25#   - MINDSPORE_VERSION: mindspore version to install, >=1.6.0
26#   - LOCAL_ASCEND: Ascend AI software package installed path, default /usr/local/Ascend.
27#   - OPENMPI: whether to install optional package Open MPI for distributed training. [on, off(default)]
28#
29# Usage:
30#   Run script like `bash ./euleros-ascend-conda.sh`.
31#   To set augments, run it as `PYTHON_VERSION=3.9 MINDSPORE_VERSION=1.6.0 bash ./euleros-ascend-conda.sh`.
32
33set -e
34
35PYTHON_VERSION=${PYTHON_VERSION:-3.7}
36MINDSPORE_VERSION=${MINDSPORE_VERSION:-EMPTY}
37LOCAL_ASCEND=${LOCAL_ASCEND:-/usr/local/Ascend}
38OPENMPI=${OPENMPI:-off}
39
40version_less() {
41    test "$(echo "$@" | tr ' ' '\n' | sort -rV | head -n 1)" != "$1";
42}
43
44if version_less "${MINDSPORE_VERSION}" "1.6.0"; then
45    echo "MINDSPORE_VERSION should be >=1.6.0, please check available versions at https://www.mindspore.cn/versions."
46    exit 1
47fi
48
49available_py_version=(3.7 3.8 3.9)
50if [[ " ${available_py_version[*]} " != *" $PYTHON_VERSION "* ]]; then
51    echo "PYTHON_VERSION is '$PYTHON_VERSION', but available versions are [${available_py_version[*]}]."
52    exit 1
53fi
54
55if [[ "$PYTHON_VERSION" == "3.8" && ${MINDSPORE_VERSION:0:3} == "1.6" ]]; then
56    echo "PYTHON_VERSION==3.8 is not compatible with MINDSPORE_VERSION==1.6.x, please use PYTHON_VERSION==3.7 or 3.9 for MINDSPORE_VERSION==1.6.x."
57    exit 1
58fi
59
60if ! (ls ${LOCAL_ASCEND}/ascend-toolkit/latest/fwkacllib/lib64/te-*-py3-none-any.whl 1> /dev/null 2>&1); then
61    echo "can not find whl packages in LOCAL_ASCEND=${LOCAL_ASCEND}, please check whether it is a valid path."
62    exit 1
63fi
64
65# add value to environment variable if value is not in it
66add_env() {
67    local name=$1
68    if [[ ":${!name}:" != *":$2:"* ]]; then
69        echo -e "export $1=$2:\$$1" >> ~/.bashrc
70    fi
71}
72
73sudo yum install gcc gmp-devel -y
74
75install_conda() {
76    echo "installing Miniconda3"
77    conda_file_name="Miniconda3-py3${PYTHON_VERSION##*.}_4.10.3-Linux-$(arch).sh"
78    cd /tmp
79    curl -O https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/$conda_file_name
80    bash $conda_file_name -b
81    cd -
82    . ~/miniconda3/etc/profile.d/conda.sh
83    conda init bash
84    # setting up conda mirror with tsinghua source
85    cat >~/.condarc <<END
86channels:
87  - defaults
88show_channel_urls: true
89default_channels:
90  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
91  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
92  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
93custom_channels:
94  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
95  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
96  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
97  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
98  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
99END
100}
101
102# install conda
103set +e && type conda &>/dev/null
104if [[ $? -eq 0 ]]; then
105    echo "conda has been installed, skip."
106    source "$(conda info --base)"/etc/profile.d/conda.sh
107else
108    install_conda
109fi
110set -e
111
112# set up conda env
113env_name=mindspore_py3${PYTHON_VERSION##*.}
114# constraint openssl when py3.9+310
115openssl_constraint=""
116if [[ "$PYTHON_VERSION" == "3.9" ]]; then
117    openssl_constraint="openssl=1.1.1"
118fi
119conda create -n $env_name python=${PYTHON_VERSION} ${openssl_constraint} -c conda-forge -y
120conda activate $env_name
121
122pip install sympy
123pip install ${LOCAL_ASCEND}/ascend-toolkit/latest/fwkacllib/lib64/te-*-py3-none-any.whl
124pip install ${LOCAL_ASCEND}/ascend-toolkit/latest/fwkacllib/lib64/hccl-*-py3-none-any.whl
125
126install_name="mindspore"
127if [[ $MINDSPORE_VERSION != "EMPTY" ]]; then
128    install_name="${install_name}=${MINDSPORE_VERSION}"
129fi
130conda install ${install_name} -c mindspore -c conda-forge -y
131