当然你首先需要有张N卡
官方文档:CUDA on WSL User Guide https://docs.nvidia.com/cuda/wsl-user-guide/
p5291@DESKTOP-1217V6I:~$ nvidia-smi Sat Oct 5 17:38:10 2024 +-----------------------------------------------------------------------------------------+ | NVIDIA-SMI 560.31.01 Driver Version: 560.81 CUDA Version: 12.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 RTX 3050 ... On | 00000000:01:00.0 Off | N/A | | N/A 44C P0 12W / 75W | 0MiB / 4096MiB | 0% Default | | | | N/A | +-----------------------------------------+------------------------+----------------------+ +-----------------------------------------------------------------------------------------+ | Processes: | | GPU GI CI PID Type Process name GPU Memory | | ID ID Usage | |=========================================================================================| | No running processes found | +-----------------------------------------------------------------------------------------+
接下来安装CUDA Toolkit
# 以下的命令只是举例,不保证时效性,安装的时候请参照最新的官方安装说明 wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-keyring_1.1-1_all.deb sudo dpkg -i cuda-keyring_1.1-1_all.deb sudo apt-get update sudo apt-get -y install cuda-toolkit-12-6
安装完成后,检查nvcc是否可用
p7742@DESKTOP-1217V6I:~$ nvcc --version nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2024 NVIDIA Corporation Built on Thu_Sep_12_02:18:05_PDT_2024 Cuda compilation tools, release 12.6, V12.6.77 Build cuda_12.6.r12.6/compiler.34841621_0