Ubuntu GPU配置+tensorflow安装:cuda8.0 cuDNN6.0 tensorflow-gpu1.4.0

一定不要tensorflow-gpu和tensorflow(cpu版)一起装,因为这样装有个先后顺序问题,先安装tensorflow-gpu再安装tensorflow,gpu版本直接不能用了???

我是自带的3.5装tensorflow-gpu,且主要用它做实验
anaconda的3.6不怎么用,试验着用,cpu版本tensorflow不在里面装了,别瞎搞,吃得太饱了!!!

0.NVIDIA显卡驱动安装

lspci | grep -i nvidia
08:00.0 3D controller: NVIDIA Corporation GM108M [GeForce 840M] (rev a2)

GeForce 840M是NVIDIA的一款显卡,于2014年3月推出。该显卡采用28纳米制程,基于GM108图形处理器,采用N15S-GT版本,支持DirectX 12.0。它具有384个着色单元,16个纹理映射单元和8个ROP。

NVIDIA已经在卡上放置了2,048 MB DDR3内存,它们使用64位内存接口连接。GPU的工作频率为1029 MHz,可升至1124 MHz,内存运行速度为1001 MHz。

作为igp卡,其功耗最高为33 W. 此设备没有显示连接,因为它没有设计为连接监视器。GeForce 840M使用PCI-Express 3.0 x8接口连接到系统的其余部分。

参考https://blog.csdn.net/Knight_vae/article/details/102009020

第一步在设置中的附加驱动直接选择nvidia-384(专有,test),我的是这样,重启电脑。

输入 lsmod | grep nouveau,没有任何输出说明禁用成功。

使用标准Ubuntu仓库进行自动化安装(最简单,最推荐)

shen@ubuntu:~$ lsmod | grep nouveau

首先,检测你的NVIDIA显卡型号和推荐的驱动程序的模型。

shen@ubuntu:~$ ubuntu-drivers devices 
== /sys/devices/pci0000:00/0000:00:1c.4/0000:08:00.0 ==
modalias : pci:v000010DEd00001341sv00001028sd00000656bc03sc02i00
model    : GM108M [GeForce 840M]
vendor   : NVIDIA Corporation
driver   : nvidia-384 - distro non-free recommended
driver   : xserver-xorg-video-nouveau - distro free builtin
driver   : nvidia-340 - distro non-free

nvidia-384 - distro non-free recommended,应该本来就有?nvidia-smi查看驱动是否安装成功,sudo nvidia-settings查看可视化界面设置。

shen@ubuntu:~$ sudo ubuntu-drivers autoinstall
[sudo] shen 的密码: 
正在读取软件包列表... 完成
正在分析软件包的依赖关系树       
正在读取状态信息... 完成       
升级了 0 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 85 个软件包未被升级。
shen@ubuntu:~$ nvidia-smi
Sun Apr  4 17:10:06 2021       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 384.130                Driver Version: 384.130                   |
|-------------------------------+----------------------+----------------------+
| 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 840M        Off  | 00000000:08:00.0 Off |                  N/A |
| N/A   46C    P8    N/A /  N/A |    153MiB /  2002MiB |      5%      Default |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0      1497      G   /usr/lib/xorg/Xorg                            66MiB |
|    0      3310      G   compiz                                        24MiB |
|    0      3448      G   fcitx-qimpanel                                 3MiB |
|    0      3716      G   ...AAgAAAAAAAAACAAAAAAAAAA= --shared-files    57MiB |
+-----------------------------------------------------------------------------+

1.cuda了解

支持 CUDA 的 GeForce 和 TITAN 产品

[GeForce 840M] 运算能力5.0

nvidia-384 - distro non-free recommended,Driver Version: 384.130

CUDA对应的NVIDIA驱动版本对照表

CUDA Toolkit           | Linux x86_64 Driver Version    Windows x86_64 Driver Version
CUDA 11.2.2 Update 2    >=460.32.03 >=461.33
......
CUDA 9.1 (9.1.85)   >= 390.46   >= 391.29-----------not
CUDA 9.0 (9.0.76)   >= 384.81   >= 385.54------------not
CUDA 8.0 (8.0.61 GA2)   >= 375.26   >= 376.51----ok
CUDA 8.0 (8.0.44)   >= 367.48   >= 369.30-----------
CUDA 7.5 (7.5.16)   >= 352.31   >= 353.66
CUDA 7.0 (7.0.28)   >= 346.46   >= 347.62

CUDA版本和cuDNN版本,总的来说,想要兼容CUDA8,就需要较低版本的cuDNN,

CUDA版本较低必定安装不了,即tensorflow 1.4及以下的不支持cuda9.0,且tensorflow1.0版本以上是不支持cuda8.0以下。tensorflow-gpu1.5开始不支持使用CUDA8.0,而cuda8.0对应的cuDNN必须是6.0+。
而CUDA版本较高,如tf1.13.1使用CUDA10.1也会报错。也就是说强烈推荐tf1.5安装CUDA9.0(别9.x),而CUDA9.0又必须需要cuDNN7+。

————但我只能装cuda8: CUDA 8.0 (8.0.61 GA2) >= 375.26

安装

注意:安装之前一定要先把CUDA和cuDNN的版本搞清楚了,因为CUDA与cuDNN的版本必须要和Tensorflow的版本对应上
参照资料,选择的版本是Tensorflow1.4,cuda8.0,cudnn6.0。


image

CUDA Toolkit 8.0 - Feb 2017
注意:下载runfile(local)文件,ubuntu 16.04 x86_64

下载完成以后,找到CUDA8.0所在位置(我的是放在home目录下),终端输入:.

sudo chmod +x cuda_8.0.61_375.26_linux.run
sudo ./cuda_8.0.61_375.26_linux.run

安装过程中会有几个选项需要确认,注意:不要安装cuda自带的显卡驱动,其他的直接选y,路径输入默认值即可

Do you accept the previously read EULA?
accept/decline/quit: accept

Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 375.26?
(y)es/(n)o/(q)uit: n

Install the CUDA 8.0 Toolkit?
(y)es/(n)o/(q)uit: y

Enter Toolkit Location
 [ default is /usr/local/cuda-8.0 ]: 

Do you want to install a symbolic link at /usr/local/cuda?
(y)es/(n)o/(q)uit: y

Install the CUDA 8.0 Samples?
(y)es/(n)o/(q)uit: y

Enter CUDA Samples Location
 [ default is /home/shen ]: 

Installing the CUDA Toolkit in /usr/local/cuda-8.0 ...
Missing recommended library: libXmu.so

Installing the CUDA Samples in /home/shen ...
Copying samples to /home/shen/NVIDIA_CUDA-8.0_Samples now...
Finished copying samples.

===========
= Summary =
===========

Driver:   Not Selected
Toolkit:  Installed in /usr/local/cuda-8.0
Samples:  Installed in /home/shen, but missing recommended libraries

Please make sure that
 -   PATH includes /usr/local/cuda-8.0/bin
 -   LD_LIBRARY_PATH includes /usr/local/cuda-8.0/lib64, or, add /usr/local/cuda-8.0/lib64 to /etc/ld.so.conf and run ldconfig as root

To uninstall the CUDA Toolkit, run the uninstall script in /usr/local/cuda-8.0/bin

Please see CUDA_Installation_Guide_Linux.pdf in /usr/local/cuda-8.0/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 361.00 is required for CUDA 8.0 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_15256.log

配置环境

安装完成以后,需要把cuda路径添加到当前用户的配置文件里:

     sudo gedit ~/.bashrc
 

将安装路径添加到文件末尾:

     export PATH=/usr/local/cuda-8.0/bin:$PATH
     export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64:$LD_LIBRARY_PATH

然后执行如下命令使路径生效:

       . ~/.bashrc

验证

shen@ubuntu:~/Desktop$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2016 NVIDIA Corporation
Built on Tue_Jan_10_13:22:03_CST_2017
Cuda compilation tools, release 8.0, V8.0.61

接着尝试运行一下cuda中自带的例子:

cd /usr/local/cuda-8.0/samples/1_Utilities/deviceQuery
sudo make
./deviceQuery
可以看到输出成功
  .........
  Compute Mode:
 < Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >

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

2. cuDNN: 官网下载cuda对应版本的cudnn

注意:下载cuDNN v6.0 Library for Linux

下载完成以后将其解压,在目录中依次执行如下命令(我没解压到cuda8.0目录):

tar -xzvf cudnn-8.0-linux-x64-v6.0.tgz
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*

3. tensorflow官网有指导

pip安装

sudo apt-get install python3-pip python3-dev
sudo pip install tensorflow-gpu==1.4.0

卸载方法

sudo pip uninstall tensorflow # for Python 3.n

!!!anaconda python tensorflow cuda cudnn对应版本很重要

tensorflow要求python3.3-3.6 。自带3.5,装个Anaconda3-5.2.0(python 3.6.5)(啊啊啊其实如果可能也没必要!!!)

https://blog.csdn.net/littlehaes/article/details/100575694
https://blog.csdn.net/yuejisuo1948/article/details/81043823

anaconda:https://repo.anaconda.com/archive/

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容