概述
因为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
- 在windows中安装visual code。
- 执行下面命令行
sudo apt-get update
sudo apt-get install wget ca-certificates
- 在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...
- Maxwell GPU is not supported.
- Unified Memory - Full Managed Memory Support is not available on Windows native and therefore WSL 2 will not support it for the foreseeable future.
- Pinned system memory (example: System memory that an application makes resident for GPU accesses) availability for applications is limited.
- Root user on bare metal (not containers) will not find nvidia-smi at the expected location.
With the NVIDIA Container Toolkit for Docker 19.03, only --gpus all is supported.
可以看到,对gpu型号的支持不完整,功能不完整,内存也不完整。对于学习没太大问题。wsl的定位就是本地开发。参考
https://zh.d2l.ai/chapter_installation/index.html
https://superuser.com/questions/1388815/use-host-cuda-from-vi...
https://learn.microsoft.com/en-us/windows/wsl/install
https://learn.microsoft.com/en-us/windows/ai/directml/gpu-ten...
https://docs.nvidia.com/cuda/wsl-user-guide/index.html#gettin...
https://learn.microsoft.com/en-us/windows/wsl/tutorials/wsl-v...
https://blogs.windows.com/windowsdeveloper/2020/06/17/gpu-acc...
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。