1. 程式人生 > >nvidia cuda工具包更新9.0版本記錄

nvidia cuda工具包更新9.0版本記錄

因工作需要,對公司2臺伺服器升級cuda到9.0版本。本文記錄其過程。

介紹

cuda在nvidia官方網站有下載,最新版本為9.2,但公司採用的tensorflow只使用9.0,為了版本的相容,決定還是選用9.0版本。官網預設使用最新版本,舊版本位於:https://developer.nvidia.com/cuda-toolkit-archive。9.0版本地址:https://developer.nvidia.com/cuda-90-download-archive。提供Windows、Linux和MacOS三大平臺安裝包。而Linux平臺支援CentOS、Ubuntu、Fedora、RHEL等等主流發行版本。Ubuntu只支援16.04和17.04版本。本文采用16.04版本。一共需要下載5個檔案,一個安裝包cuda_9.0.176_384.81_linux.run,四個補丁包,名稱為cuda_9.0.176.X_linux.run,其中X為1~4。

下載

cuda包下載比較麻煩,去年曾經安裝過,在md5問題上卡了很久,各種下載工具都嘗試過,但md5都不正確,所以安裝失敗。還是託在深圳工作的前同事幫忙下載,再傳回來的。現在認識到docker,就使用docker來做中轉。
下載docker:

$ docker pull latelee/cuda:tar-9.0

9.0安裝包位於容器根目錄下。

$ docker run -it -v /home:/home --rm latelee/cuda:tar-9.0 bash
[email protected]98dfc8d4f016:/# ls
bin                       cuda_9.0
.176.2_linux.run cuda_9.0.176_384.81_linux.run home media proc sbin tmp boot cuda_9.0.176.3_linux.run dev lib mnt root srv usr cuda_9.0.176.1_linux.run cuda_9.0.176.4_linux.run etc lib64 opt run sys var

然後將.run檔案拷貝到宿主機目錄中。

安裝

在安裝前,先檢視核心:

uname -a
Linux localhost 4.13.0-38-generic #43~16.04.1-Ubuntu SMP Wed Mar 14 17:48:43 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

再檢視nvidia顯示卡驅動版本:

$ nvidia-smi
Thu Sep 13 09:56:26 2018       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 384.130                Driver Version: 384.130                   |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce GTX 1070    Off  | 00000000:01:00.0 Off |                  N/A |
| 79%   82C    P2   131W / 200W |   2865MiB /  8112MiB |    100%      Default |
+-------------------------------+----------------------+----------------------+

上面表明驅動是正常的,由於已經安裝了驅動,在安裝cuda時就不需要再安裝了。
先解除安裝舊版本:
···
cd /usr/local/cuda-8.0/bin
sudo ./uninstall_cuda_8.0.pl
···
再進行安裝:

sudo ./cuda_9.0.176_384.81_linux.run

首先顯示協議,按q退出。下面根據步驟來安裝,如下所示(各步驟給出說明):

Do you accept the previously read EULA?
accept/decline/quit: accept  # 輸入accept表示同意協議

Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 384.81?
(y)es/(n)o/(q)uit: n # 輸入n不安裝nvidia驅動,因為已經安裝過了。

Install the CUDA 9.0 Toolkit?
(y)es/(n)o/(q)uit: y # 輸入y安裝cuda工具包

Enter Toolkit Location
[ default is /usr/local/cuda-9.0 ]: # 直接回車即可,使用預設目錄

Do you want to install a symbolic link at /usr/local/cuda?
(y)es/(n)o/(q)uit: y # 輸入y,安裝連結目錄

Install the CUDA 9.0 Samples?
(y)es/(n)o/(q)uit: y # 輸入y安裝示例

Enter CUDA Samples Location
[ default is /home/latelee ]: # 使用預設目錄,直接回車

Installing the CUDA Toolkit in /usr/local/cuda-9.0 ...
Missing recommended library: libGLU.so
Missing recommended library: libX11.so
Missing recommended library: libXi.so
Missing recommended library: libXmu.so

Installing the CUDA Samples in /home/latelee ...
Copying samples to /home/latelee/NVIDIA_CUDA-9.0_Samples now...
Finished copying samples.

===========
= Summary =
===========

Driver:   Not Selected  # 由於沒選擇驅動,會這樣列印資訊出來
Toolkit:  Installed in /usr/local/cuda-9.0
Samples:  Installed in /home/latelee, but missing recommended libraries

# 設定PATH和庫目錄
Please make sure that
-   PATH includes /usr/local/cuda-9.0/bin
-   LD_LIBRARY_PATH includes /usr/local/cuda-9.0/lib64, or, add /usr/local/cuda-9.0/lib64 to /etc/ld.so.conf and run ldconfig as root

To uninstall the CUDA Toolkit, run the uninstall script in /usr/local/cuda-9.0/bin

Please see CUDA_Installation_Guide_Linux.pdf in /usr/local/cuda-9.0/doc/pdf for detailed information on setting up CUDA.

***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 384.00 is required for CUDA 9.0 functionality to work.
To install the driver using this installer, run the following command, replacing <CudaInstaller> with the name of this run file:
    sudo <CudaInstaller>.run -silent -driver

Logfile is /tmp/cuda_install_5468.log

補丁

下面安裝補丁檔案:

sudo ./cuda_9.0.176.1_linux.run
sudo ./cuda_9.0.176.2_linux.run
sudo ./cuda_9.0.176.3_linux.run
sudo ./cuda_9.0.176.4_linux.run

按q退出協議,輸入accept,再直接回車即可,每個一補丁都如此。

環境變數

由於本文是升級,而且,安裝目錄做了連結,所以無須任何修改即可。如果是首次安裝,則要設定環境變數,——正如上面提示資訊所述那樣。設定環境變數有很多種方式,這裡只提一種,由於是伺服器,所以最好是全域性設定,所有開發人員都能使用。開啟/etc/profile檔案,在最後新增:

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

重新登陸,可執行source /etc/profile,均可生效。

驗證

檢視nvcc編譯器版本以確認cuda版本:

$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Sep__1_21:08:03_CDT_2017
Cuda compilation tools, release 9.0, V9.0.176

最後一行表示cuda已經是9.0了。接著編譯並執行示例程式碼,進入相應示例程式碼目錄:

$ cd /home/latelee/NVIDIA_CUDA-9.0_Samples/1_Utilities/deviceQuery

編譯並執行:

$ make -j
$ ./deviceQuery

輸出資訊如下:

./deviceQuery Starting...

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

Detected 1 CUDA Capable device(s)

Device 0: "GeForce GTX 1070"
  CUDA Driver Version / Runtime Version          9.0 / 9.0
  CUDA Capability Major/Minor version number:    6.1
  Total amount of global memory:                 8113 MBytes (8506769408 bytes)
  (15) Multiprocessors, (128) CUDA Cores/MP:     1920 CUDA Cores
  GPU Max Clock rate:                            1709 MHz (1.71 GHz)
  Memory Clock rate:                             4004 Mhz
  Memory Bus Width:                              256-bit
  L2 Cache Size:                                 2097152 bytes
  Maximum Texture Dimension Size (x,y,z)         1D=(131072), 2D=(131072, 65536), 3D=(16384, 16384, 16384)
  Maximum Layered 1D Texture Size, (num) layers  1D=(32768), 2048 layers
  Maximum Layered 2D Texture Size, (num) layers  2D=(32768, 32768), 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: 65536
  Warp size:                                     32
  Maximum number of threads per multiprocessor:  2048
  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): (2147483647, 65535, 65535)
  Maximum memory pitch:                          2147483647 bytes
  Texture alignment:                             512 bytes
  Concurrent copy and kernel execution:          Yes with 2 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
  Supports Cooperative Kernel Launch:            Yes
  Supports MultiDevice Co-op Kernel Launch:      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 = 9.0, NumDevs = 1
Result = PASS

最後的PASS表示程式測試通過。

小結

如果已經安裝過nvidia顯示卡驅動,在安裝cuda時就不能選擇安裝驅動,否則,因為驅動已經被載入,無法安裝成功。需要先解除安裝,但制裁重新安裝比較麻煩,考慮到年代較近(去年年底才安裝),因為就不升級驅動了。

李遲 2018.9.14 週五 夜