安装 CUDA9.0 + cuDNN8.0
再唠叨之前的准备:
-
1.修改资源镜像,可用脚本 ubuntu修改资源镜像
-
2.系统保持最新
sudo apt-get update
sudo apt-get upgrade
我的环境:
OS: ubuntu 16.04.3
uname -a
Linux scott-Z170X-UD3 4.10.0-37-generic #41~16.04.1-Ubuntu SMP Fri Oct 6 22:42:59 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.5) 5.4.0 20160609
敲黑板!
-
tensorflow 有CPU 版,GPU 版。
-
不是所有显卡都支持CUDA,可以在这里看到cuda评分,推荐GPU Compute Capability 最少 >3.0
该网址查看 cuda计算能力评分 GPU Compute Capability
CUDA官方网址
你可以选择下载自己的平台安装包
我我用的是deb[local]
CUDA9.0 deb local ubuntu x64 下载地址
Installation Instructions:
sudo dpkg -i cuda-repo-ubuntu1604-9-0-local_9.0.176-1_amd64.deb
sudo apt-key add /var/cuda-repo-<version>/7fa2af80.pub
sudo apt-get update
sudo apt-get install cuda
Other installation options are available in the form of meta-packages. For example, to install all the library packages, replace "cuda" with the "cuda-libraries-9-0" meta package. For more information on all the available meta packages click here.
The CUDA Toolkit contains Open-Source Software. The source code can be found here.
The checksums for the installer and patches can be found in Installer Checksums.
For further information, see the Installation Guide for Linux and the CUDA Quick Start Guide.
敲黑板!
推荐先看pdf [Installation Guide for Linux] , [CUDA Quick Start Guide] ,里面介绍了 不同平台的操作区别。
我只介绍ubuntu的安装
- 此时查看 Cuda compilation tools版本,
NVIDIA CUDA C/C++ Compiler (NVCC)
nvcc --version
提示找不到命令.我当时很奇怪。 之后,我用ubantu16.04的apt 软件库去安装Cuda compilation tools
sudo apt install nvidia-cuda-toolkit
再查询,发现ubuntu库中的cuda是7.5的,不是我这次安装的版本。
果断删除
sudo apt remove nvidia-cuda-toolkit
-
上网找了资料,发现原来是需要更新环境变量
- 编辑.bashrc:
sudo gedit .bashrc
- 添加cuda文件路径
export PATH=/usr/local/cuda-9.0/bin:$PATH export LD_LIBRARY_PATH=/usr/local/cuda-9.0/bin/lib64:$LD_LIBRARY_PATH
- 需要更新环境变量,终端中输入:
source ~/.bashrc
- 编辑.bashrc:
原理点此链接 在 Ubuntu 系统中有三种设置环境变量 PATH 的方法
- 再查询,是9.0!到此CUDA9.0 安装成功
NVIDIA cuDNN is a GPU-accelerated library of primitives for deep neural networks.
[Download cuDNN v7.0.3 (Sept 28, 2017), for CUDA 9.0] (https://developer.nvidia.com/rdp/cudnn-download)
不同平台操作看guide
windows:
安装完CUDA,直接复制zip包下的文件到 CUDA_PATH
CUDA_PATH C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0
验证驱动版
cat /proc/driver/nvidia/version
查看 Cuda compilation tools版本
nvcc --version
或者nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Sep__1_21:08:03_CDT_2017
Cuda compilation tools, release 9.0, V9.0.176
查看GPU 当前信息
nvidia-smi
Fri Oct 20 16:21:13 2017
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 384.81 Driver Version: 384.81 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 GeForce GTX 950 Off | 00000000:01:00.0 On | N/A |
| 33% 33C P8 12W / 100W | 332MiB / 1995MiB | 6% Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| 0 985 G /usr/lib/xorg/Xorg 214MiB |
| 0 1593 G compiz 95MiB |
| 0 1973 G fcitx-qimpanel 9MiB |
| 0 9093 G /usr/bin/vlc 8MiB |
+-----------------------------------------------------------------------------+
PCI 接口信息
lspci |grep NVIDIA
GeForce GTX 950安装CUDA 9.0后,PCI显卡显示如下
01:00.0 VGA compatible controller: NVIDIA Corporation GM206 [GeForce GTX 950] (rev a1)
01:00.1 Audio device: NVIDIA Corporation Device 0fba (rev a1)