環境描述
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 startfn+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

測試成功,如圖,
這裡寫圖片描述