参考网址:https://zhuanlan.zhihu.com/p/460806048
CUDA 11.6 + CUDNN + Anaconda + pytorch
电脑信息 RTX 2060 GPU0
1. CUDA 11.6
1.1 确认信息
C:\Users\thzn>nvidia-smi (CUDA Version指的是支持的最高版本)
显卡驱动和cuda版本的对应关系 https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html
1.2 电脑配置满足后,更新驱动 https://developer.nvidia.com/cuda-toolkit-archive
1.3 驱动安装完成后,版本查看:
C:\Users\thzn>nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Fri_Dec_17_18:28:54_Pacific_Standard_Time_2021
Cuda compilation tools, release 11.6, V11.6.55
Build cuda_11.6.r11.6/compiler.30794723_0
会自动添加环境变量
CUDA PATH C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6
CUDA PATH V10 0 C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6
1.4 CUDNN下载并配置 https://developer.nvidia.com/zh-cn/cudnn
图21安装cudnn,这个进入NVIDIA官网特别慢,还要注册,比较麻烦(官网NVIDIA cuDNN | NVIDIA Developer
![](https://pic1.zhimg.com/80/v2-67f5a3009daf876112d8456139ae5a3c_720w.webp)
最后是图23所示
![](https://pic3.zhimg.com/80/v2-c7eed339ce0398ac935897dde3db5b7e_720w.webp)
![](/i/l/?n=23&i=blog/432074/202301/432074-20230116102047144-1996793894.png)
对于cdnn里的lib文件夹,里面还存在一个x64文件夹,而CUDA中lib文件中存在Win32和x64文件,于是这时把cudnn中lib里打开x64文件夹,拷贝x64文件夹里所有内容到CUDA里lib中x64文件夹中去
验证cuda是否安装成功,首先win+R启动cmd,进入到CUDA安装目录下的 ...\extras\demo_suite,然后分别运行bandwidthTest.exe和deviceQuery.exe,应该得到图28,返回Result=PASS表示cuda安装成功。图28中只运行了bandwidthTest.exe,同样运行deviceQuery.exe也可得到PASS。
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\extras\demo_suite>bandwidthTest
[CUDA Bandwidth Test] - Starting...
Running on...
Device 0: NVIDIA GeForce RTX 2060
Quick Mode
Host to Device Bandwidth, 1 Device(s)
PINNED Memory Transfers
Transfer Size (Bytes) Bandwidth(MB/s)
33554432 11865.8
Device to Host Bandwidth, 1 Device(s)
PINNED Memory Transfers
Transfer Size (Bytes) Bandwidth(MB/s)
33554432 12609.9
Device to Device Bandwidth, 1 Device(s)
PINNED Memory Transfers
Transfer Size (Bytes) Bandwidth(MB/s)
33554432 260632.7
Result = PASS
NOTE: The CUDA Samples are not meant for performance measurements. Results may vary when GPU Boost is enabled.
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\extras\demo_suite>deviceQuery.exe
deviceQuery.exe Starting...
CUDA Device Query (Runtime API) version (CUDART static linking)
Detected 1 CUDA Capable device(s)
Device 0: "NVIDIA GeForce RTX 2060"
CUDA Driver Version / Runtime Version 12.0 / 11.6
CUDA Capability Major/Minor version number: 7.5
Total amount of global memory: 12288 MBytes (12884574208 bytes)
(34) Multiprocessors, ( 64) CUDA Cores/MP: 2176 CUDA Cores
GPU Max Clock rate: 1680 MHz (1.68 GHz)
Memory Clock rate: 7001 Mhz
Memory Bus Width: 192-bit
L2 Cache Size: 3145728 bytes
Maximum Texture Dimension Size (x,y,z) 1D=(131072), 2D=(131072, 65536), 3D=(16384, 16384, 16384)
Maximum Layered 1D Texture Size, (num) layers 1D=(32768), 2048 layers
Maximum Layered 2D Texture Size, (num) layers 2D=(32768, 32768), 2048 layers
Total amount of constant memory: zu bytes
Total amount of shared memory per block: zu bytes
Total number of registers available per block: 65536
Warp size: 32
Maximum number of threads per multiprocessor: 1024
Maximum number of threads per block: 1024
Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
Max dimension size of a grid size (x,y,z): (2147483647, 65535, 65535)
Maximum memory pitch: zu bytes
Texture alignment: zu bytes
Concurrent copy and kernel execution: Yes with 2 copy engine(s)
Run time limit on kernels: Yes
Integrated GPU sharing Host Memory: No
Support host page-locked memory mapping: Yes
Alignment requirement for Surfaces: Yes
Device has ECC support: Disabled
CUDA Device Driver Mode (TCC or WDDM): WDDM (Windows Display Driver Model)
Device supports Unified Addressing (UVA): Yes
Device supports Compute Preemption: Yes
Supports Cooperative Kernel Launch: Yes
Supports MultiDevice Co-op Kernel Launch: No
Device PCI Domain ID / Bus ID / location ID: 0 / 1 / 0
Compute Mode:
< Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >
deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 12.0, CUDA Runtime Version = 11.6, NumDevs = 1, Device0 = NVIDIA GeForce RTX 2060
Result = PASS
2. 安装Anaconda
3. 安装pytorch
conda create -n mmlabGPU python=3.7 -y
conda activate mmlabGPU
GPU:pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu116
CPU:pip3 install torch torchvision torchaudio
测试
python
>> import torch
>> torch.cuda.is_available() #检查cuda是否可以使用 True
>> torch.cuda.current_device() #查看当前gpu索引号
>> torch.cuda.current_stream(device=0)#查看当前cuda流
>> torch.cuda.device(1) #选择device
>> torch.cuda.device_count() #查看有多少个GPU设备
>> torch.cuda.get_device_capability(device=0) #查看gpu的容量
标签:torch,win11,cuda,深度,Device,GPU,NVIDIA,CUDA From: https://www.cnblogs.com/chen1880/p/17054833.html