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 environment for mindspore cpu compilation on Ubuntu 18.04. 18# 19# This file will: 20# - change deb source to huaweicloud mirror 21# - install compile dependencies via apt like cmake, gcc 22# - install python3 & pip3 via apt and set it to default 23# - install LLVM if LLVM is set to on. 24# 25# Augments: 26# - PYTHON_VERSION: python version to install. [3.7(default), 3.8, 3.9] 27# - LLVM: whether to install optional dependency LLVM for graph kernel fusion. [on, off(default)] 28# 29# Usage: 30# Run script like `bash ./ubuntu-cpu-source.sh`. 31# To set augments, run it as `PYTHON_VERSION=3.9 LLVM=on bash ./ubuntu-cpu-source.sh`. 32 33set -e 34 35PYTHON_VERSION=${PYTHON_VERSION:-3.7} 36LLVM=${LLVM:-off} 37 38available_py_version=(3.7 3.8 3.9) 39if [[ " ${available_py_version[*]} " != *" $PYTHON_VERSION "* ]]; then 40 echo "PYTHON_VERSION is '$PYTHON_VERSION', but available versions are [${available_py_version[*]}]." 41 exit 1 42fi 43 44# use huaweicloud mirror in China 45sudo sed -i "s@http://.*archive.ubuntu.com@http://repo.huaweicloud.com@g" /etc/apt/sources.list 46sudo sed -i "s@http://.*security.ubuntu.com@http://repo.huaweicloud.com@g" /etc/apt/sources.list 47 48# base packages 49sudo apt-get update 50sudo apt-get install software-properties-common lsb-release -y 51sudo apt-get install curl tcl gcc-7 git libgmp-dev patch libnuma-dev -y 52 53# cmake 54wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | sudo apt-key add - 55sudo apt-add-repository "deb https://apt.kitware.com/ubuntu/ $(lsb_release -cs) main" 56sudo apt-get install cmake -y 57 58# optional dependency LLVM for graph-computation fusion 59if [[ X"$LLVM" == "Xon" ]]; then 60 wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - 61 sudo add-apt-repository "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-12 main" 62 sudo apt-get update 63 sudo apt-get install llvm-12-dev -y 64fi 65 66# python 67sudo add-apt-repository -y ppa:deadsnakes/ppa 68sudo apt-get install python$PYTHON_VERSION python$PYTHON_VERSION-dev python$PYTHON_VERSION-distutils python3-pip -y 69sudo update-alternatives --install /usr/bin/python python /usr/bin/python$PYTHON_VERSION 100 70# pip 71python -m pip install -U pip -i https://pypi.tuna.tsinghua.edu.cn/simple 72echo -e "alias pip='python -m pip'" >> ~/.bashrc 73python -m pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple 74 75# wheel 76python -m pip install wheel 77# python 3.9 needs setuptools>44.0 78python -m pip install -U setuptools 79 80echo "The environment is ready to clone and compile mindspore." 81