From 242ef644e27e4cf1cc0a32349a82723e85dcb13b Mon Sep 17 00:00:00 2001 From: Laurent Clouet Date: Wed, 20 Jul 2016 16:29:17 +0200 Subject: [PATCH] Cleanup: use IntByReference instead of creating by hand an array of one value --- src/com/sheepit/client/hardware/gpu/CUDA.java | 6 ++++-- src/com/sheepit/client/hardware/gpu/GPU.java | 10 ++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/com/sheepit/client/hardware/gpu/CUDA.java b/src/com/sheepit/client/hardware/gpu/CUDA.java index 8e9ee80..ed40ebb 100644 --- a/src/com/sheepit/client/hardware/gpu/CUDA.java +++ b/src/com/sheepit/client/hardware/gpu/CUDA.java @@ -20,6 +20,8 @@ package com.sheepit.client.hardware.gpu; import com.sun.jna.Library; +import com.sun.jna.ptr.IntByReference; +import com.sun.jna.ptr.LongByReference; public interface CUDA extends Library { 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 */ - public int cuDeviceGetCount(int count[]); + public int cuDeviceGetCount(IntByReference count); public int cuDeviceGetName(byte[] name, int len, int dev); // http://en.wikipedia.org/wiki/Java_Native_Access - public int cuDeviceTotalMem(long bytes[], int dev); + public int cuDeviceTotalMem(LongByReference bytes, int dev); } diff --git a/src/com/sheepit/client/hardware/gpu/GPU.java b/src/com/sheepit/client/hardware/gpu/GPU.java index 651ec40..6f945e8 100644 --- a/src/com/sheepit/client/hardware/gpu/GPU.java +++ b/src/com/sheepit/client/hardware/gpu/GPU.java @@ -24,6 +24,8 @@ import java.util.List; import com.sheepit.client.os.OS; import com.sun.jna.Native; +import com.sun.jna.ptr.IntByReference; +import com.sun.jna.ptr.LongByReference; public class GPU { public static List devices = null; @@ -69,7 +71,7 @@ public class GPU { return false; } - int[] count = new int[1]; + IntByReference count = new IntByReference(); result = cudalib.cuDeviceGetCount(count); if (result != CUresult.CUDA_SUCCESS) { @@ -79,7 +81,7 @@ public class GPU { devices = new LinkedList(); - for (int num = 0; num < count[0]; num++) { + for (int num = 0; num < count.getValue(); num++) { byte name[] = new byte[256]; result = cudalib.cuDeviceGetName(name, 256, num); @@ -88,7 +90,7 @@ public class GPU { continue; } - long[] ram = new long[1]; + LongByReference ram = new LongByReference(); result = cudalib.cuDeviceTotalMem(ram, num); if (result != CUresult.CUDA_SUCCESS) { @@ -96,7 +98,7 @@ public class GPU { 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; }