Swapping between GPUs on QEMU passthrough

This is mostly asking for a friend of my.

He wants to use A4000 and GTX 970 in 1 pc (he has a spare gpu, that’s why it’s a 970), and wants to swap between which goes in VM and which goes for localhost.
Can this be done? he said he’ll do the software automating if required. I just need a concrete answer and minor explanation on how to. That’s all. Thank you in forward

I don’t think there’s a provision for hot-swapping PCIe passthrough GPUs in KVM.

More importantly, there is absolutely no provision for hot-removal of the primary GPU in X. I believe this can be done in Wayland, but not X.

He generally just needs a way to swap it after he shuts the vm. Not mid-running the vm. Restarting the PC is applicable too. But ty on that answer

Personally I solved a similar issue by making a linux VM for playing with ML. So I can stop one VM and start another to swap GPUs between Windows / Linux. A tool like https://looking-glass.io/ can also be handy if you’re between VMs (view output of one GPUin VM on host or in another VM).

Also does the A4000 support vGPU? IIRC the professional nvidia GPUs support that.

You would definitely need to reboot the PC to swap the GPUs. When doing gpu passthrough to VM, it is generally done using a VFIO driver. There are tons of guides on how to do this. Personally, i do it through Grub… in theory a script could be written to change the grub command and run a grub update.

One of the posters suggested VGPU to split the GPU. I could be mistaken, but i am pretty certain you can’t use the ports on the video card when using VGPU, so you would need to remote into the machine.