Lxn-Chan!

(~ ̄▽ ̄)→))* ̄▽ ̄*)o

安装WSL2并在WSL2中安装nvidia的cuda toolkit,以便在wsl2中共享使用主机的计算卡。

安装前准备

首先你需要确保你安装有Pascal架构(Geforce 10xx或Tesla P100)及以上的显卡,并安装了公版的最新驱动,推荐使用Game Ready驱动而非Studio驱动。

安装WSL2

仅适用于首次全新安装。

  1. 安装WSL基本环境
    1
    wsl --install
    随后会要求重启
  2. 切换默认版本为WSL2
    1
    wsl --set-default-version 2
  3. 查看可用的发行版
    1
    wsl.exe --list --online
    我这里选择了Debian,实际使用起来会比ubuntu轻量一点且差异较小。
    1
    wsl.exe --install Debian
    随后会自动下载和安装,安装完成后将要求设置用户名密码。
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    正在下载: Debian GNU/Linux
    正在安装: Debian GNU/Linux
    已成功安装分发。可以通过 “wsl.exe -d Debian” 启动它
    正在启动 Debian...
    Please create a default UNIX user account. The username does not need to match your Windows username.
    For more information visit: https://aka.ms/wslusers
    Enter new UNIX username: lxnchan
    New password:
    Retype new password:
    passwd: password updated successfully

安装CUDA Toolkit

参考官方文档

  1. 换源,不再赘述。
    安装必要的工具
    1
    apt install curl wget gnupg2 -y
  2. 下载Pin规则以防止从源安装cuda toolkit
    1
    wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-wsl-ubuntu.pin
  3. 下载安装包
    1
    wget https://developer.download.nvidia.com/compute/cuda/12.9.1/local_installers/cuda-repo-wsl-ubuntu-12-9-local_12.9.1-1_amd64.deb
  4. 下载后安装
    1
    dpkg -i cuda-repo-wsl-ubuntu-12-9-local_12.9.1-1_amd64.deb
    安装Key
    1
    cp /var/cuda-repo-wsl-ubuntu-12-9-local/cuda-CB802CB8-keyring.gpg /usr/share/keyrings/
  5. 安装Cuda toolkit
    1
    apt update && apt install -y cuda-toolkit-12-9
  6. 创建软链接
    1
    ln -s /usr/lib/wsl/lib/nvidia-smi /usr/bin/nvidia-smi
    这样就能在wsl2中执行nvidia-smi
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    root@WIN-9H35TRE44W2:~# nvidia-smi
    Tue Jul 22 09:47:51 2025
    +-----------------------------------------------------------------------------------------+
    | NVIDIA-SMI 575.64.01 Driver Version: 576.80 CUDA Version: 12.9 |
    |-----------------------------------------+------------------------+----------------------+
    | 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 RTX 3080 On | 00000000:41:00.0 Off | N/A |
    | 30% 22C P8 12W / 320W | 53MiB / 10240MiB | 0% Default |
    | | | N/A |
    +-----------------------------------------+------------------------+----------------------+

    +-----------------------------------------------------------------------------------------+
    | Processes: |
    | GPU GI CI PID Type Process name GPU Memory |
    | ID ID Usage |
    |=========================================================================================|
    | 0 N/A N/A 34 G /Xwayland N/A |
    +-----------------------------------------------------------------------------------------+

 简单说两句



联系站长 | 服务状态 | 友情链接

备案号:辽ICP备19013963号

萌ICP备 20219421 号

津公网安备12011602300394号

中国互联网违法和不良信息举报中心

架构版本号:8.1.7 | 本站已全面支持IPv6

正在载入运行数据(1/2)请稍后...
正在载入运行数据(2/2)请稍后...

♥stand with innovative technologies of all kinds♥

Copyright 2024 LingXuanNing, All rights reserved.