Tutorial: Passing through GPU to Hyper-V guest VM

Page 5 of 5 FirstFirst ... 345

  1. Posts : 52
    linux
       #41

    Can you give a look at this question that I have asked on Reddit :

    Reddit - Dive into anything

    I've asked that because I see that Ubuntu installed on the WSL2 is able to detect my GPU,but not Ubuntu installed on HyperV. But Windows installed on Hyper-V can. I was curious to understand if things are working exactly like that or if I'm making some errors during the configurations of some system and I'm getting a wrong result. Anyway,my desire is that Blender Cycles installed on Ubuntu / Hyper-V is able to detect my real GPU like it happens on Ubuntu installed on the WSL2 or Windows 11 installed on the Hyper-V with the GPU-P method,but it seems not possible,according with the reply of the user reddit BlackV :

    >no its doesnt work like that
    >wsl2 has special access to the GPU /windows partition to do this
    > hyper-v does not, you can use GPU-P, but I don't believe that will work for linux (yet)


    He does not seem to believe at 100% to what he says ; and I would like to understand if things are exactly like he says
      My Computer


  2. Posts : 16
    Win10 Pro
    Thread Starter
       #42

    No one really knows, we're all just experimenting. How did you get your Ubuntu VM from WSL2 to detect the GPU? Did you have to run that powershell script to partition it?
      My Computer


  3. Posts : 52
    linux
       #43

    For Ubuntu on the WSL2 there is nothing special to do : it's enough to install the CUDA libraries. For Hyper-V I found two tutorials :

    1) How to use Ubuntu on Hyper-V VM with Microsoft GPU-P support (dxgrknl kernel) :

    GitHub - brokeDude2901/dxgkrnl_ubuntu: Microsoft GPU-P (dxgkrnl) on Hyper-V Ubuntu VM

    (I've used the microsoft kernel 5.15).

    2) How to configure Ubuntu 21.04 VM with GPU acceleration under Hyper-V.

    Ubuntu 21.04 VM with GPU acceleration under Hyper-V...? . GitHub

    it's a nice idea to try to understand the differences between those 2 tutorials.
    Last edited by ziomario; 26 Jul 2023 at 10:25.
      My Computer


  4. Posts : 1
    W11
       #44

    Yet another account created to thanks original post Starlet7222 and the great summary step by step of mapsnrop. Just wanted to add an issue I experienced, that was giving me errors when the script tried copying the files. This comment in github solved "It was actually caused by iGPU "AMD Radeon Graphics". When I disabled it in device manager it works fine." by Jaroslav Kostal

    So with those 3 post I finally have my Nvidia discrete card access from a Hyper V machine in an asus Laptop.

    Thanks all
      My Computer


  5. Posts : 1
    Windows
       #45

    How to have multiple monitors in VM ?


    Hi
    I followed the instructions and was able to set up VM
    Can i have multiple monitors in VM ?
    Can anyone help with this ?
      My Computer


  6. Posts : 16
    Win10 Pro
    Thread Starter
       #46

    Just ran into a game complaining about Driver not supporting OpenGL inside the VM. I check the Device Manager and see a yellow exclamation next to my GPU. I shut down the VM, and on the host, I re-do Step 4 from the original post. When it finished, then i turn back on the VM, and the device manager looks clean, and the game works now. So the solution seems to still be working, at least for me
      My Computer


  7. Posts : 1
    Windows 11 Pro
       #47

    Code 43 after running scripts


    So I ran all the scripts, got no errors anywhere on the way except for the checkpoints thing, I just switched to Production Checkpoints and it's fine.

    But, my RTX is not recognized by the driver installation program (I just used that to see if it is being recognized) and on the Device Manager it does show up correctly, however it throws Code 43 and I have not found a way to fix this.

    Any ideas would be appreciated
      My Computer


  8. Posts : 2
    windows 10
       #48

    DrMemoryFish said:
    I apologise, I'm not the best when it comes to asking for help, I'm new to this platform. (if i have missed out any information, or if you require additional information, please let me know, thank you)

    I set up VM following this tutorial: Two Gamers, One GPU from your Windows PC! Hyper-V Paravirtualization Build and Tutorial - YouTube

    However, loading into the VM, I could see my GPU in Device manager with no errors, however, when I open Task Manager, i don't see my GPU.

    To test if my GPU is working on the VM, I tried to open a game, but it refused to load.
    I have the same problem I installed a game but the game wouldn't start at all. It just tries to start then disappears. Any solution for that? I have enough ram assigned and new Nvidia rtx 5070 ti is showing up in device manager but cannot run a game. Can someone help?

    - - - Updated - - -

    Hopachi said:
    Thanks.
    Tried it, it solves the drive issue indeed.

    - - - Updated - - -
    UPDATE:
    Note on the copying of the drivers from host via script:

    I tried this in a Win8.1 VM and indeed the device was detected in device manager but there are no drivers available in Win8.1 for my GPU.

    Important:
    [edit] the main requirement is: this needs a generation 2 vm, in other words: requires Win8.1 or higher installed in VM.
    This didn't worked in a live Linux Distro: only the generic Hyper-V gfx device is seen.
    And this didn't work in a Windows PE environment either.

    - - - Updated - - -


    It seems not to work with Linux guest.
    This only accepts Win8.1 or higher as guest and SAME driver version and files in host and guest.

    The partitioned GPU will get a different hardware id, logically as this isn't the entire GPU only 'a part' of it so it's a different device but with access to host capable graphics.
    Installing the driver manually in VM, through Windows update or by manufacturer driver installer will fail, so only the copy of driver from host to guest seems to work.
    How can you check what kind of GPU driver is installed in VM machines?
      My Computer


  9. Posts : 2
    windows 10
       #49

    Hyper V VM gPU passthrough gPU driver update error


    Starlet7222 said:
    I've learned so much about Hyper-V from all of the tutorials by @Kari and @Brink; that I hope I can return the favor here. I've created an account just to post this.

    My original problem: In the guest VM, my audio was out of sync when watching videos on youtube and twitter. Initially I thought it was an audio problem with the VM. Then it dawned on me that its just as likely that the video is out of sync, rather than the audio. Maybe my VM didn't have video hardware acceleration or something...

    Initial searches showed that Hyper-V actually used to have this as an option within the GUI. It was called "RemoteFX Video Adapter" that you would add under the VM settings. However, due to a security issue, this feature was removed by Microsoft.

    Next, I found something called "Discrete Device Assignment" (DDA). This looked promising, until I found out that this feature was only available on Windows Server OS, while I am on a desktop OS with Win10 Professional 21H2. Further, this DDA method might exclusively assign the device to a VM, rather than sharing it with the host or with other VMs.

    GPU Partitioning

    Finally, somehow I stumbled upon something called "GPU Partitioning". That is what this post is about. It is a method to partition off resources from your graphics card so that it can be used inside your VMs. Unfortunately, there is almost no documentation for this from Microsoft. But I've compiled together this information from all my searches.

    You can enable this feature with a some powershell commands. But the difficult part is to get the video drivers working inside the Guest VM. You DO NOT install any video drivers in the VM. Instead, you must copy the existing drivers from the host machine into the same location in the VM. If you get a "Code 43" error in Device Manager inside the VM, its likely a driver issue. Luckily, some people have scripted this to save us the hassle.

    Requires an existing Generation 2 VM.

    Steps:

    1. Test to see if your GPU can be partitioned at all. On the Host, open a Powershell prompt as administrator. Then run:
      Get-VMPartitionableGpu (win10)
      or
      Get-VMHostPartitionableGpu (win11)

    2. Open up Device Manager on the guest VM, and check the Display Adapters. You will see that your GPU is NOT enabled.
      Then shut down the VM.

    3. Go to this link: GitHub - jamesstringerparsec/Easy-GPU-PV: A Project dedicated to making GPU Partitioning on Windows easier!
      You can download the full repo if you want. But you only need these two files:
      • Add-VMGpuPartitionAdapterFiles.psm1
      • Update-VMGpuPartitionDriver.ps1

    4. From the admin powershell console, run this command:
      .\Update-VMGpuPartitionDriver.ps1 -VMName "Name of your VM" -GPUName "AUTO"
      Just edit that command with the name or your VM. GPU "AUTO" will automatically determine your GPU. These scripts will find all the driver files from your host machine, and copy the files to the VM. This can take some time.

    5. With the VM still off, create a new .ps1 powershell file on the host, and paste in this code:
      Code:
      $vm = "Name of your VM"
      if (Get-VMGpuPartitionAdapter -VMName $vm -ErrorAction SilentlyContinue) {
         Remove-VMGpuPartitionAdapter -VMName $vm
      }
      Set-VM -GuestControlledCacheTypes $true -VMName $vm
      Set-VM -LowMemoryMappedIoSpace 1Gb -VMName $vm
      Set-VM -HighMemoryMappedIoSpace 32Gb -VMName $vm
      Add-VMGpuPartitionAdapter -VMName $vm
      This script will enable the GPU partitioning for your VM, and turn on some required settings.

    6. Edit the first line and again put the name of your VM. Then run this script file in your powershell prompt by preceeding the filename with .\ just like you did with the previous script above.

    7. Now we should have the drivers copied into the VM, and the GPU partitioning feature enabled. You can now turn on the VM, and go back to Device Manager and see if your GPU is now shown under Display Adapters


    My solution above is to enable your GPU on an already existing VM. If you are willing to create a new VM from scratch, you could use all the files from the github repository in Step 3. However it also installs some extra software that you might not need.

    As far as I understand, everytime you update your graphics drivers on your host, you will similarly need to copy those new drivers into the guest VMs as well. We simply repeat Step 4 to do this.

    In the resource links below, you will see that there are other partitioning settings that you can play with, but they were unnecessary for me. Also I read that this GPU passthrough feature would require that I turn off both dynamic memory, and checkpoints. But this was not required for me. I left both enabled, and got no errors. If you get errors, try turning those off.

    And to bring it full circle, after doing this, my GPU is correctly shown in Device Manager, and my audio/video lag on youtube inside the VM is gone.


    Resources:
    GPU partitioning is finally possible in Hyper-V : sysadmin
    I made a Powershell script to automate the creation of GPU-P enabled Hyper V VMs - Servers and NAS - Linus Tech Tips
    GPU Virtualization with Hyper-V – James' Personal Site
    Running FiveM in a Hyper-V VM with full GPU performance for testing ("GPU Partitioning") - Cookbook - Cfx.re Community
    https://forum.level1techs.com/t/2-ga...-hyperv/172234
    Thank you for the explanation. it is great info. My question is how do you update the driver in Hyper V VM. After I did all the scripts, Nvidia card was showed in Hyper V VM but GPU driver is still Microsoft video driver. I tried to update the driver using Easy GPU passthrogh GPU update script, I got this error:


    PS C:\Windows\system32> C:\Users\Tree of Life\Desktop\Easy-GPU-PV-main\Update-VMGpuPartitionDriver.ps1
    Get-VM : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null
    or empty, and then try the command again.
    At C:\Users\Tree of Life\Desktop\Easy-GPU-PV-main\Update-VMGpuPartitionDriver.ps1:21 char:22
    + $VM = Get-VM -VMName $VMName
    + ~~~~~~~
    + CategoryInfo : InvalidData: (:) [Get-VM], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.HyperV.PowerShell.Commands.GetVM

    Get-VHD : Cannot validate argument on parameter 'VMId'. The argument is null or empty. Provide an argument that is not
    null or empty, and then try the command again.
    At C:\Users\Tree of Life\Desktop\Easy-GPU-PV-main\Update-VMGpuPartitionDriver.ps1:22 char:22
    + $VHD = Get-VHD -VMId $VM.VMId
    + ~~~~~~~~
    + CategoryInfo : InvalidData: (:) [Get-VHD], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Vhd.PowerShell.Cmdlets.GetVHD

    Attemping to shutdown VM...
    Stop-VM : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not
    null or empty, and then try the command again.
    At C:\Users\Tree of Life\Desktop\Easy-GPU-PV-main\Update-VMGpuPartitionDriver.ps1:30 char:19
    + Stop-VM -Name $VMName -Force
    + ~~~~~~~
    + CategoryInfo : InvalidData: (:) [Stop-VM], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.HyperV.PowerShell.Commands.StopVM

    Waiting for VM to shutdown - make sure there are no unsaved documents...

    How to fix this? Thank you in advance.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 04:00.
Find Us




Windows 10 Forums