环境描述
Ubuntu16.04 + NVIDIA Getforce 940MX (Thinkpad) + Cuda8.0
问题描述
黑屏,蓝屏,发生各种错误,然后为了解决这些错误,引入了更多的错误,重装系统;再黑屏,在蓝屏,再错误,再重装系统。
本文目的
细节网上很多,本文主要想把细节串起来,恢复解决问题的完整逻辑脉络,即:1.安装NVIDIA驱动,验证;2.安装CUDA,验证;
具体步骤
1.安装nvidia驱动:建议驱动在ubuntu tty1模式下安装(thinkpad fn+control+alt+f1进入tty1模式;并关闭intel显卡驱动,~$ sudo service lightdm stop,其他博客的添加blacklist黑名单下载源的工作逻辑上也是在这一步进行的;然后,安装nvidia显卡驱动;最后,安装成功之后再打开~$ sudo service lightdm start,fn+control+alt+f7退出tty1模式)。当然,nvidia显卡驱动选择离线安装NVIDIA驱动,注意:搜索相关的策略(哪些选项yes哪些no);也可以离线安装。
2.验证nvidia驱动安装成功:在ubuntu的“search your computer”中能直接找到”nvidia”的logo。如图:
3.验证nvidia驱动正在使用:在ubuntu的“search your computer”的“Additional Drivers”中,看到当前使用的显卡驱动是nvidia的,而非intel的集成显卡驱动,如图,(如果不能使用,一般是没有进入 “insecure mode”)
4.安装cuda8.0:建议选择离线安装cuda8.0,选项选择(先不要选择drivers,Opengl 和 X drivers !):
Description
This package includes over 100+ CUDA examples that demonstrate
various CUDA programming principles, and efficient CUDA
implementation of algorithms in specific application domains.
The NVIDIA CUDA Samples License Agreement is available in
Do you accept the previously read EULA?
accept/decline/quit: accept
Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 367.48?
(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/ ]:
Installing the CUDA Toolkit in /usr/local/cuda-8.0 ...
Installing the CUDA Samples in /home/ ...
Copying samples to /home/c302/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
5.验证CUDA是否成功:
添加系统变量:
sudo vi /etc/profile
写入:
export PATH=/usr/local/cuda-8.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64:$LD_LIBRARY_PATH
重启ubuntu
~$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2016 NVIDIA Corporation
Built on Sun_Sep__4_22:14:01_CDT_2016
Cuda compilation tools, release 8.0, V8.0.44
cd ‘/home/xxxx/NVIDIA_CUDA-8.0_Samples’
编译cuda samples
~$ make
测试cuda samples
cd 0_Simple/matrixMul
./matrixMul
测试成功,如图: