最近想用gpu并行开发一些算法,开发程序在linux下比较方便,于是打算折腾下wsl下的cuda配置。
step1. 查看nvidia配置信息
在命令行使用nvidia-smi命令可以查看
PS C:\Users\gouff> nvidia-smi
Sat Jul 15 16:24:16 2023
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 536.40 Driver Version: 536.40 CUDA Version: 12.2 |
可以看出驱动的版本是536.40,cuda的版本是12.2
step2. 配置wsl (略过),保障是wsl2
step3.在wsl的ubuntu22里安装gcc
sudo apt-get install -y gcc --fix-missing
step4.安装wsl版本的cuda
CUDA Toolkit 12.2 Downloads | NVIDIA Developer
按照下边的命令安装
step5.环境变量设置
NVIDIA CUDA Installation Guide for Linux
查看
step6.验证
输入下面两个命令,如果成功,那就ok了。
nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2023 NVIDIA Corporation
Built on Tue_Jun_13_19:16:58_PDT_2023
Cuda compilation tools, release 12.2, V12.2.91
Build cuda_12.2.r12.2/compiler.32965470_0
nvidia-smi
Sat Jul 15 18:23:09 2023
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 535.54.06 Driver Version: 536.40 CUDA Version: 12.2 |
|-----------------------------------------+----------------------+----------------------+
| 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 4070 On | 00000000:01:00.0 On | N/A |
| 0% 30C P8 6W / 215W | 3245MiB / 12282MiB | 1% Default |
| | | N/A |
+-----------------------------------------+----------------------+----------------------+
step7.说明
如果执行cuda程序出错,请补充下边环境变量
export LD_LIBRARY_PATH=/usr/lib/wsl/lib:$LD_LIBRARY_PATH