Ubuntu16.04下CUDA的安裝和卸載

1.下載 cuda.xxx.run 文件

https://developer.nvidia.com/cuda-downloads,下載 cuda_9.1.85_387.26_linux.run文件



2.在終端運(yùn)行該條指令即可:

$ sudo sh cuda_9.1.85_387.26_linux.run --no-opengl-libs

之后是一些提示信息,ctrl+c 直接結(jié)束后輸入 accept。
接下來(lái)很重要的地方是在提示是否安裝顯卡驅(qū)動(dòng)時(shí),一定選擇 no(之前安裝過(guò)對(duì)應(yīng)顯卡版本的驅(qū)動(dòng))
其他各項(xiàng)提示選擇是,并默認(rèn)安裝路徑即可。提示有 y 的輸入 y,沒(méi)有則按 enter 鍵。安裝完畢。
之后聲明一下環(huán)境變量,并將其寫(xiě)入到 ~/.bashrc 文件(在用戶目錄下)的尾部,輸入內(nèi)容如下

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

保存退出,并輸入下面指令使環(huán)境變量立刻生效:

$source ~/.bashrc




3.設(shè)置環(huán)境變量和動(dòng)態(tài)鏈接庫(kù),在命令行輸入:

$sudo vim /etc/profile

在打開(kāi)的文件末尾加入:

export PATH=/usr/local/cuda/bin:$PATH




4.創(chuàng)建鏈接文件

$ sudo vim /etc/ld.so.conf.d/cuda.conf

在打開(kāi)的文件中添加如下語(yǔ)句:

/usr/local/cuda/lib64

保存退出,然后執(zhí)行

$ sudo ldconfig 

使鏈接立即生效。




5.測(cè)試 cuda 的 Samples

切換到 CUDA 9.1 Samples 默認(rèn)安裝路徑(即在/home/用戶/ NVIDIA_CUDA-9.1_Samples 目錄下), 終端下輸入

$ cd NVIDIA_CUDA-9.1_Samples
$ sudo make all –j8
$ cd bin/x86_64/linux/release
$ ./deviceQuery

報(bào)錯(cuò)

$ ./deviceQuery
./deviceQuery Starting...

 CUDA Device Query (Runtime API) version (CUDART static linking)

cudaGetDeviceCount returned 30
-> unknown error
Result = FAIL

查看顯卡是否安裝

$ nvidia-smi
NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running.

發(fā)現(xiàn)顯卡驅(qū)動(dòng)沒(méi)有安裝成功
而且nouveau禁用失敗

$ lsmod | grep nouveau
nouveau              1601536  1
mxm_wmi                16384  1 nouveau
ttm                    98304  1 nouveau
i2c_algo_bit           16384  2 nouveau,i915
drm_kms_helper        151552  2 nouveau,i915
drm                   352256  14 nouveau,i915,ttm,drm_kms_helper
wmi                    16384  2 mxm_wmi,nouveau
video                  40960  3 thinkpad_acpi,nouveau,i915

這是需要重新禁用nouveau和安裝顯卡驅(qū)動(dòng)

如果 CUDA 安裝成功,則有:

$ ./deviceQuery
./deviceQuery Starting...

 CUDA Device Query (Runtime API) version (CUDART static linking)

Detected 1 CUDA Capable device(s)

Device 0: "GeForce GT 635M"
  CUDA Driver Version / Runtime Version          9.0 / 8.0
  CUDA Capability Major/Minor version number:    2.1
  Total amount of global memory:                 1985 MBytes (2081619968 bytes)
  ( 2) Multiprocessors, ( 48) CUDA Cores/MP:     96 CUDA Cores
  GPU Max Clock rate:                            950 MHz (0.95 GHz)
  Memory Clock rate:                             900 Mhz
  Memory Bus Width:                              128-bit
  L2 Cache Size:                                 131072 bytes
  Maximum Texture Dimension Size (x,y,z)         1D=(65536), 2D=(65536, 65535), 3D=(2048, 2048, 2048)
  Maximum Layered 1D Texture Size, (num) layers  1D=(16384), 2048 layers
  Maximum Layered 2D Texture Size, (num) layers  2D=(16384, 16384), 2048 layers
  Total amount of constant memory:               65536 bytes
  Total amount of shared memory per block:       49152 bytes
  Total number of registers available per block: 32768
  Warp size:                                     32
  Maximum number of threads per multiprocessor:  1536
  Maximum number of threads per block:           1024
  Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
  Max dimension size of a grid size    (x,y,z): (65535, 65535, 65535)
  Maximum memory pitch:                          2147483647 bytes
  Texture alignment:                             512 bytes
  Concurrent copy and kernel execution:          Yes with 1 copy engine(s)
  Run time limit on kernels:                     No
  Integrated GPU sharing Host Memory:            No
  Support host page-locked memory mapping:       Yes
  Alignment requirement for Surfaces:            Yes
  Device has ECC support:                        Disabled
  Device supports Unified Addressing (UVA):      Yes
  Device PCI Domain ID / Bus ID / location ID:   0 / 1 / 0
  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 GT 635M
Result = PASS


6.卸載CUDA

在/usr/local/cuda/bin 目錄下,有cuda 自帶的卸載工具uninstall_cuda_9.1.pl

$ cd /usr/local/cuda/bin
$ sudo ./uninstall_cuda_9.1.pl




7.其他問(wèn)題



查看NVIDIA GPU版本信息

$ lspci | grep -i nvidia

01:00.0 VGA compatible controller: NVIDIA Corporation GF108M [GeForce GT 635M] (rev a1)

驗(yàn)證自己的Linux版本是否支持 CUDA

$ uname -m && cat /etc/*release
x86_64
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.3 LTS"
NAME="Ubuntu"
VERSION="16.04.3 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.3 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial

查看正在運(yùn)行的系統(tǒng)內(nèi)核版本:

 $  uname –r
4.10.0-28-generic

安裝對(duì)應(yīng)kernel版本的kernel header和package development

sudo apt-get install linux-headers-$(uname -r)

查看是否禁用了 nouveau驅(qū)動(dòng)

lsmod | grep nouveau

如果有輸出則代表nouveau正在加載。需要我們手動(dòng)禁nouveau,Ubuntu的nouveau禁用方法前面提到過(guò)

參看鏈接:
http://blog.csdn.net/qlulibin/article/details/78714596

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容