GPU驱动安装,CUDA安装相关问题

一、GPU驱动相关

  • 安装新驱动

新装系统或出现以下提示可以重新安装驱动

Failed to initialize NVML Driver library version mismatch

先卸载旧驱动

sudo /usr/bin/nvidia-uninstall

sudo apt-get --purge remove nvidia-*

sudo apt-get purge nvidia*

sudo apt-get purge libnvidia*

查看是否卸载干净

sudo dpkg --list | grep nvidia-*
如果还有关于nvidia的则用
sudo apt-get remove --purge 文件名

卸载过程出现

If you plan to no longer use the NVIDIA driver, you should make sure that no

X screens are configured to use the NVIDIA X driver in your X configuration

file. If you used nvidia-xconfig to configure X, it may have created a

backup of your original configuration. Would you like to run `nvidia-xconfig

--restore-original-backup` to attempt restoration of the original X

configuration file?

选NO

 禁用nouveau驱动

Nouveau是由第三方为NVIDIA显卡开发的一个开源3D驱动,为了让用户安装完系统即可进入桌面,因此很多Linux发行版默认集成了Nouveau驱动。但是Nouveau驱动会影响安装NVIDIA官方驱动,因此在安装前要先禁用Nouveau驱动。
sudo gedit /etc/modprobe.d/blacklist.conf
在文本后添加
blacklist nouveau
重启机器

 开始安装

下载链接 

https://www.nvidia.cn/Download/index.aspx

$ sudo sh NVIDIA-Linux-x86_64-440.44.run -no-x-check -no-nouveau-check -no-opengl-files

 安装过程的选择

1. There appears to already be a driver installed on your system (version:      
  390.42).  As part of installing this driver (version: 390.42), the existing  
  driver will be uninstalled.  Are you sure you want to continue?

                 Continue installation      Abort installation 

(选择 Coninue,如果是重装的话)
2. The distribution-provided pre-install script failed!  Are you sure you want
  to continue?                                                                 
       
                 Continue installation      Abort installation       
(选择 Cotinue)
3. Would you like to register the kernel module sources with DKMS? This will    
  allow DKMS to automatically build a new module, if you install a different   
  kernel later.

                          Yes                       No  
(这里选 No)
4. Install NVIDIA's 32-bit compatibility libraries?
                                                                               
                          Yes                       No  
(这里选 No)
5、Would you like to run the nvidia-xconfig utility to automatically update your x configuration so that the NVIDIA x driver will be used when you restart x? Any pre-existing x confile will be backed up.
选择NO

6. Installation of the kernel module for the NVIDIA Accelerated Graphics Driver
  for Linux-x86_64 (version 390.42) is now complete.                           
                                                                       
                                       OK
  •  内核更新出现驱动问题

 NVIDIA-SMI has failed because it couldn‘t communicate with the NVIDIA driver

重启时ubuntu的内核进行了更新,更新后的内核指向的是最新的显卡驱动,导致之前安装的显卡驱动虽然在,但是新内核不知道它在。

DKMS是一个维护内核外的驱动的程序,可以在内核指向改变后自动生成新的导向模块

可以重新安装驱动适应新的内核版本,也可以以下简单方式。
查看已安装驱动的版本信息
ls  /usr/src | grep nvidia

安装dkms并执行引导,后面的驱动版本是上面查看出来的版本
sudo apt-get install dkms
sudo dkms install -m nvidia -v 470.94

 二、CUDA安装相关

CUDA下载链接 

https://developer.nvidia.com/cuda-toolkit-archive

第一行命令是下载

第二行是安装

若第1步提示Existing package manager installation of the driver found. It is strongly recommended that you remove this before continuing.,选择continue,后面会询问是不是accept,输入accept即可,但在下一步中要去除driver项,不安装GPU驱动。

CUDA 有两种API,分别是 运行时 API 和 驱动API,即所谓的 Runtime API 与 Driver API。所以nvidia-smi 中的CUDA 版本与 nvcc -V显示的版本可能不一致。nvidia-smi 显示的版本大于nvcc --version 的版本一般不会出现大问题。下面来自chatGPT4.0

  1. Runtime API:这是大多数CUDA开发人员使用的高级API。它更加简洁,对开发者友好,用于常见的任务和操作。大多数深度学习框架,如TensorFlow、PyTorch等,在进行训练时主要使用这个API。由CUDA Toolkit installer安装 。

  2. Driver API:这是一个较为底层的API,提供了更多的控制能力。使用Driver API进行开发要求开发者更加熟悉CUDA内部的工作机制。这种API主要用于那些需要特定、精细控制CUDA的应用中。由GPU driver installer安装。

  3. 对于大多数深度学习训练和应用,主要是使用Runtime API。Runtime API简化了很多CUDA的操作,使得在深度学习框架中容易进行集成。

环境变量配置

vim ~/.bashrc文件末添加:

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

上面cuda-11.3要根据自己安装的版本修改

执行source ~/.bashrc或重启终端以应用更改

nvcc -V 查看是否成功

三、cudnn安装

下载cudnn

cuDNN Archive | NVIDIA Developer

sudo tar -zxvf ./cudnn-linux-x86_64-8.9.3.28_cuda12-archive.tar

进入解压之后的include目录,在命令行进行如下操作:

sudo cp * /usr/local/cuda/include  #复制头文件

再将进入lib64目录下的动态文件进行复制和链接:

sudo cp lib* /usr/local/cuda/lib64/    #复制动态链接库

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值