GPU Acceleration & Passthrough #38

Open
opened 2025-12-28 23:22:09 +01:00 by adam · 11 comments
Owner

Originally created by @sickcodes on GitHub (Jun 15, 2020).

As per the virt-manager xml on king @kholia's repo:

https://github.com/kholia/OSX-KVM/blob/master/macOS-libvirt-Catalina.xml

I have an iGPU and it's difficult for me to test

    <!-- If you wanna passthrough GPU, make sure the gfx and audio are in the same bus (like 0x01) but different function (0x00 and 0x01)-->
    <!-- <hostdev mode='subsystem' type='pci' managed='yes'>
      <driver name='vfio'/>
      <source>
        <address domain='0x0000' bus='0x2d' slot='0x00' function='0x0'/>
      </source>
      <rom file='/mnt/disks/backups/BIOS/RX580/Ellesmere.rom'/>
      <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0' multifunction='on'/>
    </hostdev>
    <hostdev mode='subsystem' type='pci' managed='yes'>
      <driver name='vfio'/>
      <source>
        <address domain='0x0000' bus='0x2d' slot='0x00' function='0x1'/>
      </source>
      <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x1'/>
    </hostdev> -->
    <!-- If you wanna passthrough onboard audio(like 30:00.4), make sure you put it in bus 0x00 and slot 0x0y(y is numeric), otherwise AppleALC won't recognized it -->
    <!-- <hostdev mode='subsystem' type='pci' managed='yes'>
      <driver name='vfio'/>
      <source>
        <address domain='0x0000' bus='0x30' slot='0x00' function='0x4'/>
      </source>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
    </hostdev> -->
Originally created by @sickcodes on GitHub (Jun 15, 2020). As per the virt-manager xml on king @kholia's repo: https://github.com/kholia/OSX-KVM/blob/master/macOS-libvirt-Catalina.xml I have an iGPU and it's difficult for me to test ``` <!-- If you wanna passthrough GPU, make sure the gfx and audio are in the same bus (like 0x01) but different function (0x00 and 0x01)--> <!-- <hostdev mode='subsystem' type='pci' managed='yes'> <driver name='vfio'/> <source> <address domain='0x0000' bus='0x2d' slot='0x00' function='0x0'/> </source> <rom file='/mnt/disks/backups/BIOS/RX580/Ellesmere.rom'/> <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0' multifunction='on'/> </hostdev> <hostdev mode='subsystem' type='pci' managed='yes'> <driver name='vfio'/> <source> <address domain='0x0000' bus='0x2d' slot='0x00' function='0x1'/> </source> <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x1'/> </hostdev> --> <!-- If you wanna passthrough onboard audio(like 30:00.4), make sure you put it in bus 0x00 and slot 0x0y(y is numeric), otherwise AppleALC won't recognized it --> <!-- <hostdev mode='subsystem' type='pci' managed='yes'> <driver name='vfio'/> <source> <address domain='0x0000' bus='0x30' slot='0x00' function='0x4'/> </source> <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/> </hostdev> --> ```
adam added the enhancement label 2025-12-28 23:22:09 +01:00
Author
Owner

@aaronjensen commented on GitHub (Jun 24, 2020):

I'd be happy to try this out, but I'm not sure what to do with this xml... does this need to be converted to qemu command line parameters somehow and added to the dockerfile?

@aaronjensen commented on GitHub (Jun 24, 2020): I'd be happy to try this out, but I'm not sure what to do with this xml... does this need to be converted to qemu command line parameters somehow and added to the dockerfile?
Author
Owner

@sickcodes commented on GitHub (Jul 8, 2020):

Yes, or use the Catalina xml file in the OSX-KVM directory and directly import it into virt-manager.

You will find the commented lines above in that file.

@sickcodes commented on GitHub (Jul 8, 2020): Yes, or use the Catalina xml file in the OSX-KVM directory and directly import it into virt-manager. You will find the commented lines above in that file.
Author
Owner

@sickcodes commented on GitHub (Sep 11, 2020):

I have an Nvidia 1660 now, plus the integrated AMD graphics, so I might test this

@sickcodes commented on GitHub (Sep 11, 2020): I have an Nvidia 1660 now, plus the integrated AMD graphics, so I might test this
Author
Owner

@AdamMomen commented on GitHub (Nov 7, 2020):

@sickcodes any updates on GPU passthrough. Thanks

@AdamMomen commented on GitHub (Nov 7, 2020): @sickcodes any updates on GPU passthrough. Thanks
Author
Owner

@sickcodes commented on GitHub (Nov 7, 2020):

I couldn't get it to work but OSX-KVM upstream is testing

@sickcodes commented on GitHub (Nov 7, 2020): I couldn't get it to work but OSX-KVM upstream is testing
Author
Owner

@sickcodes commented on GitHub (Feb 22, 2021):

Some additional GPU based docs here, thanks to @cephasara

https://github.com/sickcodes/Docker-OSX/blob/master/helm/INSTALL-QEMU-AND-GPU-IOMMU.md

@sickcodes commented on GitHub (Feb 22, 2021): Some additional GPU based docs here, thanks to @cephasara https://github.com/sickcodes/Docker-OSX/blob/master/helm/INSTALL-QEMU-AND-GPU-IOMMU.md
Author
Owner

@clsx524 commented on GitHub (Oct 6, 2021):

I have used OSX-KVM with virt manager and my Big Sur can work with GPU (RX580) passthrough smoothly. So my system qcow2 file and custom OpenCore file should be fine. However when I tried it with docker, the screen can show the menu and I can pick the system from the list, but it will start to load the system and freeze/stuck after a few seconds. Does anyone know how to solve this?

This is the actual qemu command it executes

+ exec qemu-system-x86_64 
-m 16000 
-cpu max,kvm=on,hypervisor=on,vmx=on,vendor=GenuineIntel,vmware-cpuid-freq=on,+pcid,+popcnt,+xsave,rdtscp=on,+sse3,+sse4.2,+aes,+xsave,+avx,+xsaveopt,+xsavec,+xgetbv1,+avx2,+bmi2,+smep,+bmi1,+fma,+movbe,+invtsc 
-machine q35,accel=kvm,kernel-irqchip=on 
-smp 4,cores=4 
-usb 
-device usb-kbd 
-device usb-tablet 
-device 'isa-applesmc,osk=ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc' 
-drive if=pflash,format=raw,readonly=on,file=/home/arch/OSX-KVM/OVMF_CODE.fd 
-drive if=pflash,format=raw,file=/home/arch/OSX-KVM/OVMF_VARS-1024x768.fd 
-smbios type=2 
-audiodev alsa,id=hda -device ich9-intel-hda 
-device hda-duplex,audiodev=hda 
-device ich9-ahci,id=sata 
-drive id=OpenCoreBoot,if=none,snapshot=on,format=qcow2,file=/home/arch/OSX-KVM/OpenCore.qcow2 
-device ide-hd,bus=sata.2,drive=OpenCoreBoot 
-device ide-hd,bus=sata.3,drive=InstallMedia -drive id=InstallMedia,if=none,file=/home/arch/OSX-KVM/BaseSystem.img,format=qcow2 
-drive id=MacHDD,if=none,file=/home/arch/OSX-KVM/BigSur.qcow2,format=qcow2 
-device ide-hd,bus=sata.4,drive=MacHDD 
-netdev user,id=net0,hostfwd=tcp::10022-:22,hostfwd=tcp::5900-:5900, 
-device vmxnet3,netdev=net0,id=net0,mac=52:54:00:09:49:17 
-monitor stdio -nodefaults -enable-kvm -boot menu=on 
-vga none -nographic -display none 
-device pcie-root-port,id=pcie.1,bus=pcie.0,addr=1c.0,slot=1,chassis=5,multifunction=on 
-device vfio-pci,host=02:00.0,bus=pcie.1,addr=00.0 
-device vfio-pci,host=02:00.1,bus=pcie.1 
-device vfio-pci,host=04:00.0,bus=pcie.1 
-device vfio-pci,host=06:00.0,bus=pcie.1

and the docker run command

docker run -it --privileged \
 --device /dev/kvm --device /dev/vfio \
 -v "${PWD}/BigSur.qcow2:/home/arch/OSX-KVM/BigSur.qcow2" \
 -v "${PWD}/OpenCore.qcow2:/home/arch/OSX-KVM/OpenCore.qcow2" \
 -e "NOPICKER=false" \
 -e "RAM=16" \
 -e "BOOTDISK=/home/arch/OSX-KVM/OpenCore.qcow2" \
 -e "IMAGE_PATH=/home/arch/OSX-KVM/BigSur.qcow2" \
 docker-osx-custom

Or is it possible to start it with virt manager within docker?

@clsx524 commented on GitHub (Oct 6, 2021): I have used OSX-KVM with virt manager and my Big Sur can work with GPU (RX580) passthrough smoothly. So my system qcow2 file and custom OpenCore file should be fine. However when I tried it with docker, the screen can show the menu and I can pick the system from the list, but it will start to load the system and freeze/stuck after a few seconds. Does anyone know how to solve this? This is the actual qemu command it executes ``` + exec qemu-system-x86_64 -m 16000 -cpu max,kvm=on,hypervisor=on,vmx=on,vendor=GenuineIntel,vmware-cpuid-freq=on,+pcid,+popcnt,+xsave,rdtscp=on,+sse3,+sse4.2,+aes,+xsave,+avx,+xsaveopt,+xsavec,+xgetbv1,+avx2,+bmi2,+smep,+bmi1,+fma,+movbe,+invtsc -machine q35,accel=kvm,kernel-irqchip=on -smp 4,cores=4 -usb -device usb-kbd -device usb-tablet -device 'isa-applesmc,osk=ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc' -drive if=pflash,format=raw,readonly=on,file=/home/arch/OSX-KVM/OVMF_CODE.fd -drive if=pflash,format=raw,file=/home/arch/OSX-KVM/OVMF_VARS-1024x768.fd -smbios type=2 -audiodev alsa,id=hda -device ich9-intel-hda -device hda-duplex,audiodev=hda -device ich9-ahci,id=sata -drive id=OpenCoreBoot,if=none,snapshot=on,format=qcow2,file=/home/arch/OSX-KVM/OpenCore.qcow2 -device ide-hd,bus=sata.2,drive=OpenCoreBoot -device ide-hd,bus=sata.3,drive=InstallMedia -drive id=InstallMedia,if=none,file=/home/arch/OSX-KVM/BaseSystem.img,format=qcow2 -drive id=MacHDD,if=none,file=/home/arch/OSX-KVM/BigSur.qcow2,format=qcow2 -device ide-hd,bus=sata.4,drive=MacHDD -netdev user,id=net0,hostfwd=tcp::10022-:22,hostfwd=tcp::5900-:5900, -device vmxnet3,netdev=net0,id=net0,mac=52:54:00:09:49:17 -monitor stdio -nodefaults -enable-kvm -boot menu=on -vga none -nographic -display none -device pcie-root-port,id=pcie.1,bus=pcie.0,addr=1c.0,slot=1,chassis=5,multifunction=on -device vfio-pci,host=02:00.0,bus=pcie.1,addr=00.0 -device vfio-pci,host=02:00.1,bus=pcie.1 -device vfio-pci,host=04:00.0,bus=pcie.1 -device vfio-pci,host=06:00.0,bus=pcie.1 ``` and the docker run command ``` docker run -it --privileged \ --device /dev/kvm --device /dev/vfio \ -v "${PWD}/BigSur.qcow2:/home/arch/OSX-KVM/BigSur.qcow2" \ -v "${PWD}/OpenCore.qcow2:/home/arch/OSX-KVM/OpenCore.qcow2" \ -e "NOPICKER=false" \ -e "RAM=16" \ -e "BOOTDISK=/home/arch/OSX-KVM/OpenCore.qcow2" \ -e "IMAGE_PATH=/home/arch/OSX-KVM/BigSur.qcow2" \ docker-osx-custom ``` Or is it possible to start it with virt manager within docker?
Author
Owner

@sickcodes commented on GitHub (Oct 15, 2021):

It is possible, I had planned to add a virt-manager version and it will not be difficult to do so. I personally don't have a detached GPU to test with, only an iGPU, but we should be able to do it with Docker as well, just a matter of passing through the right permissions and devices.

@sickcodes commented on GitHub (Oct 15, 2021): It is possible, I had planned to add a virt-manager version and it will not be difficult to do so. I personally don't have a detached GPU to test with, only an iGPU, but we should be able to do it with Docker as well, just a matter of passing through the right permissions and devices.
Author
Owner

@ghost commented on GitHub (Oct 30, 2021):

I have a mobile 2060 and an Intel cpu with integrated GPU, is there something I can do to get better performance? I honestly don't have a good understanding of how it works that's why I ask where to look for.

@ghost commented on GitHub (Oct 30, 2021): I have a mobile 2060 and an Intel cpu with integrated GPU, is there something I can do to get better performance? I honestly don't have a good understanding of how it works that's why I ask where to look for.
Author
Owner

@pwltr commented on GitHub (Mar 9, 2022):

Haven't seen anyone mention it but as far as I know MacOS only supports AMD GPUs and Intel iGPUs.

This information comes from the OpenCore Install Guide which is for building "Hackintosh" systems.
Full support table here: https://dortania.github.io/OpenCore-Install-Guide/macos-limits.html#gpu-support

I don't know anything about virtualization but I don't assume it would be different for this project?

@pwltr commented on GitHub (Mar 9, 2022): Haven't seen anyone mention it but as far as I know MacOS only supports AMD GPUs and Intel iGPUs. This information comes from the OpenCore Install Guide which is for building "Hackintosh" systems. Full support table here: https://dortania.github.io/OpenCore-Install-Guide/macos-limits.html#gpu-support I don't know anything about virtualization but I don't assume it would be different for this project?
Author
Owner

@aspauldingcode commented on GitHub (Sep 30, 2023):

It is possible, I had planned to add a virt-manager version and it will not be difficult to do so. I personally don't have a detached GPU to test with, only an iGPU, but we should be able to do it with Docker as well, just a matter of passing through the right permissions and devices.

Where are we on this?

Has GPU-Passthrough worked for anyone?
Did you figure this out, add/test this yet?

@aspauldingcode commented on GitHub (Sep 30, 2023): > It is possible, I had planned to add a virt-manager version and it will not be difficult to do so. I personally don't have a detached GPU to test with, only an iGPU, but we should be able to do it with Docker as well, just a matter of passing through the right permissions and devices. Where are we on this? Has GPU-Passthrough worked for anyone? Did you figure this out, add/test this yet?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/Docker-OSX#38