Cleanup: use IntByReference instead of creating by hand an array of one value
This commit is contained in:
@@ -20,6 +20,8 @@
|
|||||||
package com.sheepit.client.hardware.gpu;
|
package com.sheepit.client.hardware.gpu;
|
||||||
|
|
||||||
import com.sun.jna.Library;
|
import com.sun.jna.Library;
|
||||||
|
import com.sun.jna.ptr.IntByReference;
|
||||||
|
import com.sun.jna.ptr.LongByReference;
|
||||||
|
|
||||||
public interface CUDA extends Library {
|
public interface CUDA extends Library {
|
||||||
public int cuInit(int flags);
|
public int cuInit(int flags);
|
||||||
@@ -27,10 +29,10 @@ public interface CUDA extends Library {
|
|||||||
/*
|
/*
|
||||||
* @return: CUDA_SUCCESS, CUDA_ERROR_DEINITIALIZED, CUDA_ERROR_NOT_INITIALIZED, CUDA_ERROR_INVALID_CONTEXT, CUDA_ERROR_INVALID_VALUE
|
* @return: CUDA_SUCCESS, CUDA_ERROR_DEINITIALIZED, CUDA_ERROR_NOT_INITIALIZED, CUDA_ERROR_INVALID_CONTEXT, CUDA_ERROR_INVALID_VALUE
|
||||||
*/
|
*/
|
||||||
public int cuDeviceGetCount(int count[]);
|
public int cuDeviceGetCount(IntByReference count);
|
||||||
|
|
||||||
public int cuDeviceGetName(byte[] name, int len, int dev);
|
public int cuDeviceGetName(byte[] name, int len, int dev);
|
||||||
|
|
||||||
// http://en.wikipedia.org/wiki/Java_Native_Access
|
// http://en.wikipedia.org/wiki/Java_Native_Access
|
||||||
public int cuDeviceTotalMem(long bytes[], int dev);
|
public int cuDeviceTotalMem(LongByReference bytes, int dev);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ import java.util.List;
|
|||||||
|
|
||||||
import com.sheepit.client.os.OS;
|
import com.sheepit.client.os.OS;
|
||||||
import com.sun.jna.Native;
|
import com.sun.jna.Native;
|
||||||
|
import com.sun.jna.ptr.IntByReference;
|
||||||
|
import com.sun.jna.ptr.LongByReference;
|
||||||
|
|
||||||
public class GPU {
|
public class GPU {
|
||||||
public static List<GPUDevice> devices = null;
|
public static List<GPUDevice> devices = null;
|
||||||
@@ -69,7 +71,7 @@ public class GPU {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int[] count = new int[1];
|
IntByReference count = new IntByReference();
|
||||||
result = cudalib.cuDeviceGetCount(count);
|
result = cudalib.cuDeviceGetCount(count);
|
||||||
|
|
||||||
if (result != CUresult.CUDA_SUCCESS) {
|
if (result != CUresult.CUDA_SUCCESS) {
|
||||||
@@ -79,7 +81,7 @@ public class GPU {
|
|||||||
|
|
||||||
devices = new LinkedList<GPUDevice>();
|
devices = new LinkedList<GPUDevice>();
|
||||||
|
|
||||||
for (int num = 0; num < count[0]; num++) {
|
for (int num = 0; num < count.getValue(); num++) {
|
||||||
byte name[] = new byte[256];
|
byte name[] = new byte[256];
|
||||||
|
|
||||||
result = cudalib.cuDeviceGetName(name, 256, num);
|
result = cudalib.cuDeviceGetName(name, 256, num);
|
||||||
@@ -88,7 +90,7 @@ public class GPU {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
long[] ram = new long[1];
|
LongByReference ram = new LongByReference();
|
||||||
result = cudalib.cuDeviceTotalMem(ram, num);
|
result = cudalib.cuDeviceTotalMem(ram, num);
|
||||||
|
|
||||||
if (result != CUresult.CUDA_SUCCESS) {
|
if (result != CUresult.CUDA_SUCCESS) {
|
||||||
@@ -96,7 +98,7 @@ public class GPU {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
devices.add(new GPUDevice(new String(name).trim(), ram[0], "CUDA_" + Integer.toString(num)));
|
devices.add(new GPUDevice(new String(name).trim(), ram.getValue(), "CUDA_" + Integer.toString(num)));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user