gpt4 book ai didi

Ubuntu16安装CUDA(9.1)和cuDNN的实现步骤(图文)

转载 作者:qq735679552 更新时间:2022-09-27 22:32:09 30 4
gpt4 key购买 nike

CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.

这篇CFSDN的博客文章Ubuntu16安装CUDA(9.1)和cuDNN的实现步骤(图文)由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.

本篇概览

自己有一台2015年的联想笔记本,显卡是gtx950m,已安装ubuntu 16.04 lts桌面版,为了使用其gpu完成deeplearning4j的训练工作,自己动手安装了cuda和cudnn,在此将整个过程记录下来,以备将来参考,整个安装过程分为以下几步:

  • 准备工作
  • 安装nvidia驱动
  • 安装cuda
  • 安装cudnn

特别问题说明

  • 按照一般步骤,在安装完nvidia显卡驱动后,会提示对应的cuda版本,接下来按照提示的版本安装cuda,例如我这里提示的是11.2,正常情况下,我应该安装11.2版本的cuda
  • 但是我选择9.1版本就行安装,因为之前的开发中发现deeplearning4j使用了11.2的sdk后,启动应用会有classnotfound的错误,此问题至今未修复(惭愧,欣宸水平如此之低…),因此,我在nvidia驱动提示11.2版本的情况下,依然安装了9.1版本,后来在此环境运行deeplearning4j应用一切正常
  • 如果您没有我这类问题,完全可以按照驱动指定的版本来安装cuda,具体的操作步骤稍后会详细说到;

准备工作

  • 接下来的操作,除了在网页下载,其余都是ssh远程连接到ubuntu机器操作的,ssh登录的帐号为普通帐号,并非root
  • 如果已有驱动,请先删除
?
1
sudo apt - get remove - - purge nvidia *

禁用nouveau驱动(很重要),用vi打开文件/etc/modprobe.d/blacklist.conf,在尾部增加以下内容,然后保存退出:

?
1
2
3
4
5
blacklist nouveau
blacklist lbm - nouveau
options nouveau modeset = 0
alias nouveau off
alias lbm - nouveau off

关闭nouveau:

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

更新initramfs

?
1
update - initramfs - u

执行reboot重启电脑 。

重启后,执行以下命令,应该不会有任何输出,证明nouveau已经禁用:

?
1
lsmod|grep nouveau

获取kernel source:

?
1
sudo apt - get install linux - source

安装过程中显示信息如下图:

Ubuntu16安装CUDA(9.1)和cuDNN的实现步骤(图文)

根据上图红框中的信息,可知内核版本号为,于是执行以下命令:

?
1
sudo apt - get install linux - headers - 4.4 . 0 - 210 - generic

下载和安装nvidia驱动

访问nvidia网站,地址https://www.nvidia.cn/download/index.aspx?lang=cn,然后选择对应的显卡和操作系统,我的选择如下图所示:

Ubuntu16安装CUDA(9.1)和cuDNN的实现步骤(图文)

点击上图搜索按钮后,进入下图页面,点击下载:

Ubuntu16安装CUDA(9.1)和cuDNN的实现步骤(图文)

下载得到的文件名为nvidia-linux-x86_64-460.84.run 。

关闭图形页面:

?
1
sudo service lightdm stop

给驱动文件增加可执行权限:

?
1
sudo chmod a + x nvidia - linux - x86_64 - 460.84 .run

开始安装:

?
1
sudo . / nvidia - linux - x86_64 - 460.84 .run - no - x - check - no - nouveau - check - no - opengl - files

遇到下图,选择红框:

Ubuntu16安装CUDA(9.1)和cuDNN的实现步骤(图文)

遇到下图,直接回车:

Ubuntu16安装CUDA(9.1)和cuDNN的实现步骤(图文)

恢复图形页面:

?
1
sudo service lightdm start

执行命令nvidia-smi,如果驱动安装成功,会显示以下内容:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
will@lenovo:~ / temp / 202106 / 20 $ nvidia - smi
sun jun 20 09 : 02 : 11 2021      
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
| nvidia - smi 460.84       driver version: 460.84       cuda version: 11.2     |
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - +
| gpu  name        persistence - m| bus - id        disp.a | volatile uncorr. ecc |
| fan  temp  perf  pwr:usage / cap|         memory - usage | gpu - util  compute m. |
|                               |                      |               mig m. |
| = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = + = = = = = = = = = = = = = = = = = = = = = = + = = = = = = = = = = = = = = = = = = = = = = |
|   0  geforce gtx 950m    off  | 00000000 : 01 : 00.0 off |                  n / a |
| n / a   41c    p0    n / a /  n / a |      0mib /  4046mib |      1 %      default |
|                               |                      |                  n / a |
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - +
                                                                               
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
| processes:                                                                  |
|  gpu   gi   ci        pid   type   process name                  gpu memory |
|        id   id                                                   usage      |
| = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = |
|  no running processes found                                                 |
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +

从上述内容可见cuda version: 11.2表示该驱动对应的cuda版本应该是11.2,正如前面所说,我这边遇到了问题,因此接下来会安装9.1版本,但是您可以选择安装11.2 。

安装cuda

浏览器访问,点击红框中的链接:

Ubuntu16安装CUDA(9.1)和cuDNN的实现步骤(图文)

如下图,下载linux版本:

Ubuntu16安装CUDA(9.1)和cuDNN的实现步骤(图文)

继续选择x86_64:

Ubuntu16安装CUDA(9.1)和cuDNN的实现步骤(图文)

选择具体的linux版本及其版本号:

Ubuntu16安装CUDA(9.1)和cuDNN的实现步骤(图文)

要下载的东西不少,一个安装程序和三个补丁:

Ubuntu16安装CUDA(9.1)和cuDNN的实现步骤(图文)

上述四个文件的下载地址整理如下:

https://developer.download.nvidia.cn/compute/cuda/9.1/secure/prod/local_installers/cuda_9.1.85_387.26_linux.run?p0ntu_6nltuuemm6fjrk1w5vl4km7oat1ofw870zkj-zdw2ckkntfloe6klrjfw2cmta8z3q390_6urlgc6lqjoqlifw9gvfvdcusninypllaw1u8lry8r4ovntpnzaxu4bqchjvdb6c6rjq20dktccrd4640woxt1yhmd95v1du7wdbbxq2eoy 。

https://developer.download.nvidia.cn/compute/cuda/9.1/secure/prod/patches/1/cuda_9.1.85.1_linux.run?yexf_7wiglhauw--e_yvlqzrgxv0x2i043wojvy-ydxu5kyhc-eyqf5jml-4mvymlvpycec5rht2sdwscx20cjbdowpkt30kwb9vx8e4oilajdq3mvpvxdikksiobux-h0q0n0jsknn80vmhw-nk8jwvry_e6mufzqwbapk 。

https://developer.download.nvidia.cn/compute/cuda/9.1/secure/prod/patches/2/cuda_9.1.85.2_linux.run?5jgzxnigaojkaapbmagjhsw7ebqvygyyoqe2vbxz1ev8qp2bzxjlxipgao11ugwhorirqkdjgq5b8efh4ashbvutmupaasvrimckdzw5yjjiobgqrceyu-lfo59abrrer57mxa0t1sc97fc80iozq8ox2repjn7a3oyvgd8 。

https://developer.download.nvidia.cn/compute/cuda/9.1/secure/prod/patches/3/cuda_9.1.85.3_linux.run?cxwimjtc-xroyihig-uzmh62odbjinf1fmxtz_bsw1nq0zz5cl5r8qlmlmr_1j2rvhk3j8z5ls6dpart8frjghh2mevn5tefmoclam8udm-rsmmmqhxye66hhn2d0drvedtcwe8zreiyb2rpucaz9svcfe8z319mge4ju94 。

下载完毕后,执行命令chmod a+x *.run为上述四个文件增加可执行权限 。

安装cuda:

?
1
sudo sh cuda_9. 1.85_387 . 26_linux .run

遇到license时,像是用vi工具那样,输入":",再输入"q"回车,就能跳过license阅读,执行真正的安装操作了:

Ubuntu16安装CUDA(9.1)和cuDNN的实现步骤(图文)

接下来是一系列提问,每一个提问的回答如下图,千万注意红框中的问题一定要选择n:

Ubuntu16安装CUDA(9.1)和cuDNN的实现步骤(图文)

安装完成后输出以下内容:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
installing the cuda toolkit in / usr / local / cuda - 9.1 ...
missing recommended library: libglu.so
missing recommended library: libx11.so
missing recommended library: libxi.so
missing recommended library: libxmu.so
missing recommended library: libgl.so
 
installing the cuda samples in / home / will ...
copying samples to / home / will / nvidia_cuda - 9.1_samples now...
finished copying samples.
 
= = = = = = = = = = =
= summary =
= = = = = = = = = = =
 
driver:   not selected
toolkit:  installed in / usr / local / cuda - 9.1
samples:  installed in / home / will, but missing recommended libraries
 
please make sure that
  -   path includes / usr / local / cuda - 9.1 / bin
  -   ld_library_path includes / usr / local / cuda - 9.1 / lib64, or , add / usr / local / cuda - 9.1 / lib64 to / etc / ld.so.conf and run ldconfig as root
 
to uninstall the cuda toolkit, run the uninstall script in / usr / local / cuda - 9.1 / bin
 
please see cuda_installation_guide_linux.pdf in / usr / local / cuda - 9.1 / doc / pdf for detailed information on setting up cuda.
 
* * * warning: incomplete installation! this installation did not install the cuda driver. a driver of version at least 384.00 is required for cuda 9.1 functionality to work.
to install the driver using this installer, run the following command, replacing <cudainstaller> with the name of this run file :
     sudo <cudainstaller>.run - silent - driver
 
logfile is / tmp / cuda_install_13425.log

打开文件~/.bashrc,在尾部增加以下两行(ld_library_path如果已经存在,请参考path的写法改成追加):

?
1
2
export path = / usr / local / cuda - 9.1 / bin :$path
export ld_library_path = / usr / local / cuda - 9.1 / lib64

执行命令source ~/.bashrc使配置生效 。

执行命令su -切换到root帐号,执行以下命令(不要用sudo,而是切到root帐号):

?
1
sudo echo "/usr/local/cuda-9.1/lib64" >> / etc / ld.so.conf

再以root身份执行以下命令:

?
1
ldconfig

执行命令exit退出root身份,现在又是普通帐号的身份了 。

执行命令nvcc -v检查cuda版本,注意参数v是大写:

?
1
2
3
4
5
will@lenovo:~$ nvcc - v
nvcc: nvidia (r) cuda compiler driver
copyright (c) 2005 - 2017 nvidia corporation
built on fri_nov__3_21: 07 : 56_cdt_2017
cuda compilation tools, release 9.1 , v9. 1.85

安装第一个补丁:

?
1
sudo sh cuda_9. 1.85 . 1_linux .run

安装第二个补丁:

?
1
sudo sh cuda_9. 1.85_387 . 26_linux .run

安装第三个补丁:

?
1
sudo sh cuda_9. 1.85_387 . 26_linux .run

安装cudnn

浏览器访问:

Ubuntu16安装CUDA(9.1)和cuDNN的实现步骤(图文)

按提示登录,如果没有帐号请注册一个,登录后进入下载页面,需要点击下图红框位置才有能见到老版本:

Ubuntu16安装CUDA(9.1)和cuDNN的实现步骤(图文)

选择与cuda匹配的版本:

Ubuntu16安装CUDA(9.1)和cuDNN的实现步骤(图文)

下载后解压,得到文件夹cuda,然后执行以下命令:

?
1
2
3
4
sudo cp cuda / include / cudnn.h / usr / local / cuda / include /
sudo cp cuda / lib64 / libcudnn * / usr / local / cuda / lib64 /
sudo chmod a + r / usr / local / cuda / include / cudnn.h
sudo chmod a + r / usr / local / cuda / lib64 / libcudnn *

执行检查确认的命令cat /usr/local/cuda/include/cudnn.h | grep cudnn_major -a 2,如果安装顺利会有以下输出:

?
1
2
3
4
5
6
7
#define cudnn_major 7
#define cudnn_minor 1
#define cudnn_patchlevel 3
- -
#define cudnn_version    (cudnn_major * 1000 + cudnn_minor * 100 + cudnn_patchlevel)
 
#include "driver_types.h"

至此,ubuntu16安装cuda(9.1)和cudnn已经完成了,希望能给您一些参考.

到此这篇关于ubuntu16安装cuda(9.1)和cudnn的实现步骤(图文)的文章就介绍到这了,更多相关ubuntu16安装cuda(9.1)和cudnn内容请搜索我以前的文章或继续浏览下面的相关文章希望大家以后多多支持我! 。

原文链接:https://blog.csdn.net/boling_cavalry/article/details/118065868 。

最后此篇关于Ubuntu16安装CUDA(9.1)和cuDNN的实现步骤(图文)的文章就讲到这里了,如果你想了解更多关于Ubuntu16安装CUDA(9.1)和cuDNN的实现步骤(图文)的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com