• 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 pip 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, required
26#   - LOCAL_ASCEND: Ascend AI software package installed path, default /usr/local/Ascend.
27#
28# Usage:
29#   Run script like `MINDSPORE_VERSION=1.7.0 bash ./euleros-ascend310-pip.sh`.
30#   To set augments, run it as `PYTHON_VERSION=3.9 MINDSPORE_VERSION=1.6.0 bash ./euleros-ascend310-pip.sh`.
31
32set -e
33
34PYTHON_VERSION=${PYTHON_VERSION:-3.7}
35MINDSPORE_VERSION=${MINDSPORE_VERSION:-EMPTY}
36LOCAL_ASCEND=${LOCAL_ASCEND:-/usr/local/Ascend}
37OPENMPI=${OPENMPI:-off}
38
39version_less() {
40    test "$(echo "$@" | tr ' ' '\n' | sort -rV | head -n 1)" != "$1";
41}
42
43if [ $MINDSPORE_VERSION == "EMPTY" ] || version_less "${MINDSPORE_VERSION}" "1.6.0"; then
44    echo "MINDSPORE_VERSION should be >=1.6.0, please check available versions at https://www.mindspore.cn/versions."
45    exit 1
46fi
47
48available_py_version=(3.7 3.8 3.9)
49if [[ " ${available_py_version[*]} " != *" $PYTHON_VERSION "* ]]; then
50    echo "PYTHON_VERSION is '$PYTHON_VERSION', but available versions are [${available_py_version[*]}]."
51    exit 1
52fi
53
54if ! (ls ${LOCAL_ASCEND}/ascend-toolkit/latest/fwkacllib/lib64/topi-*-py3-none-any.whl 1> /dev/null 2>&1); then
55    echo "can not find whl packages in LOCAL_ASCEND=${LOCAL_ASCEND}, please check whether it is a valid path."
56    exit 1
57fi
58
59declare -A version_map=()
60version_map["3.7"]="${MINDSPORE_VERSION/-/}-cp37-cp37m"
61version_map["3.8"]="${MINDSPORE_VERSION/-/}-cp38-cp38"
62version_map["3.9"]="${MINDSPORE_VERSION/-/}-cp39-cp39"
63
64# add value to environment variable if value is not in it
65add_env() {
66    local name=$1
67    if [[ ":${!name}:" != *":$2:"* ]]; then
68        echo -e "export $1=$2:\$$1" >> ~/.bashrc
69    fi
70}
71
72sudo yum install gcc gmp-devel -y
73
74# cmake
75echo "installing cmake"
76cd /tmp
77cmake_file_name="cmake-3.19.8-Linux-$(arch).sh"
78curl -O "https://cmake.org/files/v3.19/${cmake_file_name}"
79mkdir $HOME/cmake-3.19.8
80bash cmake-3.19.8-Linux-*.sh --prefix=$HOME/cmake-3.19.8 --exclude-subdir
81add_env PATH $HOME/cmake-3.19.8/bin
82set +e && source ~/.bashrc
83set -e
84cd -
85
86install_conda() {
87    echo "installing Miniconda3"
88    conda_file_name="Miniconda3-py3${PYTHON_VERSION##*.}_4.10.3-Linux-$(arch).sh"
89    cd /tmp
90    curl -O https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/$conda_file_name
91    bash $conda_file_name -b
92    cd -
93    . ~/miniconda3/etc/profile.d/conda.sh
94    conda init bash
95    # setting up conda mirror with tsinghua source
96    cat >~/.condarc <<END
97channels:
98  - defaults
99show_channel_urls: true
100default_channels:
101  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
102  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
103  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
104custom_channels:
105  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
106  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
107  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
108  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
109  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
110END
111}
112
113# install conda
114set +e && type conda &>/dev/null
115if [[ $? -eq 0 ]]; then
116    echo "conda has been installed, skip."
117    source "$(conda info --base)"/etc/profile.d/conda.sh
118else
119    install_conda
120fi
121set -e
122
123# set up conda env
124env_name=mindspore_py3${PYTHON_VERSION##*.}
125# constraint openssl when py3.9+310
126openssl_constraint=""
127if [[ "$PYTHON_VERSION" == "3.9" ]]; then
128    openssl_constraint="openssl=1.1.1"
129fi
130conda create -n $env_name python=${PYTHON_VERSION} ${openssl_constraint} -c conda-forge -y
131conda activate $env_name
132
133pip install sympy
134pip install ${LOCAL_ASCEND}/ascend-toolkit/latest/fwkacllib/lib64/topi-*-py3-none-any.whl
135pip install ${LOCAL_ASCEND}/ascend-toolkit/latest/fwkacllib/lib64/te-*-py3-none-any.whl
136pip install ${LOCAL_ASCEND}/ascend-toolkit/latest/fwkacllib/lib64/hccl-*-py3-none-any.whl
137
138ARCH=`uname -m`
139pip install https://ms-release.obs.cn-north-4.myhuaweicloud.com/${MINDSPORE_VERSION}/MindSpore/ascend/${ARCH}/mindspore_ascend-${version_map["$PYTHON_VERSION"]}-linux_${ARCH}.whl --trusted-host ms-release.obs.cn-north-4.myhuaweicloud.com -i https://pypi.tuna.tsinghua.edu.cn/simple
140