Background
Develop a program with OpenGL (using JOGL Java binding) on Windows by enforcing the “High Performance” global setting on the Windows system. But that would affect all applications running on the system, probably draining the battery quickly.
Question
How to enforce a Java program use of NVIDIA GPU on Windows under IDEA?
Answer
Short one:
You may reference here https://thinglabs.io/how-to-make-minecraft-use-your-gpu, but replace the minecraft.exe with the java.exe under the JDK you used to run your program.
Detailed instructions:
The Java program launched by IDEA has nothing to do with the GPU card used by IDEA.
Please follow the below steps:
NVIDIA Settings
- Open the NVIDIA Control Panel: Right-click on your desktop and select “NVIDIA Control Panel”.
- Manage 3D Settings: On the left, click “Manage 3D settings”.
- Program Settings: Go to the “Program Settings” tab.
- Select Java: Click “Add” and find java.exe in its installation folder, select 'open'. You can find the full path of java.exe under the IDEA's Run tool window output, eg: C:\Users\yourname.jdks\jbrsdk-17.0.9\bin\java.exe).
- Choose GPU. Under setting number 2, there’s a dropdown. Choose “High-performance NVIDIA processor” and click “Apply”.
Here is the simple Java GUI program used to test:
public class Main {
public static void main(String[] args) throws IOException {
JFrame frame = new JFrame("TEST NVIDIA");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300,300);
frame.setVisible(true);
}
}
Add JVM options in the IDEA's run configuration: -Dsun.java2d.d3d=true -Dsun.java2d.noddraw=false
The NVIDIA GPU Activity indicates it now runs on GPU (ignore some Unicode on the screenshot):
Comments
0 comments
Please sign in to leave a comment.