Ubuntu 16.04安装GPU版的MXNet

1. 选择访问网速最快的的软件源服务器,让你获得最佳apt-get速度:

在“系统设置-> “软件与更新界面中,点击“下载自按钮,点击“选择最佳服务器按钮开始搜索。

2. 更新系统,打开终端,输入

sudo apt-get update

sudo apt-get upgrade -y

sudo apt-get dist-upgrade -y

3. 安装C/C++编译器、SSH远程访问工具、VIM、Git

sudo apt-get install build-essential openssh-server vim git

# 在NVIDIA安装时,如果遇到什么莫名其妙的问题进不了系统,还有机会通过远程访问的方式进行操作。

4. 安装NVIDIA驱动

屏蔽Ubuntu系统内的Nouveau驱动:

echo -e "blacklist nouveau\nblacklist lbm-nouveau\noptions nouveau modeset=0\nalias nouveau off\nalias lbm-nouveau off\n" | sudo tee /etc/modprobe.d/blacklist-nouveau.conf

echo options nouveau modeset=0 | sudo tee -a /etc/modprobe.d/nouveau-kms.conf

sudo update-initramfs -u

重启系统,并再次更新一下系统(同步骤2)之后,安装CUDA(从https://developer.nvidia.com/cuda-downloads 网站上进行下载)

sudo service lightdm stop

sudo sh cuda_8.0.61_375.26_linux.run

sudo sh cuda_8.0.61.2_linux.run

sudo service lightdm start

安装CUDNN(下载链接:http://developer.download.nvidia.com/compute/redist/cudnn/v5.1/cudnn-8.0-linux-x64-v5.1.tgz ):

sudo tar -xzf cudnn-8.0-linux-x64-v5.1.tgz -C /usr/local

配置系统CUDA环境:

sudo touch /etc/ld.so.conf.d/cuda.conf

sudo chmod 777 "/etc/ld.so.conf.d/cuda.conf"

sudo echo "/usr/local/cuda-8.0/lib64" > /etc/ld.so.conf.d/cuda.conf

sudo ldconfig

echo "" >> ~/.bashrc

echo "# Added CUDA Paths" >> ~/.bashrc

echo LPATH=$LPATH:/usr/local/cuda-8.0:/usr/local/cuda-8.0/bin:/usr/local/cuda-8.0/lib64:/usr/local/cuda-8.0/lib >> ~/.bashrc

echo LIBRARY_PATH=$LIBRARY_PATH:/usr/local/cuda-8.0:/usr/local/cuda-8.0/lib64:/usr/local/cuda-8.0/lib >> ~/.bashrc

echo LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-8.0:/usr/local/cuda-8.0/lib64:/usr/local/cuda-8.0/lib >> ~/.bashrc

echo PATH=$PATH:/usr/local/cuda-8.0/bin:/usr/local/cuda-8.0/lib64:/usr/local/cuda-8.0/lib >> ~/.bashrc

source ~/.bashrc

5. 安装OpenBLAS

sudo apt-get install -y libopenblas-dev liblapack-dev

P.S. 安装Intel MKL可以获得更佳的性能(下载链接:https://software.intel.com/en-us/mkl )

6. 安装OpenCV

sudo apt-get install -y libopencv-dev

sudo apt-get install -y python-opencv

7. 下载及编译MXNet

git clone --recursive https://github.com/dmlc/mxnet
cd mxnet

make -j $(nproc) USE_OPENCV=1 USE_BLAS=openblas USE_CUDA=1 USE_CUDA_PATH=/usr/local/cuda USE_CUDNN=1

8. 在Python里编写MXNet代码

安装相关Python的环境

sudo apt-get install -y python-dev python-setuptools python-numpy python-pip

cd $mxnet_path/python

pip install --upgrade pip

pip install -e .

sudo apt-get install graphviz

pip install graphviz

验证安装成功:

运行python,输入:

import mxnet as mx

a = mx.nd.ones((2, 3), mx.gpu())

b = a * 2 + 1

b.asnumpy()

应该得到结果:



Reference :

1. https://www.linkedin.com/pulse/installing-nvidia-cuda-80-ubuntu-1604-linux-gpu-new-victor

2. http://mxnet.io/get_started/install.html 

你可能感兴趣的:(Ubuntu 16.04安装GPU版的MXNet)