安装CUDA和cuDNN

GPU和CPU区别

 1,CPU主要用于处理通用逻辑,以及各种中断事物

 2,GPU主要用于计算密集型程序,可并行运作;

NVIDIA 的 GeForce 显示卡系列采用 GPU 特性进行快速计算,渲染电脑画面,比如大型游戏,图像处理等场景的画面
深度学习的训练过程中,包含了大量重复性的计算,利用 GPU 的计算和并行特性,可提高训练的效率,具备 GPU 特性的电脑显卡就有用武之地啦!

使用 GPU 的计算前需要做些准备,下面以 window 7 x64 系统为例子

一,检查显卡类型和计算能力
1,查看笔记本显卡型号,以及计算能力
下载个 GPU 查看器, https://www.techpowerup.com/download/gpu-z/

我笔记本显卡型号:NVIDIA GeForce 940M

2,确定对应显卡 GPU 的计算能力
去 NVIDIA 官网查看 https://developer.nvidia.com/cuda-gpus

NVIDIA GeForce 940M Compute Capability 是 5.0

tensorflow 1.3 版本要求 GPU 计算能力必须在 3.0 以上
https://www.tensorflow.org/versions/r1.3/install/install_windows

GPU card with CUDA Compute Capability 3.0 or higher. See NVIDIA documentation for a list of supported GPU cards.

要是计算能力不支持,运行 tensorflow 会报错

Ignoring visible gpu device (device: 0, name: GeForce GT 630M, pci bus id: 0000:01:00.0) with Cuda compute capability 2.1. The minimum required Cuda capability is 3.0.

二,安装显卡驱动, CUDA ,cuDNN

1,安装显卡驱动

显卡一般都安装好了,但可能会出现显卡驱动版本跟 CUDA 不对应的问题
自己去 NVIDIA 官网下载驱动 http://www.nvidia.com/Download/index.aspx,或者使用驱动精灵

2,安装 CUDA
CUDA的主要作用是链接 GPU 和 应用程序,方便用户通过 CUDA 的 API 调度 GPU 进行计算

安装说明地址:http://docs.nvidia.com/cuda/cuda-installation-guide-microsoft-windows/
选择对应版本,window7 系统 64 位, tensorflow 1.3 当前使用 CUDA 8.0版本

安装 cuda 的时候,会询问是否安装显卡驱动,说明 cuda 安装程序里包含了的显卡驱动;
建议先不要安装 cuda 里的显卡驱动,待安装完 cuda 后,执行例子程序,如果报错再检查显卡驱动是否正确,避免覆盖原来的显卡驱动

安装完后执行 nvcc -V 检查

C:Usersyunhuichen>nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2016 NVIDIA Corporation
Built on Mon_Jan__9_17:32:33_CST_2017
Cuda compilation tools, release 8.0, V8.0.60

运行例子

C:Program FilesNVIDIA GPU Computing ToolkitCUDAv8.0extrasdemo_suite>device
Query.exe
deviceQuery.exe Starting...

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

Detected 1 CUDA Capable device(s)

Device 0: "GeForce 940M"
  CUDA Driver Version / Runtime Version          9.0 / 8.0
  CUDA Capability Major/Minor version number:    5.0
  Total amount of global memory:                 1024 MBytes (1073741824 bytes)
  ( 3) Multiprocessors, (128) CUDA Cores/MP:     384 CUDA Cores
  GPU Max Clock rate:                            980 MHz (0.98 GHz)
  Memory Clock rate:                             1001 Mhz
  Memory Bus Width:                              64-bit
  L2 Cache Size:                                 1048576 bytes
  Maximum Texture Dimension Size (x,y,z)         1D=(65536), 2D=(65536, 65536),
3D=(4096, 4096, 4096)
  Maximum Layered 1D Texture Size, (num) layers  1D=(16384), 2048 layers
  Maximum Layered 2D Texture Size, (num) layers  2D=(16384, 16384), 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 1 copy engine(s)
  Run time limit on kernels:                     Yes
  Integrated GPU sharing Host Memory:            No
  Support host page-locked memory mapping:       Yes
  Alignment requirement for Surfaces:            Yes
  Device has ECC support:                        Disabled
  CUDA Device Driver Mode (TCC or WDDM):         WDDM (Windows Display Driver Mo
del)
  Device supports Unified Addressing (UVA):      Yes
  Device PCI Domain ID / Bus ID / location ID:   0 / 4 / 0
  Compute Mode:
     < Default (multiple host threads can use ::cudaSetDevice() with device simu ltaneously) >

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 9.0, CUDA Runtime Versi
on = 8.0, NumDevs = 1, Device0 = GeForce 940M
Result = PASS

C:Program FilesNVIDIA GPU Computing ToolkitCUDAv8.0extrasdemo_suite>

至此已经安装 cuda 成功
当然此过程可能会遇到以下问题

NVIDIA Geforce GTX 940M 设备是不可移动的,无法弹出或拔出

这是因为显卡驱动和CUDA版本不对应,可试下安装CUDA里的显卡驱动

3,安装 cuDNN
cuDNN 是一个为了优化深度学习计算的类库,它能将模型训练的计算优化之后,再通过 CUDA 调用 GPU 进行运算
当然你也可直接使用 GUDA,而不通过 cuDNN ,但运算效率会低好多

cuDNN 下载地址:https://developer.nvidia.com/cudnn

选择跟CUDA 8.0 对应的版本 cuDNN  6.1

其实就几个 lib 文件,解压出来把安装路径添加到 PATH 中;你也可以把所有 lib 文件复制到 CUDA 对应目录下

原文地址:https://www.cnblogs.com/liuyihai/p/9310909.html