当前位置:网站首页>Virtual machines use host graphics cards (Hyper-V and wsl2)
Virtual machines use host graphics cards (Hyper-V and wsl2)
2022-07-29 09:28:00 【Qwertyuiop2016】
My system version
I have updated to the latest version , This can avoid a lot of unnecessary trouble .
WSL2+Ubuntu20.04+CUDA
Enable WSL2+ install Ubuntu20.04
This is very simple , Please have a look at :https://blog.csdn.net/RenLJ1895/article/details/122741040
Host installation WSL Cuda Driver.
The latest graphics card drivers have included WSL Cuda drive , So the graphics card driver has been updated to the latest version , You don't have to reinstall . in addition :WSL2 Of Ubuntu There is no need to install any driver related to the graphics card in the system
My graphics card driver version
WSL2 Ubuntu install cuda and cudnn
cuda
This and then Ubuntu Installation doesn't make much difference ,CUDA Installed command view address :https://developer.nvidia.com/cuda-toolkit-archive
The version I chose was 11.6.0, And then Ubuntu Inside, click the following commands one by one and wait for the installation to complete .
to update ~/.bashrc
file
# Copy these three lines to the bottom of the file
export CUDA_HOME=/usr/local/cuda
export PATH=$PATH:$CUDA_HOME/bin
export LD_LIBRARY_PATH=/usr/local/cuda-11.6/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
# Update bashrc file
source ~/.bashrc
# Update the dependencies you may need
sudo apt-get install freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libgl1-mesa-glx libglu1-mesa libglu1-mesa-dev
# Check with the following code cuda Is the check successful , Pay attention to cuda The version is that you are toolkit Download what was decided there , This version may be similar to nvidia-smi The version number displayed is different , It can be high or low , This is because nvidia to cuda Opened two api, these two items. api As long as the difference is not too far , Basically, normal operation can be guaranteed cuda
nvcc -V
ubuntu Medium nvidia-smi Catalog re /usr/lib/wsl/lib/nvidia-smi
, You can build a soft link to /usr/local/bin
Next , You can also add this directory to the environment variable , Any implementation nvidia-smi
( It is recognized here that cuda The version is 11.7 It should be the version of the host , It doesn't matter )
cudnn
Download address :https://developer.nvidia.com/rdp/cudnn-archive ( Need to log in , Download the latest 11.x, In fact, that is 11.6)
Unzip to cuda The installation directory
# Here are the installation commands
tar -zxvf cudnn- Complete the version number by yourself .tgz
sudo cp -P cuda/lib64/* /usr/local/cuda-11.6/lib64/
sudo cp cuda/include/cudnn.h /usr/local/cuda-11.6/include/
# To change the read permission :
sudo chmod a+r /usr/local/cuda-11.6/include/cudnn.h
sudo chmod a+r /usr/local/cuda-11.6/lib64/*
install TensorFlow
I chose tensorflow-gpu==2.8.1, because 2.0 After the TensorFlow Bring it with you keras, direct import tensorflow.keras that will do . So there is no need to install additional .
Use the built-in test program
cat /usr/local/cuda/samples/README_CUDA_Samples.txt
There's a... In this file GitHub Link to :https://github.com/NVIDIA/cuda-samples
Copy the document ( If it's slow , You need some means , Don't say that )cd /usr/local/cuda/samples
git clone https://github.com/NVIDIA/cuda-samples.git
Then compile the executable cd cuda-samples
sudo make
You need to wait for more than ten minutes , The generated executable is in cuda-samples/bin/x86_64/linux/release
Catalog
The test passed , It means that there is no problem with the environment
test keras Training models
stay vscode Download Remote-WSl plug-in unit , There will be another button on the left . Open and create a directory to write code
effect ( You can see that the video memory is full , Training also ran normally )
But there are a lot of warning messages , Google searched and found no reason , Forget it , Just run
Reference link
1、https://blog.csdn.net/iwanvan/article/details/122119595
hyper-v+win10
Get ready iso Mirror image
You need to download the same image as the host system ( Mainly for the same graphics card driver , Ensure that there is no problem in copying the host graphics card driver file directly to the virtual machine )
Use hyper-v install win10 System
There is no difference in the steps
Use script configuration GPU-Pv
Download script :https://github.com/Sam-Chai/gpu-pv-ps1
Modify the two positions in the figure , The first is the name of the virtual machine , The second is the maximum video memory used by virtual machines . I set the same as the host graphics card
Then right-click to use powershell function , It is not easy to see the output information . The window flashed by
have access to Powershell ISE To run the , The opening position is as follows
take gpu.ps1 Drag the file directly to this window , Click the green execute button to see the output , If there is no error, the output will be ok
Driver.
Now open the virtual machine directly , Although you can see the information of the graphics card in the device manager , But the display code 43, Because there are drivers , But you can't directly use the driver software to download the driver .
Shut down the virtual machine , And attach the disk of the virtual machine to the host , double-click .vhdx Files can be seen in disk management ( You can also right-click disk management and select attach VHD), There may be an error , You can ignore , Because the drive letter has not been assigned . Right click to assign the drive letter
I have assigned , Once opened, it is mounted , In the figure 500G the
Then copy the host C:\Windows\System32\DriverStore\FileRepository
Under the table of contents nv First folder to virtual machine hard disk F:\Windows\System32\HostDriverStore\FileRepository
Next ( The directory needs to be built by yourself )
Then right click on the part of the disk management red circle and select detach VHD, The disk is unmounted
Then when the virtual machine is powered on, you should be able to see that the graphics card is working properly
Is it really working properly , This is really not clear , Try Master Lu first
virtual machine :
host :
There is still a big difference , And Master Lu got stuck directly in the virtual machine , You can't connect to... Until he finishes the test , embarrassed , virtual machine CPU Only for 1 nucleus , I said why is it so stuck .
Later, I'll look at the performance of playing the game , There is no need to run a model , use WSL Or it's more convenient to run directly in the host .
hyper-v install ghost Backup file
At first I didn't want to install the system , Want to back up the host system directly to ghost In the document . And then again hyper-v Restore to virtual machine , But the restored virtual machine is too laggy , It's basically inoperable , It is estimated that many drivers are incompatible , Share if installed ghost
Create a virtual machine
The other steps are the same , It's the time to choose an image , Need to choose PE Systematic ISO Mirror image , I chose micro PE Mirror image ( Download micro PE, There is generation ISO File options )
Create a new hard disk
Hard disk size ratio ghost Just make the file bigger , For example, the size of the system file I backed up is 62G, Choose a virtual hard disk 63G That's it , Choose a fixed size ( Because I see the following written better performance )
After the virtual hard disk file is generated , Is to mount this hard disk , Then copy ghost File to virtual hard disk , The purpose of this is to restore the system in the virtual machine ,ghost Files cannot be placed on the system disk , So create a disk to hold . After installing the system disk, you can uninstall
Then add the hard disk to the virtual machine
Add the content just now ghost Virtual hard disk of file
Then turn on , Normal should enter pe System
Partition and restore the system
Because I chose the second generation , The format of the partition must be GPT, Can't choose MBR, The second generation of guidance is UEFI. After the restore is successful , It needs to be repaired UEFI guide ( It may be unnecessary )
This is not a screenshot demonstration
take DVD Drive removal
Just choose a pointless Application , contain ghost The virtual hard disk of the file can also be removed
If you also fix UEFI guide , Then a file will be added to the location of the firmware , Don't worry about this
Click the boot button and then you should be able to enter the system normally ,
Reference link
1、https://www.bilibili.com/read/cv15539810
2、https://www.bilibili.com/video/BV11u411U7KJ
边栏推荐
猜你喜欢
【BERT-多标签文本分类实战】之一——实战项目总览
23考研人撑住!考研第一波弃考高峰期已经到来!
Jetpack Glance? The spring of widgets is coming
【机器学习】逻辑回归代码练习
Four types of technical solutions shared by distributed sessions, and their advantages and disadvantages
Handwritten character recognition
网络安全(6)
[Apple Developer account]06 after transferring the developer account, the annual fee of the developer is automatically renewed
乱打日志的男孩运气怎么样我不知道,加班肯定很多
MySQL事务与MVCC如何实现的隔离级别
随机推荐
[machine learning] naive Bayesian code practice
高智伟:数据管理赋能交通行业数字化转型
[unity entry program] C # and unity - understand classes and objects
C # use restsharp library to realize post request
不用Swagger,那我用啥?
OpenCV入门基础学习
Floweable advanced
User identity identification and account system practice
Random number setting and reference between parameters
The gold content of PMP certificate has been increased again and included in the scope of Beijing work residence permit
附录2-一些简单的练习
1.2.24 fastjson deserialization templatesimpl uses chain analysis (very detailed)
Flutter文本编辑器
36. JS动画
WebAssembly 2022 问卷调查结果新鲜出炉
Parameter passing mode of C language (int x) (int *x) (int & x)
Webassembly 2022 questionnaire results are fresh
PyQt5快速开发与实战 6.5 QGridLayout(网格布局)
Configuration file settings for remote connection to Windows version server redis
Shutter gradient