Linuxは古いバージョンのCUDAとインストールされたドライバーをアンインストールし、新しいバージョンのCUDAとcudnnのインストールをインストールします

ディープラーニングの計算にGPU、CUDA、cuDNNを使用する波は長年続いています。この間、グラフィックカードドライバーとCUDAバージョン、およびcudnnディープラーニングツールキットのバージョンが何度も更新されています。 。新しいTensorFlowバージョン2.0とPytorchバージョン1.3のリリースに伴い、ディープラーニングに使用するマシンも、特にCUDA 8.0を使用している場合は、オペレーティング環境を最新バージョンに更新する必要があります。この記事では、古いバージョンのCUDA(バージョン8.0など)をアンインストールし、新しいバージョンのCUDA(バージョン10.0)をインストールする方法を紹介します。

材料の準備

まず、NVIDIAの公式Webサイトから従属ファイルをダウンロードする必要があります。1つはcuda10.0で、もう1つはcudnn7.4です。

  • cuda_10.0.130_410.48_linux
  • cudnn-10.0-linux-x64-v7.4.2.24.solitairetheme8
    独自のredhatシステム、ダウンロードされたcudaバージョンは次のとおりです。
    ここに画像の説明を挿入します

古いバージョンのCUDAをアンインストールします

アンインストールする前に、Xディスプレイマネージャーlightdmなどの一部の画像関連サービスを閉じる必要があります。キーボードのctrl + Alt + F1を押し、純粋なコマンドラインからアカウントとパスワードを入力してターミナルにログインし、次のコマンドを入力します。

$ sudo  systemctl stop lightdm
$ cd  /usr/local/cuda-8.0/bin
$ sudo  ./uninstall_cuda_8.0.pl

通常、cudaがインストールされている場合、次のようにインストールログを確認するように求めるプロンプトが表示されます。

RROR:NVIDIAカーネルモジュール「nvidia-uvm」がすでにカーネルにロードされているようです。これは、使用中(Xサーバー、CUDAプログラム、NVIDIA Persistence Daemonなど)が原因である可能性がありますが、モジュールのアンロードをサポートせずにカーネルが構成されている場合にも発生する可能性があります。ドライバをアップグレードする前に、GPUを使用している可能性のあるプログラムを必ず終了してください。GPUベースのプログラムが実行されていない場合、カーネルがモジュールのアンロードをサポートしていることがわかっていても、このメッセージが表示される場合は、NVIDIAカーネルモジュールの使用回数が破損しているエラーが発生している可能性があります。最も簡単な解決策は、コンピューター。
エラー:インストールに失敗しました。ファイルをご覧ください'/var/log/nvidia-installer.log'詳細については、www.nvidia.comのLinuxドライバーダウンロードページにあるREADMEでインストールの問題を修正するための提案を見つけることができます。

ただし、特定の問題が発生した場合は、Baiduで直接解決できます。それでも問題が発生する場合は、再起動してください。
解決策1:以前にcudaをインストールしたことがある場合、これは通常、古いドライバーがアンインストールされていないことが原因です。現時点では、NVIDIAドライバーのアンインストールは次のとおりです。

yum remove "*cublas*" "cuda*"
yum remove "*nvidia*"

アンインストール手順もあります。

To uninstall  the NVIDIA Driver, run nvidia-uninstall

新しいバージョンのCUDAをインストールする

ダウンロードしたcuda10ファイルとcudnn7.4ファイルを見つけ、最初に次のコマンドを入力してcuda10をインストールします。

$ sudo sh cuda_10.0.130_410.48_linux

最初に表示されるのはCUDAユーザー契約に関するものです。直接「Ctrl + C」を押しスキップし、「accpet」と入力して契約に同意することができます。

Logging to  /tmp/cuda_install_11026.log
Using more to  view the EULA.
End User  License Agreement
--------------------------
Preface
-------
The Software  License Agreement in Chapter 1 and the Supplement
in Chapter 2  contain license terms and conditions that govern
the use of  NVIDIA software. By accepting this agreement, you
agree to  comply with all the terms and conditions applicable
to the  product(s) included herein.
 
NVIDIA Driver
Description
This package  contains the operating system driver and
fundamental  system software components for NVIDIA GPUs.
 
NVIDIA CUDA  Toolkit
 
Description
 
The NVIDIA  CUDA Toolkit provides command-line and graphical
tools for  building, debugging and optimizing the performance
of applications  accelerated by NVIDIA GPUs, runtime and math
libraries,  and documentation including programming guides,
user manuals,  and API references.
 
Default  Install Location of CUDA Toolkit
 
Windows  platform:
 
%ProgramFiles%\NVIDIA  GPU Computing Toolkit\CUDA\v#.#
 
Linux  platform:
 
/usr/local/cuda-#.#
 
Mac platform:
 
/Developer/NVIDIA/CUDA-#.#
 
NVIDIA CUDA  Samples
 
Description
 
This package  includes over 100+ CUDA examples that demonstrate
various CUDA  programming principles, and efficient CUDA
implementation  of algorithms in specific application domains.
Do you accept  the previously read EULA?
accept/decline/quit:  accept

NVIDIAドライバーのバージョンを更新する必要があるため、「Linux用のNVIDIA Accelerated Graphics Driverをインストールします-x86_64410.48?」があります。新しいバージョンのドライバーをインストールするには、「y」を入力する必要があります。(これはインストールすることもインストールしないこともできます。)

Install  NVIDIA Accelerated Graphics Driver for Linux-x86_64 410.48?
(y)es/(n)o/(q)uit:  y    ( 如果电脑上有了显卡driver,可以不用安装)
Do you want  to install the OpenGL libraries?
(y)es/(n)o/(q)uit  [ default is yes ]: y
 
Do you want  to run nvidia-xconfig?
This will  update the system X configuration file so that the NVIDIA X driver
is used. The  pre-existing X configuration file will be backed up.
This option  should not be used on systems that require a custom
X  configuration, such as systems with multiple GPU vendors.
(y)es/(n)o/(q)uit  [ default is no ]:
 
Install the  CUDA 10.0 Toolkit?
(y)es/(n)o/(q)uit:  y
 
Enter Toolkit  Location
 [ default is /usr/local/cuda-10.0 ]:
 
Do you want  to install a symbolic link at /usr/local/cuda?
(y)es/(n)o/(q)uit:  y
 
Install the  CUDA 10.0 Samples?
(y)es/(n)o/(q)uit:  y  (这个也可以不用安装)
 
Enter CUDA  Samples Location
 [ default is /home/gpu ]:
 
Installing  the NVIDIA display driver...
Installing  the CUDA Toolkit in /usr/local/cuda-10.0 ...
Missing  recommended library: libGLU.so
Missing  recommended library: libXmu.so
 
Installing  the CUDA Samples in /home/gpu ...
Copying  samples to /home/gpu/NVIDIA_CUDA-10.0_Samples now...
Finished  copying samples.
 
===========
= Summary =
===========
 
Driver:   Installed   (已有驱动可以不用安装)
Toolkit:  Installed in /usr/local/cuda-10.0
Samples:  Installed in /home/gpu, but missing recommended  libraries  (也可以不用安装)
 
Please make  sure that
 -    PATH includes /usr/local/cuda-10.0/bin
 -    LD_LIBRARY_PATH includes /usr/local/cuda-10.0/lib64, or, add  /usr/local/cuda-10.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-10.0/bin
To uninstall  the NVIDIA Driver, run nvidia-uninstall
 
Please see  CUDA_Installation_Guide_Linux.pdf in /usr/local/cuda-10.0/doc/pdf for  detailed information on setting up CUDA.
 
Logfile is  /tmp/cuda_install_11026.log
Signal  caught, cleaning up

インストール後の上記のプロンプトは、環境を構成する方法を示しています。

Please make  sure that
 -    PATH includes /usr/local/cuda-10.0/bin
 -    LD_LIBRARY_PATH includes /usr/local/cuda-10.0/lib64, or, add  /usr/local/cuda-10.0/lib64 to /etc/ld.so.conf and run ldconfig as root

このタイプの出力が最終的に表示され、新しいバージョンのCUDAが正常にインストールされていても、他のエラーが発生しない場合。次に、新しい環境変数をインストールして構成する必要があります。では「〜/ .bashrcの」最終追加:

export  PATH=/usr/local/cuda/bin${PATH:+:${PATH}}
export  LD_LIBRARY_PATH=/usr/local/cuda/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
export  CUDA_HOME=/usr/local/cuda

その中で、最初の2つ(PATH、LD_LIBRARY_PATH)は、CUDA公式Webサイトのインストールドキュメントで推奨されている変数です。3番目(CUDA_HOME)は、tensorflow-GPUバージョンに必要な変数です。
環境変数を構成した後、それを更新する必要があります。そうしないと、すぐには有効になりません。コンピュータを再起動して、環境変数を有効にすることもできます。

$ source  ~/.bashrc

:上記の構成は基本的に必要です。これは、C ++で依存ライブラリを追加するのと同じで、VSにlib、bin、include、およびその他のファイルパスを追加する必要があります。その中で、/ usr / local / cudaはソフトリンクです。すでに存在する場合、新しくインストールされたcudaはそれを書き換えることができません。この時点で手動で作成できます。nvccは次のようにcudaのbinディレクトリにあります。

rm -rf /usr/local/cuda
mkdir /usr/local/cuda

sudo ln -s /usr/local/cuda-9.0/ /usr/local/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

次に、このコマンドはドライバーのインストール後にのみ実行されるため、新しいバージョンのグラフィックカードドライバーのインストールの結果を確認できます。

$ nvidia-smi
Fri Oct 27  15:46:57 2019
+-----------------------------------------------------------------------------+
| NVIDIA-SMI  410.48                 Driver Version:  410.48                    |
|-------------------------------+----------------------+----------------------+
| GPU  Name         Persistence-M| Bus-Id         Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0   Tesla P100-PCIE...  Off  | 00000000:06:00.0 Off |                    0 |
| N/A   29C     P0    24W / 250W |      0MiB / 12198MiB |      0%       Default |
+-------------------------------+----------------------+----------------------+
 
+-----------------------------------------------------------------------------+
|  Processes:                                                        GPU  Memory |
|  GPU        PID   Type   Process name                             Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+

最後に、画像表示を復元します。

$ sudo  systemctl start lightdm

cudnnライブラリを構成する

まず、解凍を容易にするためにcudnnファイルの名前を変更します。他のバージョンのファイル名は、実際の状況に応じて変更する必要があります。

$ cp cudnn-10.0-linux-x64-v7.4.2.24.solitairetheme8  cudnn-10.0-linux-x64-v7.4.2.24.tgz
$ tar zxvf cudnn-10.0-linux-x64-v7.4.2.24.tgz
$ sudo cp  cuda/include/cudnn.h /usr/local/cuda/include
$ sudo cp  cuda/lib64/libcudnn* /usr/local/cuda/lib64

**注:**ソフトリンクを作成していない場合は、インストール場所にコピーします。
次に、ファイルのアクセス許可を変更します。

$ sudo chmod  a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*

最後に、構成が完了しました。

おすすめ

転載: blog.csdn.net/yangdashi888/article/details/103842791