Ubuntu16.04安装GPU版Pytorch流程

声明:本文为自我实践,如按本文操作有任何问题,本人不负有任何责任。

1、硬件条件

电脑为i7处理器,显卡为gtx1060,其他就不重要了。

2、总体流程

安装ubuntu16.04系统;

安装nvidia显卡驱动;

安装cuda8.0toolkit;

安装cudnn8.0;

安装集成开发环境anaconda3;

安装pytorch;

进行测试;

3、安装ubuntu16.04系统

本人叫他人代装的;

4、安装nvidia显卡驱动

进入“系统设置——软件和更新”

点到“附加驱动”,然后按如图选择,然后是“应用”,然后“重启”。

验证;在终端中输入:nvidia-smi,出现下图的配置信息。

5、安装cuda8.0toolkit;

首先下载cuda8.0的安装文件,链接:https://developer.nvidia.com/cuda-toolkit-archive;本人下载的为CUDAToolkit 8.0 GA2;

Ubuntu16.04安装GPU版Pytorch流程_pytorch

 

然后,安装CUDA8.0,打开终端输入以下内容,同时,如下图所示;

 

cd /media/你的用户名/TOSHIBA\ EXT/alu/CUDA/ # 进入cuda 所在文件夹
# 根据官网上的提示安装 cuda 8.0
sudo dpkg -i cuda-repo-ubuntu1604-8-0-rc_8.0.27-1_amd64.deb
sudo apt-get update
sudo apt-get install cuda


然后配置环境变量,在终端中输入图片中的命令。在.bashrc文件中输入以下内容。

export PATH="$PATH:/usr/local/cuda-8.0/bin"
export LD_LIBRARY_PATH="/usr/local/cuda-8.0/lib64"


Ubuntu16.04安装GPU版Pytorch流程_cudnn_02

5.1 测试cuda

cd /usr/local/cuda-10.0/samples/1_Utilities/deviceQuery
make
./deviceQuery


正确安装时输出以下内容:

./deviceQuery Starting...

CUDA Device Query (Runtime API) version (CUDART static linking)

Detected 1 CUDA Capable device(s)

Device 0: "GeForce GTX 1080 Ti"
CUDA Driver Version / Runtime Version 10.1 / 10.1
CUDA Capability Major/Minor version number: 6.1
Total amount of global memory: 11178 MBytes (11721506816 bytes)
(28) Multiprocessors, (128) CUDA Cores/MP: 3584 CUDA Cores
GPU Max Clock rate: 1582 MHz (1.58 GHz)
Memory Clock rate: 5505 Mhz
Memory Bus Width: 352-bit
L2 Cache Size: 2883584 bytes
Maximum Texture Dimension Size (x,y,z) 1D=(131072), 2D=(131072, 65536), 3D=(16384, 16384, 16384)
Maximum Layered 1D Texture Size, (num) layers 1D=(32768), 2048 layers
Maximum Layered 2D Texture Size, (num) layers 2D=(32768, 32768), 2048 layers
Total amount of constant memory: 65536 bytes
Total amount of shared memory per block: 49152 bytes
Total number of registers available per block: 65536
Warp size: 32
Maximum number of threads per multiprocessor: 2048
Maximum number of threads per block: 1024
Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
Max dimension size of a grid size (x,y,z): (2147483647, 65535, 65535)
Maximum memory pitch: 2147483647 bytes
Texture alignment: 512 bytes
Concurrent copy and kernel execution: Yes with 2 copy engine(s)
Run time limit on kernels: No
Integrated GPU sharing Host Memory: No
Support host page-locked memory mapping: Yes
Alignment requirement for Surfaces: Yes
Device has ECC support: Disabled
Device supports Unified Addressing (UVA): Yes
Device supports Compute Preemption: Yes
Supports Cooperative Kernel Launch: Yes
Supports MultiDevice Co-op Kernel Launch: Yes
Device PCI Domain ID / Bus ID / location ID: 0 / 1 / 0
Compute Mode:
< Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 10.1, CUDA Runtime Version = 10.1, NumDevs = 1
Result = PASS


6、安装cudnn8.0

首先下载软件,链接:https://developer.nvidia.com/cudnn;需要登录,按网上的流程走就行。如下图所示:

Ubuntu16.04安装GPU版Pytorch流程_ubuntu_03


然后打开终端,1、cd到文件的下载目录;2、解压cudnn8.0文件;3、复制一些文件;在终端中输入以下命令;

 

cd  cd /media/你的用户名/TOSHIBA\ EXT/alu/CUDA/ # 进入 cuDNN 安装文件的所在路径
tar xvzf cudnn-8.0-linux-x64-v6.0.tgz # 解压
sudo cp cuda/include/cudnn.h /usr/local/cuda/include # 复制到 include 中
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64 # 复制到 lib64 中
sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn* # 讲头文件复制进去你的用户名/TOSHIBA\ EXT/alu/CUDA/ # 进入 cuDNN 安装文件的所在路径 tar xvzf cudnn-8.0-linux-x64-v6.0.tgz # 解压 sudo cp cuda/include/cudnn.h /usr/local/cuda/include # 复制到 include 中 sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64 # 复制到 lib64 中 sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn* # 讲头文件复制进去


6.1 测试cudnn

拷贝完成之后,可以使用以下命令查看CUDNN的版本信息:

cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2


7、安装anaconda3.5

 

下载anaconda3.5文件,链接:https://www.anaconda.com/download/#linux;本人下载的为:Anaconda3-5.1.0-Linux-x86_64.sh

Ubuntu16.04安装GPU版Pytorch流程_cuda_04

 

 

安装anaconda3.5;具体参考以下链接:javascript:void(0)

 

验证;安装完成之后,打开终端,输入python,出现如下信息;

Ubuntu16.04安装GPU版Pytorch流程_cuda_05

 

 

8、安装pytorch

 

首先,下载文件;链接:http://pytorch.org/previous-versions/;本人下载的版本为:torch-0.3.0.post4-cp36-cp36m-linux_x86_64.whl

 

Ubuntu16.04安装GPU版Pytorch流程_cudnn_06

 

然后,安装pytorch;在终端中cd到pytorch文件的下载目录;如下图所示:

Ubuntu16.04安装GPU版Pytorch流程_linux_07

 

然后输入以下命令:​pip install torch-0.2.0.post3-cp36-cp36m-manylinux1_x86_64.whl​

 

安装torchvison,在终端中,刚才的目录输入以下命令:​pip install torchvision​​​​,如下图所示:​

Ubuntu16.04安装GPU版Pytorch流程_cuda_08

 

9​​、验证

在终端中打开​​ipython​​,输入以下内容:

 

​importtorch​

​x= torch.Tensor([1.0])​

​xx= x.cuda()​

 

​print(xx)​

 

如果没有报错就没有什么问题了。

本人是个小菜鸟,其实,个人觉得应该在安装每个模块之后就要验证以下是否安装正确。本文,分享出来,请高手更快的上手,更好的完善吧。