一、驗證CUDA是否安裝成功
為驗證CUDA是否安裝成功,可以執行以下步驟:
1、打開終端窗口,輸入以下命令:
$ nvcc -V
如果CUDA已成功安裝,則將顯示CUDA版本信息,如:
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Thu_Jul_29_15:12:49_PDT_2021
Cuda compilation tools, release 11.4, V11.4.120
Build cuda_11.4.r11.4/compiler.30188945_0
2、輸入以下命令:
$ nvidia-smi
如果CUDA已成功安裝,則將顯示GPU卡的信息,如:
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 470.57.02 Driver Version: 470.57.02 CUDA Version: 11.4 |
|-------------------------------+----------------------+----------------------+
| 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 108... Off | 00000000:01:00.0 On | N/A |
| 51% 60C P2 84W / 250W | 9436MiB / 11178MiB | 17% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
二、驗證CUDA是否能夠被Python識別
為驗證CUDA是否能夠被Python識別,可以執行以下步驟:
1、打開Python交互式環境,輸入以下Python代碼:
import torch
print(torch.cuda.is_available())
如果CUDA已經被Python識別,則將顯示True,如:
True
三、驗證CUDA是否能夠被PyTorch識別
為驗證CUDA是否能夠被PyTorch識別,可以執行以下步驟:
1、打開Python交互式環境,輸入以下Python代碼:
import torch
print(torch.cuda.is_available())
x = torch.cuda.FloatTensor(1)
print(x.get_device())
如果CUDA已經被PyTorch識別,則將顯示True和GPU卡的編號,如:
True
0
四、驗證CUDA是否能夠被TensorFlow識別
為驗證CUDA是否能夠被TensorFlow識別,可以執行以下步驟:
1、打開Python交互式環境,輸入以下Python代碼:
import tensorflow as tf
print(tf.test.is_gpu_available())
print(tf.config.list_physical_devices('GPU'))
如果CUDA已經被TensorFlow識別,則將顯示True和GPU的詳細信息,如:
True
[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]
五、小結
通過以上幾個方面的驗證,可以充分確認CUDA是否已經安裝成功,並且能夠被各個深度學習框架識別和使用。
原創文章,作者:RALD,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/144300.html