Nvidia CUDA Toolkit的安装(cuda)
PS:特别推荐*.deb的方法,目前已提供离线版的deb文件,该方法比较简单,不需要切换到tty模式,因此不再提供原来的*.run安装方法,这里以CUDA 7.5为例。
一、CUDA Repository
1.1 安装所需依赖包
sudo apt-get install build-essential # basic requirement # sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev libhdf5-serial-dev libgflags-dev libgoogle-glog-dev liblmdb-dev protobuf-compiler #required by caffe
获取CUDA安装包,安装包请自行去NVidia官网下载。(https://developer.nvidia.com/cuda-downloads)
cd 到安装包所在的文件位置,执行下面命令。
$ sudo dpkg -i cuda-repo-ubuntu1504-7-5-local_7.5-18_amd64 $ sudo apt-get update $ sudo apt-get install cuda
安装完,这里可以重启电脑,分辨率就会自动调整了,不过不一定会变成完全适应屏幕。如果一开始安装Ubuntu没有出现输入信号的问题的话,不存在分辨率自动调整的问题。
1.2 设置环境变量:
(设置环境变量时,首先确定好cuda安装路径和位置,这一步非常重要,在安装时不需要对下面位置进行修改,系统会自动建立连接)
在/etc/profile中添加CUDA环境变量(最好使用vim,不要用gedit,刚刚装完系统gedit会导致键盘错乱,增加不必要的麻烦)
sudo gedit /etc/profile
在最后行添加内容:
export PATH=/usr/local/cuda/bin:$PATH export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
保存后, 执行下列命令, 使环境变量立即生效
source /etc/profile
同时需要添加lib库路径: 在 /etc/ld.so.conf.d/加入文件 cuda.conf,
sudo vim /etc/ld.so.conf.d/cuda.conf
内容如下
/usr/local/cuda/lib64 /lib /usr/lib /usr/lib32 这里把lib库都加全了
保存后,执行下列命令使之立刻生效
sudo ldconfig -v
2.2 安装CUDA SAMPLE:
进入/usr/local/cuda/samples, 执行下列命令来build samples
sudo make all -j8
全部编译完成后, 进入/usr/local/cuda/samples/1_Utilities/deviceQuery$ ./deviceQuery , 运行deviceQuery
/usr/local/cuda/samples/1_Utilities/deviceQuery$ ./deviceQuery
如果出现显卡信息, 则驱动及显卡安装成功:
CUDA Device Query (Runtime API) version (CUDART static linking) Detected 1 CUDA Capable device(s) Device 0: "GeForce GTX 960" CUDA Driver Version / Runtime Version 7.5 / 7.5 CUDA Capability Major/Minor version number: 5.2 Total amount of global memory: 4095 MBytes (4294246400 bytes) ( 8) Multiprocessors, (128) CUDA Cores/MP: 1024 CUDA Cores GPU Max Clock rate: 1329 MHz (1.33 GHz) Memory Clock rate: 3600 Mhz Memory Bus Width: 128-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 2 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 Device supports Unified Addressing (UVA): 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 = 7.5, CUDA Runtime Version = 7.5, NumDevs = 1, Device0 = GeForce GTX 960 Result = PASS
Nvidia CUDA Toolkit的安装(cudnn)
二、CUDNN Repository
这部分比较简单,首先要注册Nvidia的开发账号,然后才能下载cudnn。
简单地说,就是复制几个文件:库文件和头文件。将cudnn的头文件复制到/usr/local/cuda/lib64,将cudnn的库文件复制到/usr/local/cuda/include。
下载下来后,cd 到文件包目录下,解压文件:
tar -zxf cudnn-7.0-linux-x64-v4.0-prod.tgz cd cuda
#链接到cuda的库里
sudo cp lib64/* /usr/local/cuda/lib64/ sudo cp include/cudnn.h /usr/local/cuda/include/
要不要链接cuDNN的库文件:http://www.cnblogs.com/empty16/p/4793404.html (要,必须要!!)
$ sudo ln -sf /usr/local/lib/libcudnn.so.4.0.7 /usr/local/lib/libcudnn.so.4 $ sudo ln -sf /usr/local/lib/libcudnn.so.4 /usr/local/lib/libcudnn.so
#链接完config更新
$ sudo ldconfig
完成cuda和cudnn的安装