ubuntu18.04安装cuda9.0+cudnn+tf

1.禁用nouveau

安装完ubuntu18.04后,在“软件和更新“---附加驱动,会有驱动如果没有,那就自己去安装。

首先,需要禁用 nouveau,只有在禁用掉 nouveau 后才能顺利安装 NVIDIA 显卡驱动。

禁用方法就是在 /etc/modprobe.d/blacklist-nouveau.conf 文件中添加一条禁用命令,首先需要打开该文件,通过以下命令打开:

   sudo gedit /etc/modprobe.d/blacklist.conf

输入密码后在最后一行加上:  blacklist nouveau 是将Ubuntu自带的显卡驱动加入黑名单

Ctrl +C保存后,注意此时还需执行以下命令使禁用 nouveau 真正生效终端输入 : sudo update-initramfs -u

通过lsmod命令查看,确认nouveau是否已经被屏蔽掉。

lsmod | grep nouveau

若执行命令后无任何输出证明nouveau禁用成功,如有输出,则证明nouveau没有被禁用。

可以重启再看一下。

2.安装显卡驱动

请先去NVIDIA官方网站查看自己的显卡驱动型号再来操作安装,请一定注意。

https://www.nvidia.com/Download/index.aspx?lang=en-us

看显卡驱动版本支持的cuda:

https://docs.nvidia.com/deploy/cuda-compatibility/index.html#binary-compatibility__table-toolkit-driver

其中:

gaym ready跟现在一样频繁更新保持对最新游戏的优化
creator ready侧重稳定 更新间隔会比较长

GeForce笔记本电脑产品
显卡 计算能力
Geforce RTX 2080 7.5
Geforce RTX 2070 7.5
Geforce RTX 2060 7.5
GeForce GTX 1080 6.1
GeForce GTX 1070 6.1
GeForce GTX 1060 6.1
GeForce GTX 980 5.2
GeForce GTX 980M 5.2
GeForce GTX 970M 5.2
GeForce GTX 965M 5.2
GeForce GTX 960M 5.0
GeForce GTX 950M 5.0
GeForce 940M 5.0
GeForce 930M 5.0
GeForce 920M 3.5
GeForce 910M 5.2
GeForce GTX 880M 3.0
GeForce GTX 870M 3.0
GeForce GTX 860M 3.0 / 5.0(**)
GeForce GTX 850M 5.0
GeForce 840M 5.0
GeForce 830M 5.0
GeForce 820M 2.1
GeForce 800M 2.1
GeForce GTX 780M 3.0
GeForce GTX 770M 3.0
GeForce GTX 765M 3.0
GeForce GTX 760M 3.0
GeForce GTX 680MX 3.0
GeForce GTX 680M 3.0
GeForce GTX 675MX 3.0
GeForce GTX 675M 2.1
GeForce GTX 670MX 3.0
GeForce GTX 670M 2.1
GeForce GTX 660M 3.0
GeForce GT 755M 3.0
GeForce GT 750M 3.0
GeForce GT 650M 3.0
GeForce GT 745M 3.0
GeForce GT 645M 3.0
GeForce GT 740M 3.0
GeForce GT 730M 3.0
GeForce GT 640M 3.0
GeForce GT 640M LE 3.0
GeForce GT 735M 3.0
GeForce GT 635M 2.1
GeForce GT 730M 3.0
GeForce GT 630M 2.1
GeForce GT 625M 2.1
GeForce GT 720M 2.1
GeForce GT 620M 2.1
GeForce 710M 2.1
GeForce 705M 2.1
GeForce 610M 2.1
GeForce GTX 580M 2.1
GeForce GTX 570M 2.1
GeForce GTX 560M 2.1
GeForce GT 555M 2.1
GeForce GT 550M 2.1
GeForce GT 540M 2.1
GeForce GT 525M 2.1
GeForce GT 520MX 2.1
GeForce GT 520M 2.1
GeForce GTX 485M 2.1
GeForce GTX 470M 2.1
GeForce GTX 460M 2.1
GeForce GT 445M 2.1
GeForce GT 435M 2.1
GeForce GT 420M 2.1
GeForce GT 415M 2.1
GeForce GTX 480M 2.0
GeForce 710M 2.1
GeForce 410M 2.1
 

ubuntu16的可以直接设置---软件更新---附加驱动,然后选择相适应的驱动。

我的是ubuntu18,我直接在终端里安装的。

(键盘上按下 ctrl + alt + F1,进入命令行模式。ubuntu有命令行模式和X桌面模式,安装驱动必须在命令行模式进行。

禁用X桌面服务,命令行输入:sudo service lightdm stop,此命令将关闭桌面服务,现在已经不能进入桌面模式(重启电脑会重启桌面服务),重启X桌面服务,命令行输入:sudo service lightdm start)。

添加ppa库,通过ppa安装显卡驱动,注意不要从NVIDIA官网下载显卡驱动,直接通过ppa安装即可:

  1. sudo add-apt-repository ppa:graphics-drivers/ppa

  2. sudo apt-get update

  3. sudo apt-get install nvidia-384(添加完这句后可以在软件更新--附加驱动,自动搜索相应的显卡的驱动)

  4. 卸载的话:sudo apt-get --purge remove  nvidia-384

  5. 或者:

    sudo apt-get autoremove --purge nvidia-*

在终端中输入nvidia-smi,若有输出则证明驱动安装成功,若无输出则证明安装失败。

3.安装cuda9.0

降级GCC 
重启之后了,接下来的工作也都能够在图形界面下面完成。驱动安装好之后,就应该安装CUDA了,但是安装CUDA9.0最高支持的版本只到GCC6.0,那么接下来的工作是给GCC降级,我们这里推荐降级到GCC5.5. 很简单,依次输入两行命令就行了。(这两个命令就是分别来安装gcc和g++就不用我啰嗦了)

sudo apt install gcc-5 
sudo apt install g++-5

设置gcc的默认版本

设置之前可以先输入命令ls /usr/bin/gcc* 查看gcc5版本是否安装成功.

然后输入下面的命令设置默认版本:

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 100

最后的数字为优先级(越大越高),因为只有一个4.8版本作为alternatives,可以不要纠结数字,这样设就行了

然后可以输入以下命令查看设置结果(非必须)

sudo update-alternatives --config gcc

最后再次输入命令gcc -version查看gcc的版本已经变成5啦...就成功啦.

g++ 等其他软件也是这样设置进行版本升级/降级.

安装cuda

到这里,你已经安装成功CUDA了,最后,还要多配置一下环境变量: 
sudo vim ~/.bashrc 来编辑.bashrc配置文件,到文件最后,写入下面几句话(直接复制就行)

export  PATH=/usr/local/cuda-9.0/bin:$PATH
export  LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64$LD_LIBRARY_PATH
好了,重启一下。 
现在你已经重启了机子了,要是没有出现很多人遇到的在登录界面进不去的情况的话,就恭喜你了。来个自带的例子测一下。

cd /usr/local/cuda-8.0/samples/1_Utilities/deviceQuery 
sudo make 
./deviceQuery
出现了下面的你的GPU的一些信息的话,就是真的安装成功了。 

卸载cuda:

sudo /usr/local/cuda-10.0/bin/uninstall*****pl(一个文件)

4.安装cudnn

https://docs.nvidia.com/deeplearning/sdk/cudnn-install/index.html#install-linux

下载相应的cudnn

https://developer.nvidia.com/rdp/cudnn-download

2.3.1. Installing from a Tar File

  1. Navigate to your <cudnnpath> directory containing the cuDNN Tar file.
  2. Unzip the cuDNN package.
    $ tar -xzvf cudnn-9.0-linux-x64-v7.tgz
  3. Copy the following files into the CUDA Toolkit directory, and change the file permissions.
    $ 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 /usr/local/cuda/lib64/libcudnn*

2.3.2. Installing from a Debian File

  1. Navigate to your <cudnnpath> directory containing cuDNN Debian file.
  2. Install the runtime library, for example:
    sudo dpkg -i libcudnn7_7.0.3.11-1+cuda9.0_amd64.deb
  3. Install the developer library, for example:
    sudo dpkg -i libcudnn7-devel_7.0.3.11-1+cuda9.0_amd64.deb
  4. Install the code samples and the cuDNN Library User Guide, for example:
    sudo dpkg -i libcudnn7-doc_7.0.3.11-1+cuda9.0_amd64.deb

2.4. Verifying

To verify that cuDNN is installed and is running properly, compile the mnistCUDNN sample located in the /usr/src/cudnn_samples_v7 directory in the debian file.

  1. Copy the cuDNN sample to a writable path.
    $cp -r /usr/src/cudnn_samples_v7/ $HOME
  2. Go to the writable path.
    $ cd  $HOME/cudnn_samples_v7/mnistCUDNN
  3. Compile the mnistCUDNN sample.
    $make clean && make
  4. Run the mnistCUDNN sample.
    $ ./mnistCUDNN
    If cuDNN is properly installed and running on your Linux system, you will see a message similar to the following:
    Test passed!

查看cudnn的版本:

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

5.安装tf

sudo apt install python3-pip

pip3 install tensorflow-gpu

报错:

import tensorflow 出现 python3: Relink ‘/lib/x86_64-linux-gnu/libudev.so.1’ with '/lib/x86_64-linux-gnu/librt.so.1' for IFUNC symbol 'clock_gettime'

直接显示 Segmentation fault (core dumped) 退出python3

解决方法是:
sudo ln -sf /lib/x86_64-linux-gnu/libudev.so.0 /lib/x86_64-linux-gnu/libudev.so.1

 

  • 0
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

向阳+

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值