{"id":9757,"date":"2024-06-11T12:06:41","date_gmt":"2024-06-11T12:06:41","guid":{"rendered":"https:\/\/cheapwindowsvps.com\/blog\/step-by-step-guide-to-gpu-passthrough-in-hyper-v-virtual-machines\/"},"modified":"2025-01-20T11:32:57","modified_gmt":"2025-01-20T11:32:57","slug":"step-by-step-guide-to-gpu-passthrough-in-hyper-v-virtual-machines","status":"publish","type":"post","link":"https:\/\/cheapwindowsvps.com\/blog\/step-by-step-guide-to-gpu-passthrough-in-hyper-v-virtual-machines\/","title":{"rendered":"Step-by-Step Guide to GPU Passthrough in Hyper-V Virtual Machines"},"content":{"rendered":"<p>The feature <strong>RemoteFX vGPU<\/strong> was previously accessible in older Hyper-V versions (starting from Windows 7 and Windows Server 2008 R2) to allocate a host&#8217;s discrete GPU to a virtual machine. However, with the release of Windows 10 version 1809 and Windows Server 2019, the support for RemoteFX was discontinued. The upgraded feature, <strong>Discrete Device Assignment (DDA)<\/strong>, is now recommended.<\/p>\n<p>Discrete Device Assignment permits the passthrough of physical host PCI\/PCIe devices such as GPUs and NVMes directly to a Hyper-V virtual machine. The essential prerequisites for implementing DDA in Hyper-V include:<\/p>\n<ul>\n<li>Exclusively applicable to Hyper-V Gen 2 virtual machines;<\/li>\n<li>Virtual machines must have both dynamic memory and checkpoints disabled;<\/li>\n<li>The physical graphics card needs to support GPU Partitioning;<\/li>\n<li>If <a href=\"https:\/\/woshub.com\/install-wsl-windows-subsystem-linux\/\" target=\"_blank\" rel=\"nofollow noopener\">WSL (Windows Subsystem for Linux)<\/a> is active on the host system, the VM might display a code 43 video error when the graphics card is used with GPU-P;<\/li>\n<li>Despite <a href=\"https:\/\/woshub.com\/configure-sr-iov-hyperv-vm\/\" target=\"_blank\" rel=\"nofollow noopener\">SR-IOV (Single Root Input\/Output Virtualization)<\/a> not being a mandatory requirement for DDA, GPU passthrough will face issues without its support.<\/li>\n<\/ul>\n<p>Discrete Device Assignment is only available on Windows Server with the Hyper-V role. In the desktop Windows 10 and 11, you can use GPU partitioning to share the video card with the virtual machine. This article describes how to assign a physical GPU to a virtual machine on Hyper-V.<\/p>\n<div><a href=\"https:\/\/woshub.com\/vmware-esxi-usb-device-passthrough-to-virtual-machine\/\" target=\"_blank\" rel=\"nofollow noopener\">VMware PCI Passthrough (VMDirectPath)<\/a> is the VMware equivalent of this feature.<\/div>\n<h2>Enable GPU Passthrough to Hyper-V VM on Windows Server<\/h2>\n<p>Discrete Device Assignment (DDA) allows PCIe devices to be passed through to a virtual machine on Windows Server 2016 and newer.<\/p>\n<p>Before assigning the GPU to the VM, you must change its configuration.<\/p>\n<p>Disable Hyper-V automatic snapshots for VM (described in the post Manage <a href=\"https:\/\/woshub.com\/hyper-v-vm-automatic-startup-boot-order\/\" target=\"_blank\" rel=\"nofollow noopener\">VM startup and boot order on Hyper-V<\/a>).<\/p>\n<p><code>Set-VM -Name munGPUVM1 -AutomaticStopAction TurnOff<\/code><\/p>\n<p>Configure cache and memory limits for 32-bit MMIO space:<\/p>\n<p><code>Set-VM -Name munGPUVM1 -GuestControlledCacheTypes $True -LowMemoryMappedIoSpace 3Gb -HighMemoryMappedIoSpace 33280Mb<\/code><\/p>\n<p>Next, determine the physical path to the graphics card\u2019s PCIe device on the Hyper-V host. To achieve this, access the GPU Properties via Device Manager, switch to the <strong>Details<\/strong> tab, and locate the <strong>Location Paths<\/strong> property. Look for and copy the value that begins with <em>PCIROOT<\/em>.<\/p>\n<p>Alternatively, you can use PowerShell to retrieve this path value:<\/p>\n<p><code>Get-PnpDevice | Where-Object {$_.Present -eq $true} | Where-Object {$_.Class -eq \"Display\"}|select Name,InstanceId<\/code><\/p>\n<p>Disable this graphics card on the Hyper-V server in Device Manager or using PowerShell:<\/p>\n<p><code>Dismount-VmHostAssignableDevice -LocationPath \"PCIROOT(0)#PCI(0300)#PCI(0000)\" \u2013force<\/code><\/p>\n<p>Now connect the physical host GPU adapter to the virtual machine:<\/p>\n<p><code>Add-VMAssignableDevice -VMName VMName -LocationPath \"PCIROOT(0)#PCI(0300)#PCI(0000)\"<\/code><\/p>\n<p>Then power on the VM and check that your GPU appears in the <strong>Display Adapters<\/strong> section of the Device Manager, along with the <em>Microsoft Hyper-V Video<\/em> device.<\/p>\n<div>VM must have graphics drivers preinstalled.<\/div>\n<p>To disconnect the GPU from the VM and connect it to the host:<\/p>\n<p><code>Remove-VMAssignableDevice -VMName munGPUVM1 -LocationPath $locationPath<br \/>\nMount-VMHostAssignable<\/code><\/p>\n<p>Device -LocationPath $locationPath<\/p>\n<h2>Sharing the Physical GPU with Hyper-V VM on Windows 10 or 11<\/h2>\n<p>GPU Partitioning (GPU-P) is now supported in Hyper-V virtual machines that are equipped with Windows 10\/11 starting from build 1903 onwards.<\/p>\n<p>To determine if your video card is compatible with GPU partitioning, you can use the <strong>Get-VMPartitionableGpu<\/strong> command on Windows 10 or the <strong>Get-VMHostPartitionableGpu<\/strong> on Windows 11.<\/p>\n<p>To allocate a video adapter from the host to a virtual machine, execute the <strong>Add-VMGpuPartitionAdapter<\/strong> cmdlet. Transfer the graphics card drivers from the Hyper-V host to the virtual machine using the <strong>Easy-GPU-PV<\/strong> script available at <a href=\"https:\/\/github.com\/jamesstringerparsec\/Easy-GPU-PV\" target=\"_blank\" rel=\"nofollow noopener\">https:\/\/github.com\/jamesstringerparsec\/Easy-GPU-PV<\/a>.<\/p>\n<p>After downloading, unzip the script archive into a designated folder on your Hyper-V host.<\/p>\n<p>Open an elevated PowerShell console, then allow running PowerShell scripts in the current session.<\/p>\n<p><code>Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass \u2013Force<\/code><\/p>\n<p>Run the script:<\/p>\n<p><code>.Update-VMGpuPartitionDriver.ps1 -VMName myVM1 -GPUName \"AUTO\"<\/code><\/p>\n<p>The script copies the GPU drivers from the host to the VM.<\/p>\n<p>Now change the VM settings and assign the GPU to it:<\/p>\n<p><code>Set-VM -VMName myVM1 -GuestControlledCacheTypes $true -LowMemoryMappedIoSpace 1Gb -HighMemoryMappedIoSpace 32Gb<br \/>\nAdd-VMGpuPartitionAdapter -VMName myVM1<\/code><\/p>\n<p>If you have updated the video drivers on the Hyper-V host, you must also update them on the virtual machine.<\/p>\n<p><code>.Update-VMGpuPartitionDriver.ps1 -VMName myVM1 -GPUName \"AUTO\"<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The feature RemoteFX vGPU was previously accessible in older Hyper-V versions (starting from Windows 7 and Windows Server 2008 R2) to allocate a host&#8217;s discrete GPU to a virtual machine. However, with the release of Windows 10 version 1809 and Windows Server 2019, the support for RemoteFX was discontinued. The upgraded feature, Discrete Device Assignment [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":9758,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[135,117,98,99,100],"tags":[],"class_list":["post-9757","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-hyper-v","category-powershell","category-windows-10","category-windows-11","category-windows-server-2019"],"_links":{"self":[{"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/posts\/9757","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/comments?post=9757"}],"version-history":[{"count":1,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/posts\/9757\/revisions"}],"predecessor-version":[{"id":10447,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/posts\/9757\/revisions\/10447"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/media\/9758"}],"wp:attachment":[{"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/media?parent=9757"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/categories?post=9757"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/tags?post=9757"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}