概述

因为virtualbox中无法使用cuda,见use-host-cuda-from-virtualbox。所以我想到了windows下的wsl,尝试后发现可行,记录一下过程。
后面得知,wsl2对gpu的支持是20年引入的:
https://blogs.windows.com/windowsdeveloper/2020/06/17/gpu-acc...

步骤

建议按推荐步骤安装。我首次安装时,先安装了深度学习框架,后安装gpu驱动,会有segfragment fault。重新安装深度学习框架后问题解决。

1. 安装 invida 驱动,cuda

driver:
https://www.nvidia.com/download/index.aspx
cuda toolkit:
https://developer.nvidia.com/cuda-downloads
下载点击安装。

2. 安装 wsl

wsl --install
参考:
https://learn.microsoft.com/en-us/windows/wsl/install
可以安装一下windows terminal改善体验。
https://apps.microsoft.com/detail/9N0DX20HK701
默认是ubuntu22 jammy 修改成国内源:
https://www.linuxmi.com/ubuntu-22-04-apt-sources-list.html
注意不要在wsl的linux系统里安装步骤1的内容,gpu driver以及cuda。也不要安装后面的visual code。

3. 安装深度学习框架

按dive in to deep learning 中的步骤执行如下:

sh Miniconda3-py39_4.12.0-Linux-x86_64.sh -b
~/miniconda3/bin/conda init
conda create --name d2l python=3.9 -y
conda activate d2l

https://zh.d2l.ai/chapter_installation/index.html
至此环境已经搭建完毕:

(d2l) dingxinglong@DESKTOP-PUDTV3D:~/git$ nvidia-smi
Sun Nov  5 22:41:44 2023
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 545.29.01              Driver Version: 546.01       CUDA Version: 12.3     |
|-----------------------------------------+----------------------+----------------------+
| 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 GTX 1650        On  | 00000000:01:00.0 Off |                  N/A |
| 24%   34C    P8              N/A /  75W |     86MiB /  4096MiB |      0%      Default |
|                                         |                      |                  N/A |
+-----------------------------------------+----------------------+----------------------+

+---------------------------------------------------------------------------------------+
| Processes:                                                                            |
|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |
|        ID   ID                                                             Usage      |
|=======================================================================================|
|  No running processes found                                                           |
+---------------------------------------------------------------------------------------+

4. 安装 visual code (可选)

注意是在windows中安装,如果在wsl的linux系统中安装过,先用下面命令删除

sudo apt purge code
sudo apt autoremove
  1. 在windows中安装visual code。
  2. 执行下面命令行
sudo apt-get update
sudo apt-get install wget ca-certificates
  1. 在wsl terminal 中启动
code .

https://learn.microsoft.com/en-us/windows/wsl/tutorials/wsl-v...

Known Limitations

见:https://docs.nvidia.com/cuda/wsl-user-guide/index.html#gettin...


enjolras1205
77 声望9 粉丝