Assign nVidia GPU to Hyper-V Virtual Machine

assign-nvidia-gpu-to-hyper-v-virtual-machine

If you have a server which has few or more GPUs installed and you want to offload one of them to VM, you can use instructions below:

Step 1: Start Power shell in Admin

VM1 – this is the name of virtual machine for which we will make changes
PCIROOT(0)#PCI(0300)#PCI(0000) – please find it via devicemanager, select the gpu, then go to details and location paths.
You need to turn off VM before proceeding below.
VM1 Settings -> Management -> Automatic stop action -> Turn off the virtual machine

Step 2: Execute command one by one

$VM=’VM1′
Set-VM $VM -GuestControlledCacheTypes $true
$Location = ‘PCIROOT(0)#PCI(0300)#PCI(0000)’

Set-VM $VM -LowMemoryMappedIoSpace 3GB
Set-VM $VM -HighMemoryMappedIoSpace 8GB

Please disable the GPU in Device manger

Dismount-VMHostAssignableDevice -force -LocationPath $Location
Add-VMAssignableDevice -LocationPath $Location -VMName VM1

Step 3: Turn on VM and install nvidia drivers