WSL2安装cuda toolkit
首先要确保你安装的wsl是wsl2,去wsl里面输入uname -a就可以了,如果跳出的内核版本是4.x就是wsl1,你需要升级windows系统和wsl
*PS:升级完系统,如果输入wsl --update提示报错码,请输入wsl --shutdown关闭wsl实例
如果一直卡0%,请附加参数--web-download,让它从github上下载,这是nt微软商店的问题。
然后,windows主机安装好cuda toolkit和驱动就可以,在wsl里面只需要安装toolkit就好了,驱动会由windows映射到wsl里面的
检查是否映射到wsl里的方法:启动wsl,输入nvidia-smi,如果没有跳出来下面的图,你需要检查上面的步骤:
接下来直接安装,nvidia这个地址,选择wsl2 ubuntu,再选择runfile就提供安装指令了。
运行的时候如果提示failed verify gcc,请安装并更新gcc:
apt-get update apt-get install gcc-11 apt-get install gcc
再次运行,请输入accept,接下来的页面直接用键盘方向键切到install,就直接安装了。
安装完是下面这个提示。
=========== = Summary = =========== Driver: Not Selected Toolkit: Installed in /usr/local/cuda-11.6/ Please make sure that - PATH includes /usr/local/cuda-11.6/bin - LD_LIBRARY_PATH includes /usr/local/cuda-11.6/lib64, or, add /usr/local/cuda-11.6/lib64 to /etc/ld.so.conf and run ldconfig as root To uninstall the CUDA Toolkit, run cuda-uninstaller in /usr/local/cuda-11.6/bin ***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 510.00 is required for CUDA 11.6 functionality to work. To install the driver using this installer, run the following command, replacing with the name of this run file: sudo .run --silent --driver
此时会提示你要加入环境变量,root用户请在/root目录下,用nano或者vim打开.bashrc
将please make sure提示的环境变量加到文件的结尾
cuda 12.6的,自行更改:
export PATH=/usr/local/cuda-12.6/bin${PATH:+:${PATH}} export LD_LIBRARY_PATH=/usr/local/cuda-12.6/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
保存退出,输入nvcc -V查看nvcc版本以确认安装: