Can I Use My GPU In A VM? (Using GPUs in Virtual Machines)

It’s not easy to give a guest computer full access to a GPU’s resources in a virtual setup. Some people even recommend using virtual GPU (vGPU) to simplify the setup. So, can you really use your GPU in a virtual machine (VM)?

You can use your GPU in a virtual machine, but it needs a combination of software and hardware that supports GPU or PCIE passthrough. You also need to use virtualization software that allows you to assign a physical GPU and a compatible graphics card, making it more complicated than a virtual GPU.

This article will discuss everything you need to know when setting up a virtual machine. If you want to find out how to assign a physical GPU to a VM and make it fully accessible to a guest computer, keep reading.

Can I use my GPU in VM?

How To Assign a GPU to Your Virtual Machine

Assigning a physical GPU to your virtual machine can be tricky because there are several variables you need to optimize to make it work. 

Requirements to Successfully Use a GPU in a Virtual Machine 

Although it’s possible, you need the following for your setup to work properly:

  • Virtualization software that supports GPU passthrough. Some VM programs don’t have this feature because it creates complexities that can cause issues in the operation of the host and guest computers. GPU passthrough makes it possible for another computer to have direct access to the physical GPU, providing better performance when compared to a vGPU or GPU sharing.
  • An operating system that allows GPU or PCIE passthrough. Linux is the most popular OS when making a physical GPU accessible by a guest computer. While you can enable GPU passthrough in Windows or macOS, you’ll need additional hardware and software to make this type of virtualization possible.
  • A GPU that’s compatible with your VM program. Although many businesses already use a virtual machine, the practice still isn’t mainstream, so some GPUs don’t work with VM programs. You have to find a VM program that works with your GPU or vice versa and ensure that it supports GPU or PCIE passthrough before you can set it up.

A graphics card is one of the most expensive parts of any computer build. Your options will be limited if you already have one and want to use it for your virtual machine. You may have to replace your VM software or the operating system before you can assign a GPU to your virtual machine.

The Best Software to Use When Assigning a GPU to a Virtual Machine 

Some graphics cards and VM programs won’t have passthrough capability by default. You’d need to manually enable it, use a specific driver, or update your GPU’s firmware before you can assign your GPU to a virtual machine.

Here are some of the Virtual Machine (VM) Programs with GPU passthrough that you can use:

  • VMware Horizon View: This VM app works with Linux, Windows, and macOS (Catalina or later) and is your best option if you don’t want to change operating systems for your setup. All you have to do is determine whether the graphics card you’re using is compatible with VMware.
  • Hyper-V: This is a Microsoft-developed VM program that works with Windows and Linux distros like Ubuntu, CentOS, Red Hat, and SUSE. It’s the best VM program you can use with Windows because it was specifically developed to take advantage of Windows features for virtualization.
  • KVM (Kernel-based Virtual Machine): This is the most powerful virtualization program you can use for Linux. It supports GPU passthrough and makes it easy for anyone to create and manage virtual machines.

You may still find other virtualization software with GPU passthrough support, but you’d have to check their official website for OS and GPU compatibility. Doing this ensures that the system you’re building will give your guest computer full access to the resources you have on your virtual machine.

How to Assign a GPU to a Virtual Machine Using VMware Horizon View

Depending on your virtualization software, there are several ways to virtualize a GPU. However, for this article, I’ll cover the steps to do it using VMware Horizon View because it works with Windows, Linux, and macOS and is compatible with many GPUs.

The steps below are similar to other programs you can use, so this should give you an idea of how to assign a GPU to your virtual machine using most software. Here’s how to do it:

  1. Enable the virtualization technology for the platform you’re using. It can be Intel VT-d (here’s how to enable or disable Intel VT-d) for an Intel platform or AMD IOMMU (here’s how to enable or disable AMD IOMMU) for AMD builds. 
  2. Download and install the GPU drivers on your guest computer. Since there’s no GPU installed on the guest computer, the system won’t be able to detect the display drivers you need. You’ll have to jump online and download the drivers from the manufacturer’s website and manually install them on the computer.
  3. Add the GPU to the virtual machine hardware settings. If you’re using multiple GPUs, select the one you want to assign to the guest computer. VMware can detect it automatically if you only have one in your virtual machine.
  4. Restart the virtual machine. This will allow you to set the GPU as the primary display device.
  5. Turn on the guest computer and select the GPU as the primary display device. After setting this up, your guest computer will be able to use all the resources from the virtual machine as if it’s using a physical GPU.
  6. Check to see if VMware is using the right GPU. If you can set the VMware program up correctly, it’ll start being used as soon as you run a program that requires a GPU. It’ll also detect the graphics card you’re using as if it’s installed physically on the computer.

The steps may differ depending on your VMware version, but the difference is small, and the process will feel familiar. 

And even if you’re using a different virtualization program, these steps will still help you navigate the process of virtualizing your GPU.

The process in the tutorial above may not be the best solution for many people because it involves modifying the script within your operating system. However, it works with a lot of different virtualization programs. 

You only need to be familiar with PowerShell and know how to revert the changes you made if they don’t work on the program you’re using.

It’d be prudent to try this process on a dummy OS first, as you can reformat it if the process doesn’t work for your setup. It saves you from the risk of messing up with your primary OS and being unable to reverse what you did.

Things To Remember When Assigning a GPU to a Virtual Machine

Assigning a GPU to your virtual machine will give a guest computer untethered access to the resources it needs for computing. It’s one of the best ways to improve the cost-efficiency of GPUs and the speed of the computers using them.

However, it’s not always the best solution for a virtual machine. There are still a few things to consider to ensure you’re getting the most out of your GPU and that the user experience for both the host and guest computer will be smooth and stable.

Ensure You Maintain Hardware and Software Compatibility

Aside from checking the compatibility of your hardware and software, you must also ensure that you keep them updated and check that they maintain compatibility. Some virtualization programs may drop support for a GPU model after an update, which can be an issue for your virtual machine.

When this happens, you can only choose between upgrading your GPU to one supported by the program you’re using or finding a program that works with your graphics card and has passthrough support.

It’s also advisable to keep your operating system, drivers, and virtualization software up-to-date to prevent issues with the operation.

Remember, assigning a GPU to your virtual machine requires a combination of hardware and software, so you always need to monitor the ones you’re using to ensure they’re all updated and will work properly.

Assigning a GPU to a Virtual Machine Makes Your System Less Secure

Assigning a GPU to your virtual machine can create potential security risks because you’re opening up your system to other computers. Aside from this, you’re also changing the settings within your computer to provide access to files that a guest computer shouldn’t be able to access.

Although assigning a GPU to your virtual machine can provide many advantages, you must be careful when using it. 

You also need to take additional steps to ensure that important files remain inaccessible from the guest computers, which wouldn’t be an issue if you’re only using vGPU (virtual GPU) or GPU sharing.

Only Assign a GPU to a Virtual Machine When Necessary 

Assigning a GPU to your virtual machine requires a more complex setup that can create potential security risks. It can also affect the stability of the host computer, the virtual machine, and the guest computer.

So, before assigning a GPU to your virtual machine, it would be best to consider the workload you’ll be doing on the guest computer. 

Unless you plan to use a resource-intensive program on the guest computer, GPU sharing or vGPU can still provide you with the necessary resources without the complexities and potential risks.

Although the resources you’ll get from these two techniques are limited, it’s easier and safer when compared to changing the settings in your host computer to enable GPU passthrough. 

This also restricts the guest computer from accessing sensitive files that should only be accessible to the host computer.

If you can handle the workload without GPU virtualization, assigning a GPU to a virtual machine may not be worth the trouble. 

Advantages of GPU Virtualization

To help you determine whether you should assign a GPU or simply take advantage of GPU sharing or vGPU, here are some of the benefits that you can get from GPU virtualization:

  • It helps you improve the efficiency of your GPU. Unlike the CPU, your GPU only works when it needs to process graphics data from the CPU. If you’re using GPU virtualization, your GPU becomes more efficient because it “works” for two different computers that can access all its resources.
  • It helps eliminate system bottlenecks. Although GPU sharing and vGPU work well with most tasks, your resources will be limited based on how you configure your virtual machine. This can create performance bottlenecks that won’t be present if you have GPU passthrough.
  • It enables a guest computer to run graphics-intensive apps. This is perhaps the biggest advantage of assigning a GPU to a virtual machine. It’s often the only reason why people even consider it. Running graphics-intensive apps may not be possible if you’re only using vGPU or GPU sharing.
  • It provides untethered access to resources. If you assign a GPU as a primary display device, you’ll have access to all the resources you need for your tasks. Both host and guest computers will work simultaneously and have similar performance. It’s like having two computers, but you’ve only upgraded the hardware for the host.

Conclusion

Assigning a GPU to your virtual machine is possible, but the process may not be as straightforward as using vGPU or GPU sharing.

It’ll require you to change some settings within your computer to enable GPU passthrough, which is necessary for virtualizing your GPU.

However, once you find the right combination of hardware and software for virtualization, you’ll have access to many different advantages that aren’t possible for vGPU or GPU sharing.

That’s why a lot of people go to the trouble of ensuring that they have the right setup that’ll allow them to virtualize their GPUs.