我曾经苦苦挣扎数日,试图在使用RTX 3080的WSL2上使torch工作。
我安装了CUDA-toolkit 11.3版本。
运行nvcc -V
返回如下信息:
nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Sun_Mar_21_19:15:46_PDT_2021
Cuda compilation tools, release 11.3, V11.3.58
Build cuda_11.3.r11.3/compiler.29745058_0
nvidia-smi
返回以下结果
Mon Nov 29 00:38:26 2021
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 510.00 Driver Version: 510.06 CUDA Version: 11.6 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|===============================+======================+======================|
| 0 NVIDIA GeForce ... On | 00000000:01:00.0 On | N/A |
| N/A 52C P5 17W / N/A | 1082MiB / 16384MiB | N/A Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
| No running processes found |
+-----------------------------------------------------------------------------+
我用blackscholes验证了工具包的安装
./BlackScholes
[./BlackScholes] - Starting...
GPU Device 0: "Ampere" with compute capability 8.6
Initializing data...
...allocating CPU memory for options.
...allocating GPU memory for options.
...generating input data in CPU mem.
...copying input data to GPU mem.
Data init done.
Executing Black-Scholes GPU kernel (512 iterations)...
Options count : 8000000
BlackScholesGPU() time : 0.242822 msec
Effective memory bandwidth: 329.459087 GB/s
Gigaoptions per second : 32.945909
BlackScholes, Throughput = 32.9459 GOptions/s, Time = 0.00024 s, Size = 8000000 options, NumDevsUsed = 1, Workgroup = 128
Reading back GPU results...
Checking the results...
...running CPU calculations.
Comparing the results...
L1 norm: 1.741792E-07
Max absolute error: 1.192093E-05
Shutting down...
...releasing GPU memory.
...releasing CPU memory.
Shutdown done.
[BlackScholes] - Test Summary
NOTE: The CUDA Samples are not meant for performance measurements. Results may vary when GPU Boost is enabled.
Test passed
当我尝试使用torch时,它无法找到任何GPU。顺便说一下,如果我想要在我的RTX 3080上使用torch,我必须安装torch==1.10.0+cu113,因为简单的1.10.0版本与rtx3080不兼容。
运行torch会返回以下结果:
>>> import torch
>>> torch.version
<module 'torch.version' from '/home/snihar/miniconda3/envs/tscbasset/lib/python3.7/site-packages/torch/version.py'>
>>> torch.version.cuda
'11.3'
>>> torch.cuda.get_arch_list()
[]
>>> torch.cuda.device_count()
0
>>> torch.cuda.current_device()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/snihar/miniconda3/envs/tscbasset/lib/python3.7/site-packages/torch/cuda/__init__.py", line 479, in current_device
_lazy_init()
File "/home/snihar/miniconda3/envs/tscbasset/lib/python3.7/site-packages/torch/cuda/__init__.py", line 214, in _lazy_init
torch._C._cuda_init()
RuntimeError: No CUDA GPUs are available
有趣的是,我最终成功在同一台设备上运行tensorflow-gpu。
像这样安装pytorch:conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch
此外,我还成功地在WSL2机器启动的docker容器中运行了pytorch,使用以下命令:
sudo docker run --gpus all -it --rm -v /home/...:/home/... nvcr.io/nvidia/pytorch:21.11-py3.
当我在运行Windows机器上的PyTorch时,我也在运行WSL。两者都返回 ['sm_37', 'sm_50', 'sm_60', 'sm_61', 'sm_70', 'sm_75', 'sm_80', 'sm_86','compute_37'],表明该库与RTX 3080兼容。
print(torch.__version__)
的输出是什么?你有可能安装了一个仅支持 CPU 的 PyTorch 版本吗? - Shaiconda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch
。例如,返回此软件包: pytorch 1.10.0 py3.7_cuda11.3_cudnn8.2.0_0 pytorch在我的Windows机器上,我也有11.3工具包,在调用get_arch_list()时返回:['sm_37', 'sm_50', 'sm_60', 'sm_61', 'sm_70', 'sm_75', 'sm_80', 'sm_86', 'compute_37']
。 在WSL2机器上也是一样的,返回一个空列表。 - haroldnvidia-smi
。在将自己添加到video
组之后,我可以在没有root权限的情况下运行nvidia-smi
,而且初始问题也解决了。 - sh1