- Add the required VM arguments to the Eclipse/IntelliJ IDE, as shown in the following example:
-Xms1G -Xmx6G -Dorg.bytedeco.javacpp.maxbytes=16G -Dorg.bytedeco.javacpp.maxphysicalbytes=20G
For example, in IntelliJ IDE, we can add VM arguments to the runtime configuration:
- Run the following command after changing the memory limits to suit your hardware (for command-line executions):
java -Xms1G -Xmx6G -Dorg.bytedeco.javacpp.maxbytes=16G -Dorg.bytedeco.javacpp.maxphysicalbytes=20G YourClassName
- Configure a server-style generational garbage collector for JVM:
java -XX:+UseG1GC
- Reduce the frequency of garbage collector calls using ND4J:
Nd4j.getMemoryManager().setAutoGcWindow(3000);
- Disable garbage collector calls instead of step 4:
Nd4j.getMemoryManager().togglePeriodicGc(false);
- Allocate memory chunks in memory-mapped files instead of RAM:
WorkspaceConfiguration memoryMap = WorkspaceConfiguration.builder()
.initialSize(2000000000)
.policyLocation(LocationPolicy.MMAP)
.build();
try (MemoryWorkspace workspace = Nd4j.getWorkspaceManager().getAndActivateWorkspace(memoryMap, "M")) {
INDArray example = Nd4j.create(10000);
}