根据微软官方的文档在Windows下安装nvidia显卡驱动后,就不用在linux子系统安装nvidia驱动,在linux子系统中输入
~$ nvidia-smi
可以看到输出如下:
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 535.112 Driver Version: 537.42 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 GTX 1060 On | 00000000:01:00.0 On | N/A |
| N/A 51C P8 3W / 78W | 356MiB / 6144MiB | 2% Default |
| | | N/A |
+-----------------------------------------+----------------------+----------------------+
+---------------------------------------------------------------------------------------+
linux子系统中是能够正常识别到显卡的,但是输入
~$ glxinfo -B
输出为
name of display: :0
display: :0 screen: 0
direct rendering: Yes
Extended renderer info (GLX_MESA_query_renderer):
Vendor: VMware, Inc. (0xffffffff)
Device: llvmpipe (LLVM 10.0.0, 256 bits) (0xffffffff)
Version: 20.0.8
Accelerated: no
Video memory: 7881MB
Unified memory: no
Preferred profile: core (0x1)
Max core profile version: 3.3
Max compat profile version: 3.1
Max GLES1 profile version: 1.1
Max GLES[23] profile version: 3.1
OpenGL vendor string: VMware, Inc.
OpenGL renderer string: llvmpipe (LLVM 10.0.0, 256 bits)
OpenGL core profile version string: 3.3 (Core Profile) Mesa 20.0.8
OpenGL core profile shading language version string: 3.30
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL version string: 3.1 Mesa 20.0.8
OpenGL shading language version string: 1.40
OpenGL context flags: (none)
OpenGL ES profile version string: OpenGL ES 3.1 Mesa 20.0.8
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.10
可以看到renderer string这一项为llvmpipe (LLVM 10.0.0, 256 bits),并不是nvidia显卡,输入glxgears画齿轮仿真,在windows任务管理器里,发现使用的还是CPU,显卡没有被占用
找了一些博客后发现需要添加一个ppa源
sudo add-apt-repository ppa:kisak/kisak-mesa
添加完成后,更新一下
sudo apt update
sudo apt upgrade
再次输入glxinfo -B,renderer string这一项还是llvmpipe,glxgears画齿轮还是没有调用显卡,
最后在找到了问题所在
https://github.com/microsoft/WSL/issues/10245
ppa:kisak/kisak-mesa这个不在提供ubuntu 18.04的支持了
更换为ppa:kisak/turtle即可
sudo add-apt-repository ppa:kisak/turtle
sudo update
sudo upgrade
glxinfo -B后输出为
name of display: :0
display: :0 screen: 0
direct rendering: Yes
Extended renderer info (GLX_MESA_query_renderer):
Vendor: Microsoft Corporation (0xffffffff)
Device: D3D12 (NVIDIA GeForce GTX 1060) (0xffffffff)
Version: 22.3.7
Accelerated: yes
Video memory: 14172MB
Unified memory: no
Preferred profile: core (0x1)
Max core profile version: 4.2
Max compat profile version: 4.2
Max GLES1 profile version: 1.1
Max GLES[23] profile version: 3.1
OpenGL vendor string: Microsoft Corporation
OpenGL renderer string: D3D12 (NVIDIA GeForce GTX 1060)
OpenGL core profile version string: 4.2 (Core Profile) Mesa 22.3.7 - kisak-mesa PPA
OpenGL core profile shading language version string: 4.20
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL version string: 4.2 (Compatibility Profile) Mesa 22.3.7 - kisak-mesa PPA
OpenGL shading language version string: 4.20
OpenGL context flags: (none)
OpenGL profile mask: compatibility profile
OpenGL ES profile version string: OpenGL ES 3.1 Mesa 22.3.7 - kisak-mesa PPA
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.10
Segmentation fault
可以看到renderer string这一项已经变为D3D12 (NVIDIA GeForce GTX 1060),成功识别到显卡!
glxgears画齿轮成功调用显卡!