Hello Guest

GPU Affinity

  • 4 Replies
  • 5414 Views
GPU Affinity
« on: May 09, 2017, 12:38:08 »
Hi,

I would like to let my application select the high-performance GPU (if available) automatically. On my laptop I have an Intel chip and an nvidia 940m. I've recently switched from lwjgl 2.9 to 3.1.1 and ported everything to glfw. I am currently trying to achieve this on Windows.

I've found following flag for lwjgl to check if nvidia gpu affinity is supported:
Code: [Select]
GL.getCapabilitiesWGL().WGL_NV_gpu_affinityThough this flag returns false on my laptop. I suppose it's not supported then?

I've kept Googling and found the following topic on stackoverflow: http://stackoverflow.com/questions/6036292/select-a-graphic-device-in-windows-opengl
However, how can I add this C code via lwjgl to enable that flag?
Code: [Select]
// enable optimus!
extern "C" {
    _declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
}

Or am I heading towards the wrong direction? Are there other, better ways to handle GPU affinity?

Thanks in advance,
Thomy
« Last Edit: May 09, 2017, 13:02:41 by Thomy »

*

Kai

Re: GPU Affinity
« Reply #1 on: May 09, 2017, 13:26:18 »
The exe which is used to start the process needs to export that flag in its module file (PE on Windows or ELF on Linux).
So, when you simply develop locally by using the default java.exe/javaw.exe launcher, then it would be this exact exe file which needs to have this flag exported. Now, since you cannot simply edit that exe file to make it export that symbol, there are a couple of other options:
- use the JNI Invocation API to write your own launcher
- configure the java.exe/javaw.exe in the Nvidia Control panel to use the dedicated graphics card
- configure the BIOS to disable Optimus and always use the dedicated card

The Nvidia extension you mentioned merely allows to select the graphics card to use when you have multiple dedicated graphics card, such as via SLI in a desktop computer.

Re: GPU Affinity
« Reply #2 on: May 09, 2017, 13:53:46 »
Thanks! I'll have a look at JNI Invocation API, since this is the easiest way to get it to work for all users on Windows. Maybe lwjgl will also provide functions to set these flags in the future.

*

Kai

Re: GPU Affinity
« Reply #3 on: May 09, 2017, 13:59:15 »
Maybe lwjgl will also provide functions to set these flags in the future.
This is not possible. Unless LWJGL itself provides a Java launcher exe.

Re: GPU Affinity
« Reply #4 on: May 09, 2017, 14:05:28 »
I see, thanks! I've found a commit for lwjgl, where this dword is set to 1 by default:
https://github.com/LWJGL/lwjgl/blob/master/src/native/windows/LWJGL.c

Doesn't this mean that it should actually already work by default?


EDIT: My mistake, this is for 2.x!
« Last Edit: May 09, 2017, 14:07:31 by Thomy »