Skip to content

Contains a script for rebinding your GPU, and for deterministically running applications on your faster GPU.

License

Notifications You must be signed in to change notification settings

alexankitty/gpu-passthrough-scripts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gpu-passthrough-scripts

Contains a script for rebinding your GPU, and for deterministically running applications on your faster GPU.

Installation

Clone this repo, and cd and copy to /usr/bin

git clone https://github.com/alexankitty/fastgpu.git
cd fastgpu
sudo cp fastgpu /usr/bin
sudo chmod +x /usr/bin/fastgpu

If you intend to also use your GPU for a gaming VM, be sure to follow this wiki page on how to statically bind your GPU to VFIO.
If you need to hook your VM as well, a hooks installer script is included. Be sure to alter the scripts as needed. Change line 6 of hooks/qemu to the name of your VM from win11.

Usage

Before any program launch or in steam, prepend fastgpu to use your faster graphics accelerator.
If your faster GPU is unavailable (as a gpu pass through for example) it will use your primary GPU instead. If environment variables are needed prior to the launch, the script has some magic to export them out, but requires that you wrap it in quotes.
Example:

fastgpu 'WINEDLLOVERRIDES="dinput8,dll=n,b"' %command%

If you're not using steam, then you'll just replace %command% with your actual command.

Important Note

Your compositor under wayland needs to support dynamic compositing to whichever is determined to be the primary/output/active GPU. See this issue for kwin's implementation/progress. Otherwise you will need to close any programs that have touched the GPU since attaching it. Check output of the following command.

fuser -v /dev/nvidia0

Slow Application Loading

Certain applications by default will try to use the nvidia gpu first prior to whichever is the mesa GPU. You'll need to set some specific overrides to get those to work correctly in either an env var startup script, or /etc/environment

__GLX_VENDOR_LIBRARY_NAME=amd
__EGL_VENDOR_LIBRARY_FILENAMES=/usr/share/glvnd/egl_vendor.d/50_mesa.json

This should alleviate the problem of applications using the wrong gpu and make it easier to unbind. Also set the following ENV Vars

export DISABLE_LAYER_AMD_SWITCHABLE_GRAPHICS_1=1
export VK_ICD_FILENAMES=/usr/share/vulkan/icd.d/radeon_icd.i686.json:/usr/share/vulkan/icd.d/radeon_icd.x86_64.json

Adjust as needed for your integrated/primary GPU.

Alterations

The assumption here is that you're using Nvidia under wayland as a prime offload GPU.
Further details on how to achieve other configs can be found at this archwiki page.
A brief run down of changes that need to be made:
On line 2, you need to change the module you're checking on from nvidia to amdgpu if AMD is your offloader (no guarantee how well this will work).
On line 3, you will need to put in the IOMMU PCI ID of your GPU. You can grab that using this script.
On line 25 you will want to change the following:

export DRI_PRIME=pci-0000_01_00_0 __VK_LAYER_NV_optimus=NVIDIA_only __GLX_VENDOR_LIBRARY_NAME=nvidia

To:

export DRI_PRIME=pci-0000_06_00_0

GPU Swapping from vfio to nvidia

Recommend using supergfxctl as it's just a much better implementation and has guis for kde and gnome. Run swapgpu from TTY for best results!

Install

sudo cp swapgpu /usr/bin
sudo chmod +x /usr/bin/swapgpu

Change the following to match your setup.

gpu_id="0000:01:00.0"
gpu_audio_id="0000:01:00.1"

If you're on AMD I recommend looking through this reddit post for actually adjusting the script for AMD.

Usage

sudo swapgpu nvidia # swaps to nvidia
sudo swapgpu vfio-pci # swaps to vfio for binding to VM

About

Contains a script for rebinding your GPU, and for deterministically running applications on your faster GPU.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages