Explicitly choosing which GPU to use

Basically I have a system with several dedicated NVIDIA graphics cards (not integraded-dedicated GPU setup for laptops), and I want to be able to tell Unreal which one to use on an per-launch basis. That means that I don’t want to change NVIDIA settings each time I want an app to run on a different GPU, and I definitely don’t want to go to BIOS. Is there any way to do this? I’ve seen games on other engines having an ability to choose GPU in their in-game settings, but none of them were running on any version of UE.

Turns out, there is a console variable for that — r.GraphicsAdapter, set in Engine.ini or DefaultEngine.ini when in editor.

It would be nice if there were a way to specify the GPU to use at launch via the command line. Is that possible?

Hmm I’ve only seen -preferintel and -prefernvidia as command-line options (To switch between integrated and dedicated). But I haven’t gone deep into the code.

It would be quite handy to have a way to set this at runtime via command-line arguments or environment variable without having to edit an INI file for scripting purposes, especially in Linux.

EDIT: looks like adding r.GraphicsAdapter=2 to CarlaUE4/Saved/Config/LinuxNoEditor/Engine.ini has no impact, CARLA (UE4 powered) is still running on GPU 0 on my Ubuntu 16.04 machine

EDIT 2: Other users are reporting the r.GraphicsAdapter setting not working, tried it in ConsoleVariables.ini as well.

I figured out how to select a specific gpu in UE5!!

CleanShot 2022-04-26 at 00.31.15

3 Likes

This is working only on a mac if I’m not mistaken :frowning:
Does anyone have luck on win? I have 2 nvidias - old and new and I am not able to use the new one, since it is not the primary system GPU.
Thanks.

2 Likes

https://github.com/EpicGames/UnrealEngine/blob/5.2.0-release/Engine/Source/Runtime/VulkanRHI/Private/VulkanRHI.cpp#L612

Just do -graphicsadapter=<number> in commandline args.

2 Likes

This answer changed my life!!
Despite all 3 of my GPUs supporting Vulkan, I would get an error “could not find a compatible vulkan device that supports surface presentation”.

Specifying the third (external) gpu (index no. 2) was a miracle cure, and a miracle diet. I’ve lost 50lbs, and I have a new lease on life now.

2 Likes

That will not work on ubuntu, there’s no such plugin

Can you use the DRI_PRIME environment variable for the same effect? If the game is outputting over vulkan, you should be able to use DRI_PRIME=n! to only expose graphics adapter n to the game.