Windows10, CUDA, GPU version torch installation

1. Initial inspection

        Pre-environment preparation: no specific requirements for anaconda and pycharm versions

        windows10 open command line

1.1 Check if conda is installed

       

 

1.2 Check if pycharm is installed, just check if you have installed it

Windows users: win+R -> enter cmd and click "Run" -> enter nvidia-smi to check if there is graphics card information

1.2 CUDA version

 If you can’t open it nvidia-smior cuda can’t view it, please install the driver and toolkit from the official website.

NVIDIA GeForce Drivers - N Card Drivers | NVIDIA      https://www.nvidia.cn/geforce/drivers/

install cuda

CUDA Toolkit Archive | NVIDIA Developer

When installing the driver, install the appropriate cuda version and cuDNN version (for neural network acceleration. But it seems that there is no need to download it in a hurry, because PyTorch comes with cuDNN, so you may only download and install cuda).

You only need to install the ones in the red box. Others should not need to be installed. Of course, if you want to be on the safe side, install them all.

runtime is the runtime dll for Python calls, we use this

You can tell by the name that development is used for development, such as making games or game engines?

Visual studio integration can be seen as a vs plug-in by looking at the name, which is not needed here

The nsight system should also develop special programs for Nvidia graphics cards, so it is not necessary.

samples are sample programs. Not required (for graphics card application development)

Documentation is a document, in fact, you don’t need it, but this thing is not big, and you can read it as a practice English after downloading it.

After the installation is complete, run nvidia-smito view the version.

 2.1. The download rescue method for cross-extranet access in China

Copy the URL behind the command, and open it directly in the browser (you can also download it from Tsinghua source, here is the link Simple Index https://pypi.tuna.tsinghua.edu.cn/simple )

It looks like this after opening

Then look at the commands generated by PyTorch let us install what?

 Then install the three separately.

 If the download is too slow, please use a tool such as Thunder to speed it up.

For example, install torch first, click to enter, you will see a .whl file, you need to choose a suitable version to download

First of all, you must download the latest version , secondly, it must match your cuda version , then the Python version must also be suitable, then the operating system must also match, and finally,  the processor architecture must be suitable.

For example, my computer is cuda11.6, Python3.8.5(py3.8), Windows10 system (WindowsNT kernel), i5-9300H processor (Intel's x86 processor), then just choose this.

Click to download. If the download is too slow, please use a tool such as Thunder to speed up.

cu116 is the abbreviation of cuda11.6.

cp38 means the Python3.8.x version of the cpython interpreter (if it is an independent Python, not the one based on anaconda, then generally you also install the Python of the cpython interpreter (that is, the interpreter of the Python runtime uses c The version of the interpreter written in the language. There are also interpreters compiled with java, and pypy compiled with Python interpreters, which is not important here))

win_amd64 means that the system is a Windows system, and the processor is a processor with a 64-bit complex instruction set (because 64-bit is the earliest AMD developed, so it is called, of course, it is also called. Generally, AMD6432 x86-64-bit operating systems are written as only x86or  IA32words.

2.2 Installation method

Take pip as an example here, for other package managers, please refer to the installation method online.

Use pip to specify the path of the installed package.

the easiest way

  1. Open the folder of the .whl file
  2. Hold down shift, right click, select "Open PowerShell here" (anyway, just open a terminal under this path. You can also use the cd command to change dir), and perform the following operations
  3. Type and run pip install ./torch-1.12.0+cu116-cp38-cp38-win_amd64.whl to install torch.
  4. Similarly, install other packages (using the package name of .whl, which can be automatically completed by tab)

3. Installation is ready, start testing
 

First run this command in Python: torch.cuda.is_available()

specific method:

  1. open a terminal
  2. run python
  3. import torch
  4. torch.cuda.is_available()

as shown in the picture

If it returns True, then it is good. You can run the graphics card.

If it doesn't work, then it's not installed correctly, and it can only run with cpu. There must be something wrong. Check back......

Use a program to test the execution time, otherwise I don't worry

I'm also a beginner, maybe I can't write well, but this program can prove that the graphics card is working.

import torch
import time

gpu = torch.device('cuda')
# 如果用cpu测试那么注释掉上面的代码, 用下面的
# gpu = torch.device('cpu')

beginTime=time.time()

a=torch.rand(2048,2048)
b=torch.rand(2048,2048)
c=torch.rand(2048,2048)

x = a.to(gpu)
y = b.to(gpu)

z = c.to(gpu)

initTime=time.time()
print("ok")

i=0

while i<10000:
    z=(z+x+y)
    i+=1
    
endTime=time.time()

print(z)

print("运行结束, 初始化使用了 {} 秒, 循环用了 {} 秒".format(initTime-beginTime,endTime-beginTime))
    

Guess you like

Origin blog.csdn.net/qq_46644680/article/details/129744112