官網地址:
https://www.mindspore.cn/install
系統:Ubuntu18.04
硬件:
i7-9700k CPU
2060super nvidia顯卡
由於考慮到mindspore版本更新,依賴環境的變化,因此將mindspore依賴的環境安裝到自建文件夾下,
給出下面操作中環境的安裝文件夾:
/home/devilmaycry/anaconda3/mindspore_envs
這個路徑可以按照個人情況進行設置的,只要下面均保持一致即可。
下文中修改 .bashrc 是指打開.bashrc :
vim ~/.bashrc
本文假設系統中已經為GPU顯卡安裝好驅動程序了,因此本文不介紹驅動的安裝。
(請注意:下面的安裝建議按照步驟來進行)
================================================================
1. 安裝CUDA11.1.0 和 cuDNN 8.0.X版本:
cuda安裝
創建cuda的安裝目錄:
mkdir cuda11.1
查看所創建路徑:
/home/devilmaycry/anaconda3/mindspore_envs/cuda11.1
下載並安裝:
wget https://developer.download.nvidia.com/compute/cuda/11.1.0/local_installers/cuda_11.1.0_455.23.05_linux.run
sh ./cuda_11.1.0_455.23.05_linux.run --toolkit --toolkitpath=/home/devilmaycry/anaconda3/mindspore_envs/cuda11.1 --silent
2. cuDnn安裝:
下載地址:
解壓文件:
tar -zxvf cudnn-11.1-linux-x64-v8.0.5.39.tgz
拷貝解壓后的文件到cuda安裝目錄內:
cp cuda/include/* /home/devilmaycry/anaconda3/mindspore_envs/cuda11.1/include
cp cuda/lib64/* /home/devilmaycry/anaconda3/mindspore_envs/cuda11.1/lib64
配置環境變量:
修改 .bashrc 文件
# cuda&cudnn export LD_LIBRARY_PATH=/home/devilmaycry/anaconda3/mindspore_envs/cuda11.1/lib64:$LD_LIBRARY_PATH export PATH=/home/devilmaycry/anaconda3/mindspore_envs/cuda11.1/bin:$PATH
================================================================
GCC的安裝:
下載gcc 7.3.0版本安裝包,執行以下命令:
wget http://ftp.gnu.org/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz
執行tar -xzf gcc-7.3.0.tar.gz
解壓源碼包。
執行cd gcc-7.3.0
,進入到源碼包目錄。
繼續下面操作前清空系統內的環境變量:
export LIBRARY_PATH= export LD_LIBRARY_PATH= export C_INCLUDE_PATH= export CPLUS_INCLUDE_PATH=
運行以下命令,進行安裝前的配置。
安裝依賴環境:
./contrib/download_prerequisites
配置環境:
./configure --prefix=/home/devilmaycry/anaconda3/mindspore_envs/gcc_7.3.0 --enable-bootstrap -enable-threads=posix --enable-checking=release --enable-languages=c,c++ --disable-multilib
編譯安裝:
make -j8 && make install
配置系統環境: 修改 .bashrc 文件,添加內容:
# gcc export PATH=/home/devilmaycry/anaconda3/mindspore_envs/gcc_7.3.0/bin:$PATH ###export LIBRARY_PATH=/home/devilmaycry/anaconda3/mindspore_envs/gcc_7.3.0/share:$LIBRARY_PATH export LD_LIBRARY_PATH=/home/devilmaycry/anaconda3/mindspore_envs/gcc_7.3.0/lib64:$LD_LIBRARY_PATH export C_INCLUDE_PATH=/home/devilmaycry/anaconda3/mindspore_envs/gcc_7.3.0/include:$C_INCLUDE_PATH export CPLUS_INCLUDE_PATH=$C_INCLUDE_PATH:$CPLUS_INCLUDE_PATH
=========================================================
m4 下載安裝:
下載:
wget http://ftp.gnu.org/gnu/m4/m4-1.4.16.tar.bz2
解壓:
tar -jxvf m4-1.4.16.tar.bz2
修改m4_1.4.16下源文件中代碼:(https://blog.csdn.net/weixin_34168880/article/details/91842744)
vi lib/stdio.in.h
查找字段:gets is a security hole
注釋:
將_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead"); 字段和他之前的注釋 /* 一塊注釋掉,如下
/* It is very rare that the developer ever has full control of stdin, so any use of gets warrants an unconditional warning. Assume it is always declared, since it is required by C89. #undef gets _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead"); */
再添加如下內容:
#if defined(__GLIBC__) && !defined(__UCLIBC__) && !__GLIBC_PREREQ(2, 16) _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead"); #endif
配置:
./configure --prefix=/home/devilmaycry/anaconda3/mindspore_envs/m4_1.4.16/
編譯安裝
make && make install
配置系統環境變量:
修改 .bashrc 文件
export PATH=/home/devilmaycry/anaconda3/mindspore_envs/m4_1.4.16/bin:$PATH
說明: 其中,/home/devilmaycry/anaconda3/mindspore_envs/m4_1.4.16 路徑為我們剛才編譯源碼配置安裝路徑的地址。
==============================================================
需要注意:安裝好m4后需要執行命令 soure ~/.bashrc ,然后才可以繼續安裝gmp。
安裝gmp 6.1.2
下載gmp 6.1.2
源碼包:
wget https://gmplib.org/download/gmp/gmp-6.1.2.tar.xz
解壓到當前文件夾:
tar -xvf gmp-6.1.2.tar.xz
配置:
./configure --prefix=/home/devilmaycry/anaconda3/mindspore_envs/gmp_6.1.2/ --enable-cxx
編譯安裝:
make && make install
配置系統環境變量: 修改 .bashrc 文件
# gmp export LIBRARY_PATH=/home/devilmaycry/anaconda3/mindspore_envs/gmp_6.1.2/lib:$LIBRARY_PATH export LD_LIBRARY_PATH=/home/devilmaycry/anaconda3/mindspore_envs/gmp_6.1.2/lib:$LD_LIBRARY_PATH export C_INCLUDE_PATH=/home/devilmaycry/anaconda3/mindspore_envs/gmp_6.1.2/include:$C_INCLUDE_PATH export CPLUS_INCLUDE_PATH=$C_INCLUDE_PATH:$CPLUS_INCLUDE_PATH
測試 gmp 是否安裝並配置成功:(聲明:測試部分內容源於:https://blog.csdn.net/just_h/article/details/82667787)
代碼:
# test.cpp 文件
#include <gmpxx.h> #include <iostream> #include <stdio.h> using namespace std; int main() { mpz_t a,b,c; mpz_init(a); mpz_init(b); mpz_init(c); gmp_scanf("%Zd%Zd",a,b); mpz_add(c,a,b); gmp_printf("c= %Zd\n",c); return 0; }
編譯:
g++ test.cpp -o test -lgmp
運行:
openssl 的安裝:
下載地址:
https://www.openssl.org/source/openssl-1.1.1k.tar.gz
解壓:
tar -zxvf openssl-1.1.1k
配置:
./config --prefix=/home/devilmaycry/anaconda3/mindspore_envs/openssl_1.1.1
編譯並安裝:
make -j8&& make install
配置系統環境:修改 .bashrc 文件, 添加內容:
# openssl export OPENSSL_ROOT_DIR=/home/devilmaycry/anaconda3/mindspore_envs/openssl_1.1.1 export OPENSSL_INCLUDE_DIR=/home/devilmaycry/anaconda3/mindspore_envs/openssl_1.1.1/include export OPENSSL_CRYPTO_LIBRARY=/home/devilmaycry/anaconda3/mindspore_envs/openssl_1.1.1/lib
重新載入 .bashrc 文件:
source ~/.bashrc
cmake 安裝:
下載文件:
wget https://github.com/Kitware/CMake/releases/download/v3.21.0/cmake-3.21.0.tar.gz
解壓:
tar -zxvf cmake-3.21.0.tar.gz
配置:
./configure --prefix=/home/devilmaycry/anaconda3/mindspore_envs/cmake_3.21.0
編譯並安裝:
make -j8&& make install
配置系統環境:
修改 ~/.bashrc 文件,添加內容:
# make export PATH=/home/devilmaycry/anaconda3/mindspore_envs/cmake_3.21.0/bin:$PATH
重新載入 .bashrc 文件:
source ~/.bashrc
patch 的安裝:
下載文件:
wget https://ftp.gnu.org/gnu/patch/patch-2.7.6.tar.gz
解壓:
tar -zxvf patch-2.7.6.tar.gz
配置:
./configure --prefix=/home/devilmaycry/anaconda3/mindspore_envs/patch_2.7.6
編譯並安裝:
make -j8&& make install
配置系統環境:
修改 ~/.bashrc 文件,添加內容:
# patch export PATH=/home/devilmaycry/anaconda3/mindspore_envs/patch_2.7.6/bin:$PATH
重新載入 .bashrc 文件:
source ~/.bashrc
安裝Autoconf
下載文件:
wget https://ftp.gnu.org/gnu/autoconf/autoconf-2.71.tar.gz
解壓:
tar -zxvf autoconf-2.71.tar.gz
配置:
./configure --prefix=/home/devilmaycry/anaconda3/mindspore_envs/autoconf_2.71
編譯並安裝:
make -j8&& make install
配置系統環境:
修改 ~/.bashrc 文件,添加內容:
# autoconf export PATH=/home/devilmaycry/anaconda3/mindspore_envs/autoconf_2.71/bin:$PATH
重新載入 .bashrc 文件:
source ~/.bashrc
安裝 libtool
下載地址:
wget https://ftpmirror.gnu.org/libtool/libtool-2.4.6.tar.gz
解壓:
tar -zxvf libtool-2.4.6.tar.gz
配置:
./configure --prefix=/home/devilmaycry/anaconda3/mindspore_envs/libtool_2.4.6
編譯並安裝:
make -j8&& make install
配置系統環境:
修改 ~/.bashrc 文件,添加內容:
# libtool export PATH=/home/devilmaycry/anaconda3/mindspore_envs/libtool_2.4.6/bin:$PATH
重新載入 .bashrc 文件:
source ~/.bashrc
安裝automake
下載:
wget https://ftp.gnu.org/gnu/automake/automake-1.16.3.tar.gz
解壓:
tar -zxvf automake-1.16.3.tar.gz
配置:
./configure --prefix=/home/devilmaycry/anaconda3/mindspore_envs/automake_1.16.3
編譯並安裝:
make -j8&& make install
配置系統環境:
修改 ~/.bashrc 文件,添加內容:
# automake export PATH=/home/devilmaycry/anaconda3/mindspore_envs/automake_1.16.3/bin:$PATH
重新載入 .bashrc 文件:
source ~/.bashrc
安裝flex
下載文件:
wget https://github.com/westes/flex/files/981163/flex-2.6.4.tar.gz
解壓:
tar -zxvf flex-2.6.4.tar.gz
配置:
./configure --prefix=/home/devilmaycry/anaconda3/mindspore_envs/flex_2.6.4
編譯並安裝:
make -j8&& make install
修改系統環境,修改 .bashrc文件,添加內容:
# flex export PATH=/home/devilmaycry/anaconda3/mindspore_envs/flex_2.6.4/bin:$PATH export LIBRARY_PATH=/home/devilmaycry/anaconda3/mindspore_envs/flex_2.6.4/lib:$LIBRARY_PATH export LD_LIBRARY_PATH=/home/devilmaycry/anaconda3/mindspore_envs/flex_2.6.4/lib:$LD_LIBRARY_PATH export C_INCLUDE_PATH=/home/devilmaycry/anaconda3/mindspore_envs/flex_2.6.4/include:$C_INCLUDE_PATH export CPLUS_INCLUDE_PATH=$C_INCLUDE_PATH:$CPLUS_INCLUDE_PATH
重新載入 .bashrc 文件:
source ~/.bashrc
安裝Python環境和wheel
這里我們使用anaconda下的Python環境,anaconda的安裝這里不進行講解:
創建Python環境,命名mindspore_1.3.0:
conda create -n mindspore_1.3.0 python=3.7.5
安裝 wheel :
激活Python環境:
activate mindspore_1.3.0
安裝:
pip install wheel
安裝NUMA
下載:
wget https://github.com/numactl/numactl/releases/download/v2.0.14/numactl-2.0.14.tar.gz
解壓:
tar -zxvf numactl-2.0.14.tar.gz
配置:
./configure --prefix=/home/devilmaycry/anaconda3/mindspore_envs/numactl_2.0.14
編譯並安裝:
make -j8&& make install
修改系統環境,修改 .bashrc文件,添加內容:
# numa export PATH=/home/devilmaycry/anaconda3/mindspore_envs/numactl_2.0.14/bin:$PATH export LIBRARY_PATH=/home/devilmaycry/anaconda3/mindspore_envs/numactl_2.0.14/lib:$LIBRARY_PATH export LD_LIBRARY_PATH=/home/devilmaycry/anaconda3/mindspore_envs/numactl_2.0.14/lib:$LD_LIBRARY_PATH export C_INCLUDE_PATH=/home/devilmaycry/anaconda3/mindspore_envs/numactl_2.0.14/include:$C_INCLUDE_PATH export CPLUS_INCLUDE_PATH=$C_INCLUDE_PATH:$CPLUS_INCLUDE_PATH
重新載入 .bashrc 文件:
source ~/.bashrc
=========================================================================
必要環境已經全部安裝好,正式編譯:
git clone https://gitee.com/mindspore/mindspore.git -b r1.3
bash build.sh -e gpu
失敗。
報錯信息:
---------------- MindSpore: build start ----------------
mkdir: 已創建目錄 '/tmp/mindspore/build'
mkdir: 已創建目錄 '/tmp/mindspore/build//package'
mkdir: 已創建目錄 '/tmp/mindspore/build//package/mindspore'
mkdir: 已創建目錄 '/tmp/mindspore/build//package/mindspore/lib'
子模組 'graphengine'(https://gitee.com/mindspore/graphengine.git)未對路徑 'graphengine' 注冊
正克隆到 '/tmp/mindspore/graphengine'...
子模組路徑 'graphengine':檢出 'acc2472c4119d70b579d7ac2f7a6bbf2c344af29'
子模組 'metadef'(https://gitee.com/ascend/metadef.git)未對路徑 'metadef' 注冊
正克隆到 '/tmp/mindspore/graphengine/metadef'...
子模組路徑 'metadef':檢出 '0a9ebe1c7f7b27554659f39e387110ac30d4a1e6'
子模組 'akg'(https://gitee.com/mindspore/akg.git)未對路徑 'akg' 注冊
正克隆到 '/tmp/mindspore/akg'...
子模組路徑 'akg':檢出 '796260887e9c87964aad87ab8154211060870fec'
start build mindspore project.
mkdir: 已創建目錄 '/tmp/mindspore/build//mindspore'
-DDEBUG_MODE=off -DBUILD_PATH=/tmp/mindspore/build/ -DENABLE_INFER=ON -DENABLE_DUMP_PROTO=ON -DENABLE_DUMP_IR=on -DENABLE_PYTHON=on -DENABLE_MPI=ON -DENABLE_GPU=ON -DUSE_CUDA=ON -DCUDA_PATH= -DMS_REQUIRE_CUDA_VERSION=10.1 -DENABLE_CPU=ON -DX86_64_SIMD=off -DARM_SIMD=off -DENABLE_MINDDATA=ON -DUSE_GLOG=ON -DENABLE_AKG=ON -DENABLE_DEBUGGER=ON
-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /home/devilmaycry/anaconda3/mindspore_envs/gcc_7.3.0/bin/gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /home/devilmaycry/anaconda3/mindspore_envs/gcc_7.3.0/bin/g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Python3: /home/devilmaycry/anaconda3/envs/mindspore_1.3.0/bin/python3.7 (found version "3.7.5") found components: Interpreter Development Development.Module Development.Embed
Python3 found, version: 3.7.5
Python3 library path:
Python3 interpreter: /home/devilmaycry/anaconda3/envs/mindspore_1.3.0/bin/python3.7
-- Found Patch: /home/devilmaycry/anaconda3/mindspore_envs/patch_2.7.6/bin/patch
PATCH_EXECUTABLE=/home/devilmaycry/anaconda3/mindspore_envs/patch_2.7.6/bin/patch
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
CMake Error at cmake/check_requirements.cmake:66 (message):
Required package gmp not found, please install gmp and try building
MindSpore again.
Call Stack (most recent call first):
CMakeLists.txt:13 (include)
-- Configuring incomplete, errors occurred!
See also "/tmp/mindspore/build/mindspore/CMakeFiles/CMakeOutput.log".
See also "/tmp/mindspore/build/mindspore/CMakeFiles/CMakeError.log".
參考:
https://gitee.com/mindspore/mindspore/issues/I284ZL
========================================================================
另附其他環境的安裝方式:
mpfr 的安裝:
下載地址:
wget https://www.mpfr.org/mpfr-current/mpfr-4.1.0.tar.gz
解壓文件:
tar -zxvf mpfr-4.1.0.tar.gz
配置:
./configure --prefix=/home/devilmaycry/anaconda3/mindspore_envs/mpfr_4.1.0/
編譯安裝:
make && make install
配置文件: 添加內容到 .bashrc 文件中
# mpfr export LIBRARY_PATH=/home/devilmaycry/anaconda3/mindspore_envs/mpfr_4.1.0/lib:$LIBRARY_PATH export LD_LIBRARY_PATH=/home/devilmaycry/anaconda3/mindspore_envs/mpfr_4.1.0/lib:$LD_LIBRARY_PATH export C_INCLUDE_PATH=/home/devilmaycry/anaconda3/mindspore_envs/mpfr_4.1.0/include:$C_INCLUDE_PATH export CPLUS_INCLUDE_PATH=$C_INCLUDE_PATH:$CPLUS_INCLUDE_PATH
測試安裝及配置是否成功:
代碼: #test.cpp
#include <stdio.h> #include <mpfr.h> int main (void) { printf ("MPFR library: %-12s\nMPFR header: %s (based on %d.%d.%d)\n", mpfr_get_version (), MPFR_VERSION_STRING, MPFR_VERSION_MAJOR, MPFR_VERSION_MINOR, MPFR_VERSION_PATCHLEVEL); return 0; }
編譯及運行:
gcc test.cpp -o test -lmpfr
mpc 的安裝:
下載:
wget https://ftp.gnu.org/gnu/mpc/mpc-1.2.1.tar.gz
解壓:
tar -zxvf mpc-1.2.1.tar.gz
配置:
./configure --prefix=/home/devilmaycry/anaconda3/mindspore_envs/mpc_1.2.1/
編譯安裝:
make && make install
修改 .bashrc 文件,添加內容:
# mpc export LIBRARY_PATH=/home/devilmaycry/anaconda3/mindspore_envs/mpc_1.2.1/share:$LIBRARY_PATH export LD_LIBRARY_PATH=/home/devilmaycry/anaconda3/mindspore_envs/mpc_1.2.1/lib:$LD_LIBRARY_PATH export C_INCLUDE_PATH=/home/devilmaycry/anaconda3/mindspore_envs/mpc_1.2.1/include:$C_INCLUDE_PATH export CPLUS_INCLUDE_PATH=$C_INCLUDE_PATH:$CPLUS_INCLUDE_PATH
==================================================================