WSL2 Pytorch-运行时错误:RTX3080没有可用的CUDA GPU



我一整天都在努力使用RTX 3080在WSL2上实现火炬工作。

我安装了CUDA工具包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。顺便说一句,如果我想将torch与RTX 3080一起使用,我必须安装torch==1.10.0+cu113,因为sm_与简单的1.10.0版本不兼容rtx3080。

正在运行的火炬返回:

>>> 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.  

当在我运行WSL的windows机器上运行pytorch时,它也能工作。两者都返回['sm_37','sm_50','sm_60','sm_70','sm_75','sm_80','sm_86','compute_37'],表示该库与rtx 3080兼容。

在我的案例中,我通过将/usr/lib/wsl/lib/libcuda.so.1链接到您的wsl2 CUDA位置中的libcuda.so来解决此问题。看见https://github.com/microsoft/WSL/issues/5663重新启动后,pytorch可以找到GPU。

(我在apt-get升级命令中发现警告"/usr/lib/wsl/lib/libcuda.so.1不是符号链接"。不确定你能用同样的方法解决它(降级到pytorch 1.8.2LTS也能解决问题,但计算速度极低。

我也遇到过同样的问题,通过将pytorch从1.10降级到1.8.2LTS 来解决

运行命令sudo ldconfig时,我收到了与@Homer-Simpson相同的警告。

以@Homer Simpson发布的方式处理它。从本质上讲,您需要做的是删除libcuda.solibcuda.so.1并重新创建它们,但这一次,创建到libcuda.so.1.1的符号链接

# Run CMD in Windows (as Administrator)
C:
cd WindowsSystem32lxsslib
del libcuda.so
del libcuda.so.1
mklink libcuda.so libcuda.so.1.1
mklink libcuda.so.1 libcuda.so.1.1
# Open WSL bash
wsl -e /bin/bash
sudo ldconfig

参考编号:https://github.com/microsoft/WSL/issues/5548#issuecomment-912495487

简而言之:安装带有cuda 11.1或更低版本的PyTorch

Long:不幸的是,我无法解释为什么会发生这种情况,但在尝试了不同的发行版版本(ubuntu和debian(和PyTorch版本(pip和conda(后,cuda 11.3似乎不起作用(cuda 10.2运行得很好(,这是PyTorch在conda上唯一附带的11.x cuda。

解决方案:必须使用pip安装它,给定您想要的版本,从官方先前的pytorch版本页面。

在撰写本文时,可以使用以下命令安装WSL2上具有最高cuda的最高PyTorch版本:

pip install torch==1.10.1+cu111 torchvision==0.11.2+cu111 -f https://download.pytorch.org/whl/torch_stable.html

注意,您需要使用cmd.exe而不是powershell,因为mklink是cmd.exe的一部分,而不是实际的程序

最新更新