Install CUDA, CUDNN and Pytorch (the latest super detailed graphic version is the latest in August 2023)

1. Install CUDA

1.1. Download the installation package

cuda can be considered as a software developed by Nvidia for alchemy of graphics cards. The download address is: CUDA Toolkit 12.2 Update 1 Downloads | NVIDIA Developer

When you click on this link, you need to select
image-20230806174437057

1 is to select the system, here choose windows

2 is to choose the platform, 32-bit or 64-bit, in fact, only 64-bit is supported

3 is to select the system version, here we choose win10, if it is another system, choose other

4. Choose local download, that is, download all at once and then install, or download from the network, that is, download an installation tool and install while downloading

5 is download, you can see that the installation package has 3GB

Note: Here we directly select the latest version of CUDA. If you need other versions, just click this link CUDA Toolkit Archive | NVIDIA Developer,
https://img-blog.csdnimg.cn/07e19c81ee304585bf8b76b522b7a46e.png
which has the version you need.

1.2. Installation

Double-click the downloaded file
image-20230806195158529
and confirm all the way later. The default installation location is

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.2

So we need to add two system variables. In fact, they have been added by default during installation. In order to prevent the addition from being successful, here we can take a look
1

click properties

1 1

It mainly depends on whether there are these two items. If not, create a new one and add it.

Two, CUDNN installation

2.1, CUDNN download

Download link: cuDNN Download | NVIDIA Developer
1

You have to agree to his policy, which is to click on the small box in front
1

Then there will be two download options, we choose the first one, because the CUDA version corresponding to the first CUDNN is 12, and the CUDA version we installed is 12.

If you need to download historical versions, click this link cuDNN Archive | NVIDIA Developer

Note: Maybe you need to log in to enter this website. This is normal. I have logged in before, so I haven’t encountered it. If you need to log in, just register an account and log in.

2.2. Installation

After downloading, it is a compressed package. We can get three folders by decompressing it so far.

1

Copy these three folders to our previous CUDA directory, , C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.2there are also three files with the same name in this directory, just copy the files.

After the copy is complete, you need to add environment variables, this time we add to PATH,

1

2.3. Verification

How do we know that the CUDA and CUDNN we installed are correct? We need to verify it, open CMD, and enter the command

nvcc -V
1

There are things like these version numbers to basically verify that the installation is successful. Open this address for further verification

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.2\extras\demo_suite

run these two programs
1

Get the following two results
1

1

Verify the installation was successful

3. Pytorch installation

3.1. Install Anaconda

You can refer to my blog Anaconda Meng new entry_LyaJpunov's blog - CSDN blog

Just download a program and confirm all the way. Now it is recommended to download from the official, the official download is also very fast. Free Download | Anaconda

3.2. Create and activate a virtual environment

After entering the command line, create a virtual environment named learning

conda create -n learning

Then activate the environment

conda activate learning

3.3. Install pytorch

We entered the Pytorch download address Start Locally | PyTorch , and found that we installed the latest CUDA12.2 version, but the latest stable version of pytorch supports up to 11.7, which is too dry, but after searching for information, it is found that it can be used.
1

Of course, we can also use the preview version, that is, the unstable version, which supports 12.1
1

Let's follow CUDA11.7 and enter the following command, which is also generated by the website

conda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidia

After a period of time, it is installed. After installation, you can verify it through the Python script.

import torch
torch.cuda.is_available()

If the output is True, there is no problem

Guess you like

Origin blog.csdn.net/weixin_43903639/article/details/132135094