1 引言
因为笔记本电脑上运行Milvus图像检索代码,需要安装CUDA驱动。电脑显卡型号是NVIDIA GeForce GTX 1050 Ti Mobile, 操作系统是Ubuntu 20.04,内核版本为Linux 5.15.0-72-generic。
2 CUDA驱动测试
参考网上的资料:https://blog.csdn.net/wjinjie/article/details/108997692,首先进行显示环境检查。使用nvidia-smi命令检测显卡驱动是否正常工作。如果命令提示出错信息,无法输出CUDA相关信息,则说明CUDA无法正常工作,接下来检查NVDIA显卡驱动。
使用nvcc -V检查cuda驱动,相关版本信息输出如下:
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Thu_Nov_18_09:45:30_PST_2021
Cuda compilation tools, release 11.5, V11.5.119
Build cuda_11.5.r11.5/compiler.30672275_0
这说明CUDA驱动本身没有问题,接下来检查显卡nvidia driver版本。
3 NVIDIA驱动测试
输入如下命令
ls /usr/src | grep nvidia
,本地电脑输出信息如下:
nvidia-530.41.03
这说明本地显卡驱动已经安装。如果未输出显卡驱动信息,说明显示驱动也要重新安装。可以通过如下命令查看版本信息:
xxx@xxx:~$ ubuntu-drivers devices
== /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0 ==
modalias : pci:v000010DEd00001C8Csv00001028sd0000086Fbc03sc02i00
vendor : NVIDIA Corporation
model : GP107M [GeForce GTX 1050 Ti Mobile]
driver : nvidia-driver-525 - distro non-free
driver : nvidia-driver-525-server - distro non-free
driver : nvidia-driver-530 - distro non-free recommended
driver : nvidia-driver-390 - distro non-free
driver : nvidia-driver-510 - distro non-free
driver : nvidia-driver-450-server - distro non-free
driver : nvidia-driver-515-server - distro non-free
driver : nvidia-driver-418-server - distro non-free
driver : nvidia-driver-470-server - distro non-free
driver : nvidia-driver-515 - distro non-free
driver : nvidia-driver-470 - distro non-free
driver : xserver-xorg-video-nouveau - distro free builtin
其中标识有recommended字样的驱动是系统推荐驱动,直接运行
sudo ubuntu-drivers autoinstall
即可安装,详细信息也可参见网上资料:https://www.jianshu.com/p/e562752cdbee。这个步骤可以从Ubuntu桌面系统中自带的附加驱动界面中进行安装:
4 DKMS测试
安装完成nvidia驱动之后,接下来就要安装dkms相关组件:
sudo apt-get install dkms
sudo dkms install -m nvidia -v 530.41.03
安装完成之后,重启电脑,发现Ubuntu显示黑屏,无法进行桌面系统,查看网上的资料:https://forums.developer.nvidia.com/t/black-screen-after-install-of-nvidia-driver-ubuntu/109312/68?page=6,其中提到:
Please remove the ‘nomodeset’ kernel parameter and reboot.
试了一下,果然解决了问题,顺利进行桌面系统。再来运行nvidia-smi命令,成功输出相关信息:
Tue May 9 13:42:45 2023
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 530.41.03 Driver Version: 530.41.03 CUDA Version: 12.1 |
|-----------------------------------------+----------------------+----------------------+
| 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 NVIDIA GeForce GTX 1050 Ti Off| 00000000:01:00.0 Off | N/A |
| N/A 45C P8 N/A / N/A| 6MiB / 4096MiB | 0% Default |
| | | N/A |
+-----------------------------------------+----------------------+----------------------+
+---------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=======================================================================================|
| 0 N/A N/A 2143 G /usr/lib/xorg/Xorg 4MiB |
+---------------------------------------------------------------------------------------+
至此,CUDA功能顺利启用。