Beginners: Building your own GPU cloud on consumer hardware & software
Sometimes heavy compute needs don't scale well across multiple GPUs, requiring virtualization to make the best use of hardware.
The good news is that setting up virtual machines to make use of GPUs is straightforward and only takes maybe half an hour to configure - even if you only have a single GPU you want to spread across several VMs!
Prepping Windows
You'll need to enable Hyper-V, Microsoft's native hypervisor, in Windows:
Verifying prerequisites
You'll need a motherboard, GPU and OS that support virtualization and paravirtualization of hardware. Fortunately, a lot of consumer-level hardware does.
To check if your motherboard supports virtualization in its BIOS, the process varies on whether your system is AMD or Intel based:
In terms of OS, we'll be using Windows 11 Pro in this guide, but it should also work in Windows 10 Pro, or any recent edition of Windows Server. As always, you could use Linux, but it's a different process than this guide.
Lastly, to see if your GPU is compatible in Windows 11 Pro, open an elevated (run as admin) PowerShell prompt and enter the following:
Get-VMHostPartitionableGpu
If you are running Windows 10 Pro, the command is:
Get-VMPartitionableGpu
This will return all GPUs available for paravirtualization on the host.
If all this looks good, then go download a Windows 11 Pro ISO from Microsoft. If you are using Windows 10 Pro, go download an ISO that matches your OS. We'll need it later when we set up the virtual machine.
Lastly, before we proceed, update your graphics drivers to the newest available.
Configuring the hypervisor
To support GPU paravirtualization, you'll need to disable Enhanced Session Mode:
Next, we'll set up a virtual network switch so your virtual machines can access the internet:
Virtual machine setup
You'll now see a new virtual machine in Hyper-V, but before we fire it up, there's a few settings that we have to change to support Windows 11 installation as well as GPU paravirtualization.
Configuring the virtual machine
With all of these changes in place, you should now be able to run the virtual machine and install Windows as you normally would. If the machine instantly crashes while booting into the installation media, try holding the spacebar as you turn on the VM.
Driver setup
GPU paravirualization requires some manual copying of drivers from your parent OS to the virtual OS. Below is the process for Nvidia GPUs - a similar process can be followed for AMD:
Next, we need to get these files you've copied into the VM's virtual hard disk:
Please note that if you update the drivers on the parent OS running the hypervisor, you will need to redo this process to update the drivers on your virtual machine(s).
领英推荐
Final VM configuration
Open an elevated PowerShell prompt, and enter the following commands one by one replacing YourVMNameHere with what you named the VM in Hyper-V. They configure memory spaces and cache settings for the virtual machine and what the machine should do when turned off (a requirement for paravirtualization):
Set-VM -GuestControlledCacheTypes $true -VMName YourVMNameHere
Set-VM -LowMemoryMappedIoSpace 3Gb -VMName YourVMNameHere
Set-VM -HighMemoryMappedIoSpace 33280Mb -VMName YourVMNameHere
Set-VM -Name YourVMNameHere -AutomaticStopAction TurnOff
Assigning the GPU
This is the moment it all comes together.
First, we need to get the location path of your GPU:
In an elevated PowerShell prompt, run the following command to tell the hypervisor to give the VM up to 100% of the GPU:
Add-VMGpuPartitionAdapter -VMName "YourVMNameHere" -InstancePath "YourDevicePathHere"
That's it! Fire up your VM and go look in Device Manager to see your paravirtualized GPU.
Appendix: Splitting up your GPU(s)
You don't have to assign up to 100% of the GPU to a single VM, you can divide each GPU into up to 32 blocks that you can assign to different VMs. This is useful when the VM is will be tasked with things that won't utilize an entire GPU. See here for more info regarding how to do this as a starting point.
Appendix: DDA vs paravirtualization
Since the GPU is still being managed by the hypervisor OS when paravirtualizing, you are losing a small amount of performance and adding a small amount of latency. For most use cases, this is negligible.
However, professional cards and the latest consumer Nvidia cards support removing the GPU entirely from the host OS and having the VM entirely run the card which removes this performance overhead. This is called DDA (Discrete Device Assignment).
You need to be running Windows Server 2016 or later for this.
The card must support SR-IOV (Single-root input/output virtualization). On the Nvidia side, Ada Lovelace consumer GPUs seem to support this as well as newer Quadro cards.
The setup process for this looks a little different at the end:
In an elevated PowerShell prompt, enter the following command to remove the GPU from showing up to the parent OS:
Dismount-VMHostAssignableDevice -Force -LocationPath "YourDevicePathHere"
You should see the GPU vanish from your device manager.
Next, assign it to the VM with the following command:
Add-VMAssignableDevice -LocationPath "YourDevicePathHere" -VMName YourVMNameHere
Now you should be able to boot up your VM and see the GPU there as you would have in the parent OS. If Hyper-V errors out when launching the VM saying that "A hypervisor feature is not available to the user." It is likely you aren't running a Windows SKU with access to DDA, or your GPU doesn't support being directly passed to the virtual OS.
Appendix: Troubleshooting
Setting up VMs with GPUs often run into issues that surface when you try to boot up your VM or see an Error 43 in Device Manager on the GPU within the VM.
This often seems to be related to IOMMU (Input-Output Memory Management Unit) settings - which can be remedied by changing your computer's Core Isolation Memory Integrity settings: