MindSpore源码编译安装(CPU版)

2021/7/28 11:06:15

本文主要是介绍MindSpore源码编译安装(CPU版),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

转载地址:https://bbs.huaweicloud.com/forum/thread-75723-1-1.html

作者:liaops

一、软硬件环境

硬件平台:阿里云服务器

规格族:计算平衡增强型 c6e
实例规格:ecs.c6e.large
vCPU:2 vCPU
内存:4 GiB
处理器主频/睿频:2.5 GHz/3.2 GHz
处理器型号:Intel Xeon(Cascade Lake) Platinum 8269CY

软件平台

操作系统:Ubuntu 18.04 64位

二、准备依赖

安装依赖

sudo apt-get update

sudo DEBIAN_FRONTEND=noninteractive apt install -y \
    vim \
    wget \
    curl \
    xz-utils \
    net-tools \
    openssh-client \
    git \
    ntpdate \
    tzdata \
    tcl \
    sudo \
    bash-completion
sudo DEBIAN_FRONTEND=noninteractive apt install -y \
    gcc \
    g++ \
    zlibc \
    make \
    libgmp-dev \
    patch \
    autoconf \
    libtool \
    automake \
    libssl-dev \
    flex

安装CMake

版本 >= 3.14.1

下载

wget https://github.com/Kitware/CMake/releases/download/v3.18.2/cmake-3.18.2-Linux-x86_64.sh

安装

sudo bash cmake-3.18.2-Linux-x86_64.sh  --prefix=/usr/local
sudo ln -s /usr/local/cmake-3.18.2-Linux-x86_64/bin/cmake /usr/local/bin/cmake

确认CMake安装成功

$ cmake -version
cmake version 3.18.2

CMake suite maintained and supported by Kitware (kitware.com/cmake).

安装Python 3.7

安装python3.7

sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.7 python3.7-dev

确认Python3.7安装成功

$ python3.7 -V
Python 3.7.9

安装pip

python3.7 -m pip install pip

echo "export PATH=$HOME/.local/bin:$PATH" > ~/.bashrc
source ~/.bashrc

确认pip安装成功

$ pip -V
pip 20.2.2 from /home/liaops/.local/lib/python3.7/site-packages/pip (python 3.7)

设置pip国内源

mkdir -pv ~/.pip 
echo "[global]" > ~/.pip/pip.conf 
echo "trusted-host=mirrors.aliyun.com" >> ~/.pip/pip.conf 
echo "index-url=http://mirrors.aliyun.com/pypi/simple/" >> ~/.pip/pip.conf

三、编译MindSpore

下载

git clone https://gitee.com/mindspore/mindspore.git
cd mindspore
git checkout v0.7.0-beta -b v0.7.0-beta

编译

bash build.sh -e cpu -t off -j1

编译完成时输出如下信息表示编译成功:

adding 'mindspore-0.7.0.dist-info/METADATA'  
adding 'mindspore-0.7.0.dist-info/WHEEL'  
adding 'mindspore-0.7.0.dist-info/top_level.txt'  
adding 'mindspore-0.7.0.dist-info/RECORD'  
removing build/bdist.linux-x86_64/wheel  
CPack: - package: /home/liaops/work/mindspore/build/mindspore/mindspore generated.  
success building mindspore project!  
---------------- mindspore: build end   ----------------

文件build/package/mindspore-0.7.0-cp37-cp37m-linux_x86_64.whl就是MindSpore安装包

四、安装MindSpore

pip install build/package/mindspore-0.7.0-cp37-cp37m-linux_x86_64.whl

注:
1.编译的瓶颈在于要下载很多第三方开源库,阿里云国内的服务器下载会非常慢,可以考虑香港的服务器。

2.多线程编译会报如下错误:

[ 23%] Built target engine-datasetops-mapop
Scanning dependencies of target engine-opt
[ 23%] Building CXX object mindspore/ccsrc/minddata/dataset/engine/opt/CMakeFiles/engine-opt.dir/pass.cc.o
In file included from /home/liaops/mindspore/mindspore/ccsrc/minddata/dataset/engine/cache/cache_grpc_client.h:22:0,
                 from /home/liaops/mindspore/mindspore/ccsrc/minddata/dataset/engine/cache/cache_client.h:28,
                 from /home/liaops/mindspore/mindspore/ccsrc/minddata/dataset/engine/datasetops/cache_base_op.h:25,
                 from /home/liaops/mindspore/mindspore/ccsrc/minddata/dataset/engine/datasetops/cache_op.h:23,
                 from /home/liaops/mindspore/mindspore/ccsrc/minddata/dataset/engine/opt/pass.cc:21:
/home/liaops/mindspore/mindspore/ccsrc/minddata/dataset/engine/cache/cache_common.h:40:10: fatal error: proto/cache_grpc.grpc.pb.h: No such file or directory
 #include "proto/cache_grpc.grpc.pb.h"
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
mindspore/ccsrc/minddata/dataset/engine/opt/CMakeFiles/engine-opt.dir/build.make:81: recipe for target 'mindspore/ccsrc/minddata/dataset/engine/opt/CMakeFiles/engine-opt.dir/pass.cc.o' failed
make[2]: *** [mindspore/ccsrc/minddata/dataset/engine/opt/CMakeFiles/engine-opt.dir/pass.cc.o] Error 1
CMakeFiles/Makefile2:2002: recipe for target 'mindspore/ccsrc/minddata/dataset/engine/opt/CMakeFiles/engine-opt.dir/all' failed
make[1]: *** [mindspore/ccsrc/minddata/dataset/engine/opt/CMakeFiles/engine-opt.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....



这篇关于MindSpore源码编译安装(CPU版)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程