Do you accept the previously read EULA? accept/decline/quit: accept
Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 384.81? (y)es/(n)o/(q)uit: n # 如果在这之前已经安装好更高版本的显卡驱动就不需要再重复安装,如果需要重复安装就选择 yes,此外还需要关闭图形界面。
Install the CUDA 9.0 Toolkit? (y)es/(n)o/(q)uit: y
Enter Toolkit Location [ default is /usr/local/cuda-9.0 ]: # 一般选择默认即可,也可以选择安装在其他目录,在需要用的时候指向该目录或者使用软连接 link 到 /usr/local/cuda。
/usr/local/cuda-9.0 is not writable. Do you wish to run the installation with 'sudo'? (y)es/(n)o: y
Please enter your password: Do you want to install a symbolic link at /usr/local/cuda? # 是否将安装目录通过软连接的方式 link 到 /usr/local/cuda,yes or no 都可以,取决于你是否使用 /usr/local/cuda 为默认的 cuda 目录。 (y)es/(n)o/(q)uit: n
Install the CUDA 9.0 Samples? (y)es/(n)o/(q)uit: n
选择的汇总:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Driver: Not Selected Toolkit: Installed in /usr/local/cuda-9.0 Samples: Not Selected
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
安装完成后可以在 /usr/local
目录下看到:
1 2 3
cuda-11.1 # 之前安装的cuda-11.1 cuda-9.0 # 刚刚安装的cuda-9.0 cuda # cuda-10.0 的软连接
nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2016 NVIDIA Corporation Built on Mon_Jan_23_12:24:11_CST_2017 Cuda compilation tools, release 8.0, V8.0.62
# In[]: import torch # cpu print(torch.__version__) # gpu print(torch.cuda.is_available())
# In[]: import tensorflow as tf # cpu print(tf.__version__) # v1 to test gpu print(tf.test.is_gpu_available()) # v2 to test gpu print(tf.config.list_physical_devices('GPU'))
from tensorflow.python.client import device_lib # 列出所有的本地机器设备 local_device_protos = device_lib.list_local_devices() # 打印 # print(local_device_protos) # 只打印GPU设备 [print(x) for x in local_device_protos if x.device_type == 'GPU']
pytorch
1 2 3 4 5 6 7 8 9 10 11 12 13
import torch flag = torch.cuda.is_available() if flag: print("CUDA可使用") else: print("CUDA不可用")
ngpu= 1 # Decide which device we want to run on device = torch.device("cuda:0"if (torch.cuda.is_available() and ngpu > 0) else"cpu") print("驱动为:",device) print("GPU型号: ",torch.cuda.get_device_name(0))