Use the actual available free memory instead of the max possible
This commit is contained in:
@@ -133,6 +133,11 @@ public class FreeBSD extends OS {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFreeMemory() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCUDALib() {
|
||||
return "cuda";
|
||||
|
||||
@@ -116,6 +116,35 @@ public class Linux extends OS {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFreeMemory() {
|
||||
try {
|
||||
String filePath = "/proc/meminfo";
|
||||
Scanner scanner = new Scanner(new File(filePath));
|
||||
|
||||
while (scanner.hasNextLine()) {
|
||||
String line = scanner.nextLine();
|
||||
|
||||
if (line.startsWith("MemFree")) {
|
||||
String buf[] = line.split(":");
|
||||
if (buf.length > 0) {
|
||||
Integer buf2 = new Integer(buf[1].trim().split(" ")[0]);
|
||||
return (((buf2 / 262144) + 1) * 262144); // 256*1024 = 262144
|
||||
}
|
||||
}
|
||||
}
|
||||
scanner.close();
|
||||
}
|
||||
catch (java.lang.NoClassDefFoundError e) {
|
||||
System.err.println("OS::Linux::getFreeMemory error " + e + " mostly because Scanner class was introducted by Java 5 and you are running a lower version");
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCUDALib() {
|
||||
return "cuda";
|
||||
|
||||
@@ -140,6 +140,11 @@ public class Mac extends OS {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFreeMemory() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Process exec(List<String> command, Map<String, String> env) throws IOException {
|
||||
List<String> actual_command = command;
|
||||
|
||||
@@ -33,6 +33,8 @@ public abstract class OS {
|
||||
|
||||
public abstract int getMemory();
|
||||
|
||||
public abstract int getFreeMemory();
|
||||
|
||||
public abstract String getRenderBinaryPath();
|
||||
|
||||
public String getCUDALib() {
|
||||
|
||||
@@ -102,6 +102,21 @@ public class Windows extends OS {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFreeMemory() {
|
||||
try {
|
||||
MEMORYSTATUSEX _memory = new MEMORYSTATUSEX();
|
||||
if (Kernel32.INSTANCE.GlobalMemoryStatusEx(_memory)) {
|
||||
return (int) (_memory.ullAvailPhys.longValue() / 1024); // size in KB
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCUDALib() {
|
||||
return "nvcuda";
|
||||
|
||||
Reference in New Issue
Block a user