某一天,在摸鱼的时候被人拍了一下,叫我用Kali跑一下hashcat,因为hashcat可以调用CUDA(显卡)模块,加速爆破 虽然实际上,我的CPU跑起来也很快
但是,既然来了就研究一下。但是我又不想装多系统,那么就该想想怎么在WSL里面调用CUDA了。Update: 其实做到最后我又重新做了一遍。原因在于,我的linux核心其实不支持CUDA。 GPU_CUDA_IN_WSL 在安装前,你需要确认一下你的内核版本,只有5.10.43.3以上的版本才是默认支持的
PS C:\Users\hz2016> wsl cat /proc/version
Linux version 5.10.16.3-microsoft-standard-WSL2 (oe-user@oe-host) (x86_64-msft-linux-gcc (GCC) 9.3.0, GNU ld (GNU Binutils) 2.34.0.20200220) #1 SMP Fri Apr 2 22:23:49 UTC 2021
你需要打开下面的功能,并且把内核更新到最新版
- 安装Ubuntu的WSL版并换源
由于WSL版的Ubuntu不自带gcc,所以我们在安装CUDA前要自己装一个
apt-get install gcc -y
- 安装CUDA for WSL-Ubuntu
CUDA Toolkit官网下载 我安装的十CUDA Toolkit 11.6版本,选择的是Runfile(可执行文件)安装 别问为什么,只要知道我翻车很多次就是了。
wget https://developer.download.nvidia.com/compute/cuda/11.6.2/local_installers/cuda_11.6.2_510.47.03_linux.run
sudo sh cuda_11.6.2_510.47.03_linux.run
千万别点进去Options的Drives,别问我为什么问就是我在来了一次
安装完成===========
= 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
- 添加PATH路径
export PATH=/usr/local/cuda-11.6/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-11.6/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
- 验证是否更新成功
root@hz2016-pc:~# nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Tue_Mar__8_18:18:20_PST_2022
Cuda compilation tools, release 11.6, V11.6.124
Build cuda_11.6.r11.6/compiler.31057947_0
- 更新你的显卡驱动
A driver of version at least 510.00 is required for CUDA 11.6 functionality to work.
打开GPU-Z查看一下
发现自己是497.29版本的显卡驱动,于是更新一下然后你就可以在你的WSL里面跑CUDA了~
- 安装OpenCL相关(翻车)
apt-get install beignet clinfo
apt-get install beignet-dev
apt-cache search opencl
运行clinfo测试一下
root@hz2016-pc:~# clinfo
······
clCreateContextFromType(NULL, CL_DEVICE_TYPE_GPU) No devices found in platform
clCreateContextFromType(NULL, CL_DEVICE_TYPE_ACCELERATOR) No devices found in platform
clCreateContextFromType(NULL, CL_DEVICE_TYPE_CUSTOM) No devices found in platform
······
还是找不到GPU,翻了下文档,还是我想多了
OpenGL-CUDA Interop is not yet supported. Applications relying on OpenGL will not work.
要用GPU跑hashcat还是去win版跑吧
实测GPU跑比CPU跑快130倍
播主这条export PATH不能这么用啊,你这样会把其他PATH干没得
测试了一下使用
好像是会把旧的PATH也涵盖进来,而不会覆盖掉旧的PATH
完犊子,PATH给我整没了
很奇怪,我本地是可以跑的,可能你复制少了🤔
哈哈哈