Imagine I have a proxmox server with four active desktop, two windows and two linux
Is it possible to swap the GPU between the VM at will and efficiently ?
I am curious if GPU passthrough settings can be changed at all while the VM is running, to begin with ?
Then, does swapping the GPU causes the VMs to crash or the GPU itself to enter a crash state ?
How long does it take, say, compared with the time of switching betweem ports of a KVM ?
Would it make sense to Live snap shot and suspend the VMs, connect the GPU to the desired one and then unfreeze it ? And then when you switch again, freeze the VM, switch gpu, unfreeze new VM ?
Would the GPU need to "reboot" between this swapping ? Is it going to be like pressing ctrl+win+shift+b and restarting the video system each time ?
Would it cause a running, 3d or video compression using application to crash ?
What happens if two VMs are trying to GPU passthrough at the same time ? They both crash and crash the GPU ?
How do I implement easy switching logic to work from where I am interacting these VMs ?
That was a lot of questions, I wanted to create this list first and put it out there to find if there are other people trying this.
What I have in mind is, multiple things really.
First would be my desktop computer, running proxmox, all my screens are connected to the physical GPU. Right now it just shows the proxmox login prompt.
I would like the physical outputs to display the content of the VM instead of the content of the proxmox host.
I also access my VMs, from other computers, in fullscreen using moonlight/sunshine, but when the GPU detaches, my moonlight client will become unoperative. So the scripts have to be efficient, I run the script and reconnect, it should be the new VM, or else I will have to start logging into the console and stuff and that's not going to a good experience.
And then there will be more complications, such as VM and CT containers running parrallal AI applications such as stable diffusion and oogabooga text generator UI, which need the host to use the GPU, and it's unclear how I can swap between passthrough GPU and host using GPU without rebooting the entire thing !
Please consider the following proxmox support forum question
And break it down in terms of individual goals
------------------------------
This Proxmox support forum post contains several distinct technical goals and questions about dynamically swapping a GPU between multiple virtual machines (VMs) and containers (CTs) efficiently. Let’s break down the post into its individual goals and questions:

Primary Goals :​

  1. Dynamically Swap a GPU Between VMs at Will :
    • The user wants to swap the GPU between VMs efficiently and on demand.
    • Efficient Switching Without VM or GPU Crashes :
      • The user wants to understand if switching the GPU while the VM is running is possible, and whether such switching could cause crashes for the VMs or the GPU.
      • Minimal Downtime During GPU Swapping :
        • The user is concerned about how long it takes to switch the GPU between VMs and wants a comparison with switching between ports on a KVM (keyboard-video-mouse) switch.
        • VM Suspension for Safe GPU Switching :
          • The user proposes the idea of suspending or freezing VMs (taking live snapshots), switching the GPU to the new VM, and unfreezing the VMs to minimize downtime. They are seeking advice on whether this is a reasonable approach.
          • Behavior of GPU When Swapped :
            • The user is asking if the GPU needs to "reboot" or restart each time it’s swapped between VMs and if this would be similar to pressing a key combination (Ctrl+Win+Shift+B) to reset the video system.
            • Impact on GPU-Intensive Applications :
              • The user is concerned about whether applications like 3D rendering or video compression running on a VM could crash when the GPU is swapped.
              • Handling Multiple VMs Trying to Use GPU Passthrough Simultaneously :
                • The user wonders what happens if two VMs attempt to use the GPU at the same time. Specifically, they are concerned about both VMs and the GPU crashing due to simultaneous access attempts.

Secondary/Implementation Goals :​

  1. Efficient Scripted GPU Switching :
    • The user is looking to automate and streamline the process of switching the GPU between VMs, using scripts that ensure the Moonlight/Sunshine streaming service reconnects to the correct VM without manual intervention.
    • Output VM Display to Physical GPU Ports :
      • The user wants the physical GPU outputs (which currently display the Proxmox host interface) to switch and display the contents of a VM instead.
      • Handle GPU Sharing Between VMs and Host (AI Workloads) :
        • The user needs to juggle both VM GPU passthrough for desktops and the host itself using the GPU for container-based AI applications (e.g., Stable Diffusion, Oogabooga UI). They are concerned about how to handle GPU passthrough for VMs and still allow the host to use the GPU without frequent reboots.

Key Questions from the Post :​

Possible Solutions/Implementation Considerations :​