Article directory
Download and installation of Cuda
cuda version
Due to different graphics cards, you need to check the highest CUDA supported by our graphics card and driver first.
Enter cmd input
nvidia -smi
The version supports backward compatibility. In order to ensure compatibility with other development library versions, the CUDN version used here is 11.6.
cuda download
CUDA Toolkit| NVIDIA Developer official websiteFind the corresponding CUDA version. (I chose CUDA11.6 here)
Select the following configurations in turn, click Download to download
Open the downloaded .exe file, it is recommended to choose custom installation, as follows Figures are selected according to this option.
Just wait for the installation to complete.
cuDNN download and installation
cuDNN download
Use the following URL to find the corresponding cuDNN version
cuDNN download
The download is a compressed package. After decompressing the compressed package, the file Yes
Copy the three files, open the CUDA installation location, (I am using the default location, the file path is as shown below) and paste it directly. If you encounter replacement, you can agree by default.
Configure environment variables
Environment variables will be automatically configured for you when installing CUDA. If not, follow the following steps to complete the configuration:
Open "Edit Environment System Variables"—> "Environment Variables"—>Find "path" in "System Variables"—>Add the following path
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\bin
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\include
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\libnvvp
TestCUDA
Enter in cmdnvcc -V
Test computing power
"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\extras\demo_suite\deviceQuery.exe"
Find deviceQuery.exe and run it with cmd,
At this point, CUDA Complete with cuDNN configuration
Download torch package
Usually when we talk about pytorch, we refer to the cpu version. If you use torch.cuda.is_available()
, it will return False no matter what. After checking many blogs, I found out that there is also a gpu version of torch.
pytorch official website
Find the previous version here
Mine is 11.6, and the corresponding code entered in the conda terminal is:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple torch===1.13.1 torchvision==0.14.1 -f https://download.pytorch.org/whl/torch_stable.html
Download is complete
Verify whether cuda is available
Enter the code in pycharm/vscode to see if cuda is available
import torch
flag = torch.cuda.is_available()
if flag:
print("CUDA可使用")
else:
print("CUDA不可用")
ngpu= 1
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))
At this point, you can use your local GPU to train the neural network!