-
-
Save ShayBox/82f34647426cc044a0cb1e8b598191d8 to your computer and use it in GitHub Desktop.
Dual GPU Passthrough Libvirt/QEMU Hook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
GPU="0000_41_00" | |
if [[ "$1" == "Windows-11-GPU" ]] | |
then | |
case "$2" in | |
"prepare") | |
echo "Preparing..." >&2 | |
echo "Stopping Ollama..." >&2 | |
systemctl stop ollama >&2 | |
if [[ $(lsof -n | grep -c -e "/dev/nvidia") > 0 ]] | |
then | |
echo "Starting Ollama..." >&2 | |
systemctl start ollama >&2 | |
echo "GPU is still in use!" >&2 | |
exit 1 | |
fi | |
echo "Removing Nvidia DRM..." >&2 | |
modprobe -r nvidia_drm >&2 | |
echo "Removing GPU..." >&2 | |
virsh nodedev-detach "pci_${GPU}_0" >&2 | |
virsh nodedev-detach "pci_${GPU}_1" >&2 | |
;; | |
"release") | |
echo "Releasing..." >&2 | |
echo "Adding GPU..." >&2 | |
virsh nodedev-reattach "pci_${GPU}_0" >&2 | |
virsh nodedev-reattach "pci_${GPU}_1" >&2 | |
echo "Adding Nvidia DRM..." >&2 | |
modprobe nvidia_drm >&2 | |
echo "Starting Ollama..." >&2 | |
systemctl start ollama >&2 | |
;; | |
esac | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment